From d34239cc098dc6569e5f25311a6cdfea56ecfbb9 Mon Sep 17 00:00:00 2001 From: IanRamosC Date: Wed, 18 Dec 2024 19:09:33 +0000 Subject: [PATCH] My Jetpack: support features as recommendations (#40492) * My Jetpack: add feature as possible module recommendation * changelog * Add the module classes for the 3 features * Add config for feature modules * Refactor module product class * Fix PHAN errors Committed via a GitHub action: https://github.com/Automattic/jetpack/actions/runs/12399469677 Upstream-Ref: Automattic/jetpack@21b4c4f00c460e8314ba58c7bdbbd702f1342bae --- CHANGELOG.md | 7 +- composer.json | 2 +- package.json | 2 +- src/class-initializer.php | 2 +- src/class-products.php | 38 ++--- src/products/class-module-product.php | 38 +++++ src/products/class-newsletter.php | 179 ++++++++++++++++++++++++ src/products/class-related-posts.php | 179 ++++++++++++++++++++++++ src/products/class-site-accelerator.php | 179 ++++++++++++++++++++++++ 9 files changed, 604 insertions(+), 22 deletions(-) create mode 100644 src/products/class-newsletter.php create mode 100644 src/products/class-related-posts.php create mode 100644 src/products/class-site-accelerator.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 0fe3e4b0..56105f2c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,10 +5,13 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). -## [5.1.3-alpha] - unreleased +## [5.2.0-alpha] - unreleased This is an alpha version! The changes listed here are not final. +### Added +- My Jetpack: add features as possible modules to the recommendations list. + ### Changed - My Jetpack: Plans section: Improvements to how we display plan expiration date. @@ -1875,7 +1878,7 @@ This is an alpha version! The changes listed here are not final. ### Added - Created package -[5.1.3-alpha]: https://github.com/Automattic/jetpack-my-jetpack/compare/5.1.2...5.1.3-alpha +[5.2.0-alpha]: https://github.com/Automattic/jetpack-my-jetpack/compare/5.1.2...5.2.0-alpha [5.1.2]: https://github.com/Automattic/jetpack-my-jetpack/compare/5.1.1...5.1.2 [5.1.1]: https://github.com/Automattic/jetpack-my-jetpack/compare/5.1.0...5.1.1 [5.1.0]: https://github.com/Automattic/jetpack-my-jetpack/compare/5.0.4...5.1.0 diff --git a/composer.json b/composer.json index 17ad82f0..18b1b112 100644 --- a/composer.json +++ b/composer.json @@ -72,7 +72,7 @@ "link-template": "https://github.com/Automattic/jetpack-my-jetpack/compare/${old}...${new}" }, "branch-alias": { - "dev-trunk": "5.1.x-dev" + "dev-trunk": "5.2.x-dev" }, "version-constants": { "::PACKAGE_VERSION": "src/class-initializer.php" diff --git a/package.json b/package.json index fa42a94c..faae0078 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "private": true, "name": "@automattic/jetpack-my-jetpack", - "version": "5.1.3-alpha", + "version": "5.2.0-alpha", "description": "WP Admin page with information and configuration shared among all Jetpack stand-alone plugins", "homepage": "https://github.com/Automattic/jetpack/tree/HEAD/projects/packages/my-jetpack/#readme", "bugs": { diff --git a/src/class-initializer.php b/src/class-initializer.php index da2f1853..6a0784e3 100644 --- a/src/class-initializer.php +++ b/src/class-initializer.php @@ -42,7 +42,7 @@ class Initializer { * * @var string */ - const PACKAGE_VERSION = '5.1.3-alpha'; + const PACKAGE_VERSION = '5.2.0-alpha'; /** * HTML container ID for the IDC screen on My Jetpack page. diff --git a/src/class-products.php b/src/class-products.php index 87e277dc..8f8681fd 100644 --- a/src/class-products.php +++ b/src/class-products.php @@ -119,24 +119,28 @@ class Products { */ public static function get_products_classes() { $classes = array( - 'anti-spam' => Products\Anti_Spam::class, - 'backup' => Products\Backup::class, - 'boost' => Products\Boost::class, - 'crm' => Products\Crm::class, - 'creator' => Products\Creator::class, - 'extras' => Products\Extras::class, - 'jetpack-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, + 'extras' => Products\Extras::class, + 'jetpack-ai' => Products\Jetpack_Ai::class, // TODO: Remove this duplicate class ('ai')? See: https://github.com/Automattic/jetpack/pull/35910#pullrequestreview-2456462227 - 'ai' => Products\Jetpack_Ai::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, - 'stats' => Products\Stats::class, - 'growth' => Products\Growth::class, - 'complete' => Products\Complete::class, + 'ai' => Products\Jetpack_Ai::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, + 'stats' => Products\Stats::class, + 'growth' => Products\Growth::class, + 'complete' => Products\Complete::class, + // Features + 'newsletter' => Products\Newsletter::class, + 'site-accelerator' => Products\Site_Accelerator::class, + 'related-posts' => Products\Related_Posts::class, ); /** diff --git a/src/products/class-module-product.php b/src/products/class-module-product.php index 5472cfec..9d1a14f0 100644 --- a/src/products/class-module-product.php +++ b/src/products/class-module-product.php @@ -7,6 +7,7 @@ namespace Automattic\Jetpack\My_Jetpack; +use Automattic\Jetpack\Connection\Manager as Connection_Manager; use Jetpack; use WP_Error; @@ -26,6 +27,13 @@ abstract class Module_Product extends Product { */ public static $module_name = null; + /** + * Whether this module is a Jetpack feature + * + * @var boolean + */ + public static $is_feature = false; + /** * Get the plugin slug - ovewrite it ans return Jetpack's * @@ -79,12 +87,42 @@ public static function is_module_active() { return Jetpack::is_module_active( static::$module_name ); } + /** + * Get the product status. + * We don't use parent::get_status() to avoid complexity. + * + * @return string Product status. + */ + private static function get_feature_status() { + if ( ! static::is_plugin_installed() ) { + return Products::STATUS_PLUGIN_ABSENT; + } + + if ( ! static::is_plugin_active() ) { + return Products::STATUS_INACTIVE; + } + + if ( static::$requires_user_connection && ! ( new Connection_Manager() )->has_connected_owner() ) { + return Products::STATUS_USER_CONNECTION_ERROR; + } + + if ( ! static::is_module_active() ) { + return Products::STATUS_MODULE_DISABLED; + } + + return Products::STATUS_ACTIVE; + } + /** * Gets the current status of the product * * @return string */ public static function get_status() { + if ( static::$is_feature ) { + return static::get_feature_status(); + } + $status = parent::get_status(); if ( Products::STATUS_INACTIVE === $status && ! static::is_module_active() ) { $status = Products::STATUS_MODULE_DISABLED; diff --git a/src/products/class-newsletter.php b/src/products/class-newsletter.php new file mode 100644 index 00000000..66d806d5 --- /dev/null +++ b/src/products/class-newsletter.php @@ -0,0 +1,179 @@ + true, + 'is_free' => true, + ); + } + + /** + * Checks whether the Product is active. + * + * @return boolean + */ + public static function is_active() { + return static::is_jetpack_plugin_active(); + } + + /** + * Checks whether the plugin is installed + * + * @return boolean + */ + public static function is_plugin_installed() { + return static::is_jetpack_plugin_installed(); + } + + /** + * 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' ); + } + + /** + * Activates the Jetpack plugin + * + * @return null|WP_Error Null on success, WP_Error on invalid file. + */ + public static function activate_plugin() { + $plugin_filename = static::get_installed_plugin_filename( self::JETPACK_PLUGIN_SLUG ); + + if ( $plugin_filename ) { + return activate_plugin( $plugin_filename ); + } + } +} diff --git a/src/products/class-related-posts.php b/src/products/class-related-posts.php new file mode 100644 index 00000000..e5b10ec9 --- /dev/null +++ b/src/products/class-related-posts.php @@ -0,0 +1,179 @@ + true, + 'is_free' => true, + ); + } + + /** + * Checks whether the Product is active. + * + * @return boolean + */ + public static function is_active() { + return static::is_jetpack_plugin_active(); + } + + /** + * Checks whether the plugin is installed + * + * @return boolean + */ + public static function is_plugin_installed() { + return static::is_jetpack_plugin_installed(); + } + + /** + * Get the URL where the user manages the product + * + * @return ?string + */ + public static function get_manage_url() { + return admin_url( 'admin.php?page=jetpack#/traffic?term=related%20posts' ); + } + + /** + * Activates the Jetpack plugin + * + * @return null|WP_Error Null on success, WP_Error on invalid file. + */ + public static function activate_plugin() { + $plugin_filename = static::get_installed_plugin_filename( self::JETPACK_PLUGIN_SLUG ); + + if ( $plugin_filename ) { + return activate_plugin( $plugin_filename ); + } + } +} diff --git a/src/products/class-site-accelerator.php b/src/products/class-site-accelerator.php new file mode 100644 index 00000000..42cda9bc --- /dev/null +++ b/src/products/class-site-accelerator.php @@ -0,0 +1,179 @@ + true, + 'is_free' => true, + ); + } + + /** + * Checks whether the Product is active. + * + * @return boolean + */ + public static function is_active() { + return static::is_jetpack_plugin_active(); + } + + /** + * Checks whether the plugin is installed + * + * @return boolean + */ + public static function is_plugin_installed() { + return static::is_jetpack_plugin_installed(); + } + + /** + * 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=site%20accelerator' ); + } + + /** + * Activates the Jetpack plugin + * + * @return null|WP_Error Null on success, WP_Error on invalid file. + */ + public static function activate_plugin() { + $plugin_filename = static::get_installed_plugin_filename( self::JETPACK_PLUGIN_SLUG ); + + if ( $plugin_filename ) { + return activate_plugin( $plugin_filename ); + } + } +}