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

Committed via a GitHub action: https://github.com/Automattic/jetpack/actions/runs/12399469677

Upstream-Ref: Automattic/jetpack@21b4c4f
  • Loading branch information
IanRamosC authored and matticbot committed Dec 18, 2024
1 parent 82c8258 commit 1ae2b93
Show file tree
Hide file tree
Showing 15 changed files with 720 additions and 120 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"automattic/jetpack-connection": "^6.2.1",
"automattic/jetpack-device-detection": "^3.0.0",
"automattic/jetpack-image-cdn": "^0.7.2",
"automattic/jetpack-my-jetpack": "^5.1.3-alpha",
"automattic/jetpack-my-jetpack": "^5.2.0-alpha",
"automattic/jetpack-plugin-deactivation": "^0.3.1-alpha",
"automattic/jetpack-schema": "^0.2.0",
"automattic/jetpack-status": "^5.0.1",
Expand Down
7 changes: 5 additions & 2 deletions jetpack_vendor/automattic/jetpack-my-jetpack/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion jetpack_vendor/automattic/jetpack-my-jetpack/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
38 changes: 21 additions & 17 deletions jetpack_vendor/automattic/jetpack-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
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
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 1ae2b93

Please sign in to comment.