Skip to content

Commit

Permalink
Add product class for Newsletter
Browse files Browse the repository at this point in the history
  • Loading branch information
IanRamosC committed Jul 19, 2024
1 parent b4e1648 commit b83a31b
Show file tree
Hide file tree
Showing 3 changed files with 201 additions and 5 deletions.
1 change: 1 addition & 0 deletions projects/packages/my-jetpack/.phan/baseline.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
'src/products/class-hybrid-product.php' => ['PhanTypeMismatchArgumentNullable', 'PhanTypeMismatchReturnNullable'],
'src/products/class-jetpack-ai.php' => ['PhanPluginDuplicateConditionalNullCoalescing', 'PhanTypeMismatchReturn', 'PhanTypeMismatchReturnProbablyReal'],
'src/products/class-module-product.php' => ['PhanTypeMismatchReturnProbablyReal'],
'src/products/class-newsletter.php' => ['PhanTypeMismatchArgumentNullable', 'PhanTypeMismatchArgumentNullableInternal'],
'src/products/class-product.php' => ['PhanAbstractStaticMethodCallInStatic', 'PhanTypeMismatchArgumentNullable', 'PhanTypeMismatchPropertyDefault'],
'src/products/class-protect.php' => ['PhanTypeMismatchPropertyDefault'],
'src/products/class-scan.php' => ['PhanTypeMismatchArgumentNullable'],
Expand Down
11 changes: 6 additions & 5 deletions projects/packages/my-jetpack/src/class-products.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,21 +105,22 @@ class Products {
*/
public static function get_products_classes() {
$classes = array(
'ai' => Products\Jetpack_Ai::class,
'anti-spam' => Products\Anti_Spam::class,
'backup' => Products\Backup::class,
'boost' => Products\Boost::class,
'crm' => Products\Crm::class,
'creator' => Products\Creator::class,
'crm' => Products\Crm::class,
'extras' => Products\Extras::class,
'jetpack-ai' => Products\Jetpack_Ai::class,
'newsletter' => Products\Newsletter::class,
'protect' => Products\Protect::class,
'scan' => Products\Scan::class,
'search' => Products\Search::class,
'social' => Products\Social::class,
'security' => Products\Security::class,
'protect' => Products\Protect::class,
'videopress' => Products\Videopress::class,
'social' => Products\Social::class,
'stats' => Products\Stats::class,
'ai' => Products\Jetpack_Ai::class,
'videopress' => Products\Videopress::class,
);

/**
Expand Down
194 changes: 194 additions & 0 deletions projects/packages/my-jetpack/src/products/class-newsletter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,194 @@
<?php
/**
* Jetpack Newsletter
*
* @package my-jetpack
*/

namespace Automattic\Jetpack\My_Jetpack\Products;

use Automattic\Jetpack\My_Jetpack\Initializer;
use Automattic\Jetpack\My_Jetpack\Module_Product;
use Automattic\Jetpack\My_jetpack\Products;
use Automattic\Jetpack\My_Jetpack\Wpcom_Products;

/**
* Class responsible for handling the Jetpack Newsletter (subscriptions) module
*/
class Newsletter extends Module_Product {
/**
* The product slug
*
* @var string
*/
public static $slug = 'newsletter';

/**
* The Jetpack module name associated with this product
*
* @var string|null
*/
public static $module_name = 'subscriptions';

/**
* The Plugin slug associated with Newsletter
*
* @var string|null
*/
public static $plugin_slug = self::JETPACK_PLUGIN_SLUG;

/**
* The Plugin file associated with Newsletter
*
* @var string|null
*/
public static $plugin_filename = self::JETPACK_PLUGIN_FILENAME;

/**
* Newsletter only requires site connection, not user connection
*
* @var bool
*/
public static $requires_user_connection = false;

/**
* Newsletter does not have a standalone plugin yet
*
* @var bool
*/
public static $has_standalone_plugin = false;

/**
* Whether this product has a free offering
*
* @var bool
*/
public static $has_free_offering = true;

/**
* Get the product name
*
* @return string
*/
public static function get_name() {
return 'Newsletter';
}

/**
* Get the product title
*
* @return string
*/
public static function get_title() {
return 'Jetpack Newsletter';
}

/**
* Get the internationalized product description
*
* @return string
*/
public static function get_description() {
return __( 'Deliver your content with ease.', 'jetpack-my-jetpack' );
}

/**
* Get the internationalized product long description
*
* @return string
*/
public static function get_long_description() {
return __( 'Write and share your content, get more subscribers, and monetize your writing.', 'jetpack-my-jetpack' );
}

/**
* Get the internationalized features list
*
* @return array Newsletter features list
*/
public static function get_features() {
return array(
__( 'Instant blog‑to‑newsletter delivery', 'jetpack-my-jetpack' ),
__( 'Effortlessly reach your subscribers with fresh content', 'jetpack-my-jetpack' ),
__( 'Earn money through your Newsletter', 'jetpack-my-jetpack' ),
);
}

/**
* Get the product pricing details
* Only showing the pricing details for the commercial product
*
* @return array Pricing details
*/
public static function get_pricing_for_ui() {
return array(
'available' => true,
'is_free' => true,
);
}

/**
* Gets the 'status' of the Newsletter module
*
* @return string
*/
public static function get_status() {
$status = parent::get_status();
if ( Products::STATUS_MODULE_DISABLED === $status && ! Initializer::is_registered() ) {
// If the site has never been connected before, show the "Learn more" CTA.
// It should point to the settings page where the user can manage Newsletter
$status = Products::STATUS_NEEDS_PURCHASE_OR_FREE;
}
return $status;
}

/**
* Checks whether the product can be upgraded to a different product.
* Newsletter is not upgradable.
*
* @return boolean
*/
public static function is_upgradable() {
return false;
}

/**
* Checks if the site has a paid plan that supports this product
*
* @return boolean
*/
public static function has_paid_plan_for_product() {
$purchases_data = Wpcom_Products::get_site_current_purchases();
if ( is_wp_error( $purchases_data ) ) {
return false;
}
if ( is_array( $purchases_data ) && ! empty( $purchases_data ) ) {
foreach ( $purchases_data as $purchase ) {
// Newsletter is also part of Creator and Complete plans.
if ( strpos( $purchase->product_slug, 'jetpack_complete' ) !== false || str_starts_with( $purchase->product_slug, 'jetpack_creator' ) ) {
return true;
}
}
}
return false;
}

/**
* Checks whether the product supports trial or not.
* Since Jetpack Newsletter has a free product, it "supports" a trial.
*
* @return boolean
*/
public static function has_trial_support() {
return true;
}

/**
* Get the URL where the user manages the product
*
* @return ?string
*/
public static function get_manage_url() {
return admin_url( 'admin.php?page=jetpack#/settings?term=newsletter' );
}
}

0 comments on commit b83a31b

Please sign in to comment.