Skip to content

Commit

Permalink
SEO Tools: make feature available on non-connected sites. (#36528)
Browse files Browse the repository at this point in the history
* SEO Tools: make feature available on non-connected sites.

The module was previously restricted to paid Jetpack plans. When we added the options to customize the different SEO options to wp-admin (in the block editor and in Jetpack settings), we made the module available to all plans. It is still restricted to paid plans on WordPress.com though.

As a result:

- On self-hosted, we do not need to be checking if the feature is available; it always is.
- On WordPress.com, we should be checking if the feature is available.
- On self-hosted, the feature can consequently be available on offline mode.

* Add missing parameter to stub function

The original function on WordPress.com simple does include that second parameter.

* Update Phan config

* Bump version

* Update plugin registration to match simplified module availability

* Bump version

* Add plan check back to editor extension

It does not currently make any calls to WordPress.com behind the scenes. `set_availability_for_plan` relies on `Current_Plan::supports()` behind the scenes, but without passing a `$refresh_from_wpcom` second parameter so it only relies on local data on self-hosted sites.

* Remove offline mode check in wp-admin UI
  • Loading branch information
jeherve authored Mar 28, 2024
1 parent 55ccd60 commit 2ece631
Show file tree
Hide file tree
Showing 12 changed files with 30 additions and 37 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: changed

General: update Phan configuration.
2 changes: 1 addition & 1 deletion projects/packages/jetpack-mu-wpcom/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"private": true,
"name": "@automattic/jetpack-mu-wpcom",
"version": "5.21.0",
"version": "5.21.1-alpha",
"description": "Enhances your site with features powered by WordPress.com",
"homepage": "https://github.com/Automattic/jetpack/tree/HEAD/projects/packages/jetpack-mu-wpcom/#readme",
"bugs": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* Jetpack_Mu_Wpcom main class.
*/
class Jetpack_Mu_Wpcom {
const PACKAGE_VERSION = '5.21.0';
const PACKAGE_VERSION = '5.21.1-alpha';
const PKG_DIR = __DIR__ . '/../';
const BASE_DIR = __DIR__ . '/';
const BASE_FILE = __FILE__;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: changed

General: update Phan configuration.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class Scheduled_Updates {
*
* @var string
*/
const PACKAGE_VERSION = '0.5.2';
const PACKAGE_VERSION = '0.5.3-alpha';
/**
* The cron event hook for the scheduled plugins update.
*
Expand Down
2 changes: 1 addition & 1 deletion projects/plugins/jetpack/.phan/baseline.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@
'_inc/lib/admin-pages/class-jetpack-about-page.php' => ['PhanTypeMismatchArgument', 'PhanTypeMismatchArgumentProbablyReal'],
'_inc/lib/admin-pages/class-jetpack-redux-state-helper.php' => ['PhanParamTooMany', 'PhanPluginDuplicateConditionalNullCoalescing', 'PhanRedundantCondition', 'PhanTypeMismatchArgument', 'PhanTypeMismatchArgumentProbablyReal', 'PhanTypeMismatchDimAssignment'],
'_inc/lib/admin-pages/class.jetpack-admin-page.php' => ['PhanDeprecatedProperty', 'PhanTypeMismatchArgumentProbablyReal', 'PhanTypeMismatchReturnProbablyReal', 'PhanUndeclaredProperty'],
'_inc/lib/class-jetpack-ai-helper.php' => ['PhanParamTooMany', 'PhanTypeMismatchArgument', 'PhanTypeMismatchArgumentProbablyReal', 'PhanTypeMismatchPropertyDefault', 'PhanUndeclaredClassMethod', 'PhanUndeclaredFunction'],
'_inc/lib/class-jetpack-ai-helper.php' => ['PhanTypeMismatchArgument', 'PhanTypeMismatchArgumentProbablyReal', 'PhanTypeMismatchPropertyDefault', 'PhanUndeclaredClassMethod', 'PhanUndeclaredFunction'],
'_inc/lib/class-jetpack-currencies.php' => ['PhanTypeMismatchArgument', 'PhanTypeMismatchArgumentInternal'],
'_inc/lib/class-jetpack-google-drive-helper.php' => ['PhanTypeMismatchArgumentProbablyReal', 'PhanTypeMismatchReturnProbablyReal', 'PhanUndeclaredClassMethod', 'PhanUndeclaredFunction'],
'_inc/lib/class-jetpack-instagram-gallery-helper.php' => ['PhanTypeMismatchArgument', 'PhanTypeMismatchArgumentProbablyReal', 'PhanUndeclaredClassMethod', 'PhanUndeclaredFunction'],
Expand Down
4 changes: 1 addition & 3 deletions projects/plugins/jetpack/_inc/client/traffic/seo.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,7 @@ export const SEO = withModuleSettingsFormHelpers(
};

render() {
const isOfflineMode = this.props.isOfflineMode,
seo = this.props.getModule( 'seo-tools' ),
const seo = this.props.getModule( 'seo-tools' ),
isSeoActive = this.props.getOptionValue( seo.module ),
customSeoTitles = this.props.getOptionValue( 'advanced_seo_title_formats' ),
frontPageMetaDescription = this.props.getOptionValue(
Expand Down Expand Up @@ -204,7 +203,6 @@ export const SEO = withModuleSettingsFormHelpers(
</ModuleToggle>
</SettingsGroup>
{ isSeoActive &&
! isOfflineMode &&
! isFetchingPluginsData( this.props.state ) &&
! hasConflictingSeoPlugin && (
<>
Expand Down
4 changes: 4 additions & 0 deletions projects/plugins/jetpack/changelog/update-seo-settings
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: compat

SEO Tools: make the feature available on non-connected sites.
31 changes: 6 additions & 25 deletions projects/plugins/jetpack/extensions/plugins/seo/seo.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,13 @@

namespace Automattic\Jetpack\Extensions\Seo;

use Automattic\Jetpack\Connection\Manager as Connection_Manager;
use Automattic\Jetpack\Status;
use Automattic\Jetpack\Status\Host;
use Jetpack_Gutenberg;

/**
* Register SEO plugin.
*
* @return void
*/
function register_plugins() {
// Setting availability for Advanced SEO plan.
Jetpack_Gutenberg::set_availability_for_plan( 'advanced-seo' );

// On WPCOM sites we handle plan with Upsell message if needed.
// On Self-Hosted we check if there's an active connection and if the site is not in offline mode.
$is_wpcom_platform = ( new Host() )->is_wpcom_platform();
if (
$is_wpcom_platform
|| ( ( new Connection_Manager( 'jetpack' ) )->has_connected_owner() && ! ( new Status() )->is_offline_mode() )
) {
Jetpack_Gutenberg::set_extension_available( 'jetpack-seo' );
add_action(
'jetpack_register_gutenberg_extensions',
function () {
\Jetpack_Gutenberg::set_availability_for_plan( 'advanced-seo' );
\Jetpack_Gutenberg::set_extension_available( 'jetpack-seo' );
}
}

add_action( 'jetpack_register_gutenberg_extensions', __NAMESPACE__ . '\register_plugins' );
);

add_filter(
'jetpack_set_available_extensions',
Expand Down
2 changes: 1 addition & 1 deletion projects/plugins/jetpack/modules/seo-tools.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* Sort Order: 35
* Recommendation Order: 15
* First Introduced: 4.4
* Requires Connection: Yes
* Requires Connection: No
* Requires User Connection: No
* Auto Activate: No
* Module Tags: Social, Appearance
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
* @package automattic/jetpack
*/

use Automattic\Jetpack\Current_Plan as Jetpack_Plan;

/**
* Class containing utility static methods that other SEO tools are relying on.
*/
Expand Down Expand Up @@ -41,7 +39,11 @@ public static function is_enabled_jetpack_seo() {
return false;
}

return Jetpack_Plan::supports( 'advanced-seo' );
if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) {
return wpcom_site_has_feature( 'advanced-seo', get_current_blog_id() );
}

return true;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion projects/plugins/jetpack/tests/php/lib/mock-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function wp_cache_is_enabled() {}
*
* @param string $feature The feature to check.
*/
function wpcom_site_has_feature( $feature ) {
function wpcom_site_has_feature( $feature, $blog_id = 0 ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
switch ( $feature ) {
case WPCOM_Features::ATOMIC:
case WPCOM_Features::MANAGE_PLUGINS:
Expand Down

0 comments on commit 2ece631

Please sign in to comment.