diff --git a/projects/plugins/jetpack/_inc/lib/admin-pages/settings-redirect-map.json b/projects/plugins/jetpack/_inc/lib/admin-pages/settings-redirect-map.json index 1ca64a8b4656..2c80960b20f4 100644 --- a/projects/plugins/jetpack/_inc/lib/admin-pages/settings-redirect-map.json +++ b/projects/plugins/jetpack/_inc/lib/admin-pages/settings-redirect-map.json @@ -101,8 +101,8 @@ { "destination": "admin.php?page=my-jetpack#/features", "alreadyRedirects": true } ], "linkedFrom": [ - "plugins/jetpack Unavailable_Blocks::get_editor_data(): fixUrl for blocks the Blocks module turned off; wants admin.php?page=my-jetpack#/features?search=blocks", - "plugins/wpcomsh feature-moved-to-jetpack-notices.php: the notice on Settings > Writing" + "plugins/jetpack Unavailable_Blocks::get_editor_data(): fixUrl for blocks the Blocks module turned off, with the flag off", + "plugins/wpcomsh feature-moved-to-jetpack-notices.php: the notice on Settings > Writing, with the flag off" ] }, { diff --git a/projects/plugins/jetpack/changelog/update-settings-writing-links-to-features b/projects/plugins/jetpack/changelog/update-settings-writing-links-to-features new file mode 100644 index 000000000000..81d7f7f7f328 --- /dev/null +++ b/projects/plugins/jetpack/changelog/update-settings-writing-links-to-features @@ -0,0 +1,5 @@ +Significance: patch +Type: enhancement +Comment: Settings: Point the Writing links to My Jetpack › Features, behind the settings consolidation flag. + + diff --git a/projects/plugins/jetpack/src/class-unavailable-blocks.php b/projects/plugins/jetpack/src/class-unavailable-blocks.php index 195e1ec9cf3d..6b42d5d00d6e 100644 --- a/projects/plugins/jetpack/src/class-unavailable-blocks.php +++ b/projects/plugins/jetpack/src/class-unavailable-blocks.php @@ -10,6 +10,7 @@ use Automattic\Jetpack\Assets; use Automattic\Jetpack\Constants; use Automattic\Jetpack\Modules; +use Automattic\Jetpack\My_Jetpack\Initializer; use Automattic\Jetpack\Status; use Automattic\Jetpack\Status\Host; use Jetpack; @@ -121,7 +122,7 @@ public static function get_editor_data() { return array( 'reason' => $reason, 'canFix' => current_user_can( $is_disconnected ? 'jetpack_connect' : 'jetpack_manage_modules' ), - 'fixUrl' => admin_url( $is_disconnected ? 'admin.php?page=jetpack' : 'admin.php?page=jetpack#/writing' ), + 'fixUrl' => $is_disconnected ? admin_url( 'admin.php?page=jetpack' ) : self::get_blocks_module_url(), 'features' => $features, 'canManageModules' => current_user_can( 'jetpack_manage_modules' ), 'modulesUrl' => admin_url( 'admin.php?page=jetpack_modules' ), @@ -228,6 +229,22 @@ public static function get_shipped_blocks() { return array_values( array_diff( $blocks, self::CONDITIONAL_BLOCKS ) ); } + /** + * Where an admin turns the Blocks module back on. + * + * @return string + */ + private static function get_blocks_module_url() { + if ( ! method_exists( Initializer::class, 'is_settings_consolidation_enabled' ) || ! Initializer::is_settings_consolidation_enabled() ) { + return admin_url( 'admin.php?page=jetpack#/writing' ); + } + + // Features searches translated module names, so an English term would miss the row in other locales. + $i18n = function_exists( 'jetpack_get_module_i18n' ) ? jetpack_get_module_i18n( 'blocks' ) : array(); + + return admin_url( 'admin.php?page=my-jetpack#/features?search=' . rawurlencode( ! empty( $i18n['name'] ) ? $i18n['name'] : 'blocks' ) ); + } + /** * Whether a filter or the host's feature policy keeps a module inactive. * diff --git a/projects/plugins/jetpack/tests/php/src/Unavailable_Blocks_Test.php b/projects/plugins/jetpack/tests/php/src/Unavailable_Blocks_Test.php index ffccfca84632..705db763bd80 100644 --- a/projects/plugins/jetpack/tests/php/src/Unavailable_Blocks_Test.php +++ b/projects/plugins/jetpack/tests/php/src/Unavailable_Blocks_Test.php @@ -6,6 +6,7 @@ */ use Automattic\Jetpack\Constants; +use Automattic\Jetpack\My_Jetpack\Initializer; use Automattic\Jetpack\Plugin\Unavailable_Blocks; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\DataProvider; @@ -35,6 +36,8 @@ public function tear_down() { remove_all_filters( 'jetpack_is_connection_ready' ); remove_all_filters( 'jetpack_gutenberg' ); remove_all_filters( 'jetpack_active_modules' ); + remove_all_filters( 'jetpack_feature_flag_enabled_' . Initializer::SETTINGS_CONSOLIDATION_FLAG ); + remove_all_filters( 'jetpack_my_jetpack_modules_management_available' ); Jetpack_Options::delete_option( 'active_modules' ); Jetpack_Modules_Overrides::instance()->clear_cache(); \Automattic\Jetpack\Status\Cache::clear(); @@ -212,7 +215,47 @@ public function test_editor_data_offers_the_fix_only_to_users_who_can_apply_it( $this->assertSame( 'blocks_module', $data['reason'] ); $this->assertSame( $can_fix, $data['canFix'] ); - $this->assertStringEndsWith( 'admin.php?page=jetpack#/writing', $data['fixUrl'] ); + } + + /** + * Whether settings consolidation is on, filters that override the rest of the site, and where the fix should link. + * + * @return array[] + */ + public static function provide_fix_urls() { + return array( + 'flag off' => array( false, array(), 'admin.php?page=jetpack#/writing' ), + 'flag on' => array( true, array(), 'admin.php?page=my-jetpack#/features?search=Blocks' ), + 'flag on, host hides My Jetpack' => array( true, array( 'jetpack_my_jetpack_modules_management_available' => '__return_false' ), 'admin.php?page=jetpack#/writing' ), + 'flag on, not connected' => array( true, array( 'jetpack_is_connection_ready' => '__return_false' ), 'admin.php?page=jetpack' ), + ); + } + + /** + * @param bool $consolidated Whether the settings consolidation flag is on. + * @param string[] $filters Callbacks by hook name, added after the ones set_up() adds. + * @param string $expected The fix URL, relative to wp-admin. + * + * @dataProvider provide_fix_urls + */ + #[DataProvider( 'provide_fix_urls' )] + public function test_fix_url_follows_the_settings_consolidation_flag( $consolidated, $filters, $expected ) { + global $_registered_pages; + $registered_pages = $_registered_pages; + wp_set_current_user( self::factory()->user->create( array( 'role' => 'administrator' ) ) ); + Jetpack_Options::update_option( 'active_modules', array() ); + do_action( 'my_jetpack_init' ); + $_registered_pages[ get_plugin_page_hookname( 'my-jetpack', 'jetpack' ) ] = true; + add_filter( 'jetpack_feature_flag_enabled_' . Initializer::SETTINGS_CONSOLIDATION_FLAG, $consolidated ? '__return_true' : '__return_false' ); + foreach ( $filters as $hook => $callback ) { + add_filter( $hook, $callback, 1001 ); + } + + try { + $this->assertSame( admin_url( $expected ), ( (array) Unavailable_Blocks::get_editor_data() )['fixUrl'] ); + } finally { + $_registered_pages = $registered_pages; + } } public function test_editor_data_is_null_without_a_site_wide_cause() { diff --git a/projects/plugins/wpcomsh/changelog/update-settings-writing-links-to-features b/projects/plugins/wpcomsh/changelog/update-settings-writing-links-to-features new file mode 100644 index 000000000000..1934a1886e8e --- /dev/null +++ b/projects/plugins/wpcomsh/changelog/update-settings-writing-links-to-features @@ -0,0 +1,5 @@ +Significance: patch +Type: changed +Comment: Notices: Point the Settings › Writing notice to My Jetpack › Features, behind the settings consolidation flag. + + diff --git a/projects/plugins/wpcomsh/notices/feature-moved-to-jetpack-notices.php b/projects/plugins/wpcomsh/notices/feature-moved-to-jetpack-notices.php index 712fb55de8e8..ab5bba225df7 100644 --- a/projects/plugins/wpcomsh/notices/feature-moved-to-jetpack-notices.php +++ b/projects/plugins/wpcomsh/notices/feature-moved-to-jetpack-notices.php @@ -7,19 +7,28 @@ /** * Displays a dismissible admin notice on 'options-writing.php' informing the user that some settings have moved - * to Jetpack Settings > Writing. + * to Jetpack Settings › Writing, or to My Jetpack › Features once settings consolidation is on. */ function wpcom_writing_features_moved_notice() { global $pagenow; if ( 'options-writing.php' === $pagenow ) { $has_dismissed = get_option( 'wpcom_writing_features_notice_dismissed' ); if ( ! $has_dismissed ) { - $jetpack_settings_url = admin_url( 'admin.php?page=jetpack#/writing' ); + $my_jetpack = 'Automattic\Jetpack\My_Jetpack\Initializer'; + // @phan-suppress-next-line PhanUndeclaredClassReference -- My Jetpack ships with the Jetpack plugin, at a version wpcomsh does not control. + if ( method_exists( $my_jetpack, 'is_settings_consolidation_enabled' ) && $my_jetpack::is_settings_consolidation_enabled() ) { + $url = admin_url( 'admin.php?page=my-jetpack#/features' ); + // Translators: %1$s: Start HTML link tag with the URL to My Jetpack's Features page, %2$s: End HTML link tag. + $message = __( 'Visit %1$sMy Jetpack › Features%2$s for more writing settings powered by Jetpack.', 'wpcomsh' ); + } else { + $url = admin_url( 'admin.php?page=jetpack#/writing' ); + // Translators: %1$s: Start HTML link tag with the URL to Jetpack settings, %2$s: End HTML link tag. + $message = __( 'Visit %1$sJetpack Settings%2$s for more writing settings powered by Jetpack.', 'wpcomsh' ); + } echo '

' . sprintf( - // Translators: %1$s: Start HTML link tag with the URL to Jetpack settings, %2$s: End HTML link tag. - esc_html__( 'Visit %1$sJetpack Settings%2$s for more writing settings powered by Jetpack.', 'wpcomsh' ), - '', + esc_html( $message ), + '', '' ) . '

';