From b83a31b6897b73833a374eb9d4b02d2a594bb818 Mon Sep 17 00:00:00 2001 From: Ian Ramos <5714212+IanRamosC@users.noreply.github.com> Date: Thu, 18 Jul 2024 22:10:14 -0300 Subject: [PATCH] Add product class for Newsletter --- .../packages/my-jetpack/.phan/baseline.php | 1 + .../my-jetpack/src/class-products.php | 11 +- .../src/products/class-newsletter.php | 194 ++++++++++++++++++ 3 files changed, 201 insertions(+), 5 deletions(-) create mode 100644 projects/packages/my-jetpack/src/products/class-newsletter.php diff --git a/projects/packages/my-jetpack/.phan/baseline.php b/projects/packages/my-jetpack/.phan/baseline.php index 7f99fefac08c1..bcc034e383d51 100644 --- a/projects/packages/my-jetpack/.phan/baseline.php +++ b/projects/packages/my-jetpack/.phan/baseline.php @@ -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'], diff --git a/projects/packages/my-jetpack/src/class-products.php b/projects/packages/my-jetpack/src/class-products.php index 7dfa561b61728..211fefdd29143 100644 --- a/projects/packages/my-jetpack/src/class-products.php +++ b/projects/packages/my-jetpack/src/class-products.php @@ -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, ); /** diff --git a/projects/packages/my-jetpack/src/products/class-newsletter.php b/projects/packages/my-jetpack/src/products/class-newsletter.php new file mode 100644 index 0000000000000..8c004b16aba8c --- /dev/null +++ b/projects/packages/my-jetpack/src/products/class-newsletter.php @@ -0,0 +1,194 @@ + 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' ); + } +}