Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]
},
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: enhancement
Comment: Settings: Point the Writing links to My Jetpack › Features, behind the settings consolidation flag.


19 changes: 18 additions & 1 deletion projects/plugins/jetpack/src/class-unavailable-blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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' ),
Expand Down Expand Up @@ -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.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: changed
Comment: Notices: Point the Settings › Writing notice to My Jetpack › Features, behind the settings consolidation flag.


Original file line number Diff line number Diff line change
Expand Up @@ -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 '<div class="notice notice-info is-dismissible" data-notice="options_writing"><p>' .
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' ),
'<a href="' . esc_url( $jetpack_settings_url ) . '">',
esc_html( $message ),
'<a href="' . esc_url( $url ) . '">',
'</a>'
)
. '</p></div>';
Expand Down
Loading