Skip to content

Commit

Permalink
My Jetpack: support features as recommendations (#40492)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
IanRamosC authored Dec 18, 2024
1 parent ca81f76 commit 21b4c4f
Show file tree
Hide file tree
Showing 6 changed files with 600 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: added

My Jetpack: add features as possible modules to the recommendations list.
38 changes: 21 additions & 17 deletions projects/packages/my-jetpack/src/class-products.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);

/**
Expand Down
38 changes: 38 additions & 0 deletions projects/packages/my-jetpack/src/products/class-module-product.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

namespace Automattic\Jetpack\My_Jetpack;

use Automattic\Jetpack\Connection\Manager as Connection_Manager;
use Jetpack;
use WP_Error;

Expand All @@ -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
*
Expand Down Expand Up @@ -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;
Expand Down
179 changes: 179 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,179 @@
<?php
/**
* Feature: Newsletter
*
* @package my-jetpack
*/

namespace Automattic\Jetpack\My_Jetpack\Products;

use Automattic\Jetpack\My_Jetpack\Module_Product;
use WP_Error;

/**
* Class responsible for handling the Newsletter module.
*/
class Newsletter extends Module_Product {

/**
* The product slug
*
* @var string
*/
public static $slug = 'newsletter';

/**
* The slug of the plugin associated with this product.
* Newsletter is a feature available as part of the Jetpack plugin.
*
* @var string
*/
public static $plugin_slug = self::JETPACK_PLUGIN_SLUG;

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

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

/**
* Whether this module is a Jetpack feature
*
* @var boolean
*/
public static $is_feature = true;

/**
* Whether this product requires a user connection
*
* @var boolean
*/
public static $requires_user_connection = true;

/**
* Whether this product has a standalone plugin
*
* @var bool
*/
public static $has_standalone_plugin = false;

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

/**
* Whether the product requires a plan to run
* The plan could be paid or free
*
* @var bool
*/
public static $requires_plan = false;

/**
* 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 'Newsletter';
}

/**
* Get the internationalized product description
*
* @return string
*/
public static function get_description() {
return __( 'Draw your readers from one post to another', 'jetpack-my-jetpack' );
}

/**
* Get the internationalized product long description
*
* @return string
*/
public static function get_long_description() {
return __( 'Draw your readers from one post to another, increasing overall traffic on your site', 'jetpack-my-jetpack' );
}

/**
* Get the internationalized feature list
*
* @return array Newsletter features list
*/
public static function get_features() {
return array();
}

/**
* Get the product princing details
*
* @return array Pricing details
*/
public static function get_pricing_for_ui() {
return array(
'available' => 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 );
}
}
}
Loading

0 comments on commit 21b4c4f

Please sign in to comment.