From b0ecb92e4951c247eddd76e477874cdfe568038b Mon Sep 17 00:00:00 2001 From: Mukesh Panchal Date: Mon, 18 Dec 2023 14:09:32 +0530 Subject: [PATCH 1/5] Add module migration pointer --- admin/load.php | 143 +++++++++++++++++++++++++++++++++---------------- 1 file changed, 97 insertions(+), 46 deletions(-) diff --git a/admin/load.php b/admin/load.php index 7ba97c02c0..afb398539a 100644 --- a/admin/load.php +++ b/admin/load.php @@ -403,6 +403,41 @@ function perflab_admin_pointer( $hook_suffix ) { $current_user = get_current_user_id(); $dismissed = explode( ',', (string) get_user_meta( $current_user, 'dismissed_wp_pointers', true ) ); + /* + * Show an admin pointer if module is active to prompt + * for an action to use the standalone plugin instead. + */ + $available_module_names = perflab_get_modules_compatible_with_standalone_plugin(); + if ( + ! empty( $available_module_names ) + && current_user_can( 'install_plugins' ) + && current_user_can( 'activate_plugins' ) + && ! in_array( 'perflab-module-migration-pointer', $dismissed, true ) + ) { + // Enqueue the pointer logic and return early. + wp_enqueue_style( 'wp-pointer' ); + wp_enqueue_script( 'wp-pointer' ); + add_action( + 'admin_print_footer_scripts', + static function () { + $content = __( 'Your site is using modules which will be removed in the future in favor of their equivalent standalone plugins.', 'performance-lab' ); + $content .= ' ' . sprintf( + /* translators: %s: settings page link */ + __( 'Open %s to learn more about next steps to keep the functionality available.', 'performance-lab' ), + '' . __( 'Settings > Performance', 'performance-lab' ) . '' + ); + perflab_render_pointer( + 'perflab-module-migration-pointer', + array( + 'heading' => __( 'Action required', 'performance-lab' ), + 'content' => $content, + ) + ); + } + ); + return; + } + if ( in_array( 'perflab-admin-pointer', $dismissed, true ) ) { return; } @@ -743,58 +778,74 @@ function perflab_plugin_admin_notices() { '; + $message .= sprintf( + /* translators: Module name */ + esc_html__( 'Your site is using the "%s" module which will be removed in the future in favor of its equivalent standalone plugin.', 'performance-lab' ), + esc_attr( $available_module_names[0] ) + ); + $message .= ' '; + $message .= esc_html__( 'Please click the following button to install and activate the relevant plugin in favor of the module. This will not impact any of the underlying functionality.', 'performance-lab' ); + $message .= '

'; + } else { + $message = '

'; + $message .= esc_html__( 'Your site is using modules which will be removed in the future in favor of their equivalent standalone plugins.', 'performance-lab' ); + $message .= ' '; + $message .= esc_html__( 'Please click the following button to install and activate the relevant plugins in favor of the modules. This will not impact any of the underlying functionality.', 'performance-lab' ); + $message .= '

'; + $message .= '' . esc_html__( 'Available standalone plugins:', 'performance-lab' ) . ''; + $message .= '
    '; + foreach ( $available_module_names as $module_name ) { + $message .= sprintf( '
  1. %s
  2. ', esc_html( $module_name ) ); } + $message .= '
'; + } - if ( 1 === $modules_count ) { - $message = '

'; - $message .= sprintf( - /* translators: Module name */ - esc_html__( 'Your site is using the "%s" module which will be removed in the future in favor of its equivalent standalone plugin.', 'performance-lab' ), - esc_attr( $available_module_names[0] ) - ); - $message .= ' '; - $message .= esc_html__( 'Please click the following button to install and activate the relevant plugin in favor of the module. This will not impact any of the underlying functionality.', 'performance-lab' ); - $message .= '

'; - } else { - $message = '

'; - $message .= esc_html__( 'Your site is using modules which will be removed in the future in favor of their equivalent standalone plugins.', 'performance-lab' ); - $message .= ' '; - $message .= esc_html__( 'Please click the following button to install and activate the relevant plugins in favor of the modules. This will not impact any of the underlying functionality.', 'performance-lab' ); - $message .= '

'; - $message .= '' . esc_html__( 'Available standalone plugins:', 'performance-lab' ) . ''; - $message .= '
    '; - foreach ( $available_module_names as $module_name ) { - $message .= sprintf( '
  1. %s
  2. ', esc_html( $module_name ) ); - } - $message .= '
'; - } + ?> +
+ +

+ + +

+
+ -
- -

- - -

-
- Date: Mon, 18 Dec 2023 14:39:12 +0530 Subject: [PATCH 2/5] Update pointer heading --- admin/load.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/admin/load.php b/admin/load.php index afb398539a..c593ec205c 100644 --- a/admin/load.php +++ b/admin/load.php @@ -429,7 +429,7 @@ static function () { perflab_render_pointer( 'perflab-module-migration-pointer', array( - 'heading' => __( 'Action required', 'performance-lab' ), + 'heading' => __( 'Performance Lab: Action required', 'performance-lab' ), 'content' => $content, ) ); From c8ac7e0698bf0a3cfb53d6585b46fa1c2d3b437b Mon Sep 17 00:00:00 2001 From: Mukesh Panchal Date: Mon, 18 Dec 2023 14:51:58 +0530 Subject: [PATCH 3/5] Remove string concatenation --- admin/load.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/admin/load.php b/admin/load.php index c593ec205c..3347cbf2f3 100644 --- a/admin/load.php +++ b/admin/load.php @@ -420,10 +420,9 @@ function perflab_admin_pointer( $hook_suffix ) { add_action( 'admin_print_footer_scripts', static function () { - $content = __( 'Your site is using modules which will be removed in the future in favor of their equivalent standalone plugins.', 'performance-lab' ); - $content .= ' ' . sprintf( + $content = sprintf( /* translators: %s: settings page link */ - __( 'Open %s to learn more about next steps to keep the functionality available.', 'performance-lab' ), + __( 'Your site is using modules which will be removed in the future in favor of their equivalent standalone plugins. Open %s to learn more about next steps to keep the functionality available.', 'performance-lab' ), '' . __( 'Settings > Performance', 'performance-lab' ) . '' ); perflab_render_pointer( From d855b9e67bcc8ec5a8dc22e24f325752724d421f Mon Sep 17 00:00:00 2001 From: Mukesh Panchal Date: Tue, 19 Dec 2023 10:59:02 +0530 Subject: [PATCH 4/5] Address review feedback --- admin/load.php | 44 +++++++++++++++++++++----------------------- 1 file changed, 21 insertions(+), 23 deletions(-) diff --git a/admin/load.php b/admin/load.php index 4fb474b853..49d0a6435e 100644 --- a/admin/load.php +++ b/admin/load.php @@ -407,12 +407,12 @@ function perflab_admin_pointer( $hook_suffix ) { $dismissed = explode( ',', (string) get_user_meta( $current_user, 'dismissed_wp_pointers', true ) ); /* - * Show an admin pointer if module is active to prompt - * for an action to use the standalone plugin instead. + * If there are any active modules with inactive standalone plugins, + * show an admin pointer to prompt the user to migrate. */ - $available_module_names = perflab_get_modules_compatible_with_standalone_plugin(); + $active_modules_with_inactive_plugins = perflab_get_active_module_data_with_inactive_standalone_plugins(); if ( - ! empty( $available_module_names ) + ! empty( $active_modules_with_inactive_plugins ) && current_user_can( 'install_plugins' ) && current_user_can( 'activate_plugins' ) && ! in_array( 'perflab-module-migration-pointer', $dismissed, true ) @@ -425,8 +425,8 @@ function perflab_admin_pointer( $hook_suffix ) { static function () { $content = sprintf( /* translators: %s: settings page link */ - __( 'Your site is using modules which will be removed in the future in favor of their equivalent standalone plugins. Open %s to learn more about next steps to keep the functionality available.', 'performance-lab' ), - '' . __( 'Settings > Performance', 'performance-lab' ) . '' + esc_html__( 'Your site is using modules which will be removed in the future in favor of their equivalent standalone plugins. Open %s to learn more about next steps to keep the functionality available.', 'performance-lab' ), + '' . esc_html__( 'Settings > Performance', 'performance-lab' ) . '' ); perflab_render_pointer( 'perflab-module-migration-pointer', @@ -470,8 +470,8 @@ function perflab_render_pointer( $pointer_id = 'perflab-admin-pointer', $args = if ( ! isset( $args['content'] ) ) { $args['content'] = sprintf( /* translators: %s: settings page link */ - __( 'You can now test upcoming WordPress performance features. Open %s to individually toggle the performance features included in the plugin.', 'performance-lab' ), - '' . __( 'Settings > Performance', 'performance-lab' ) . '' + esc_html__( 'You can now test upcoming WordPress performance features. Open %s to individually toggle the performance features included in the plugin.', 'performance-lab' ), + '' . esc_html__( 'Settings > Performance', 'performance-lab' ) . '' ); } @@ -791,15 +791,13 @@ function perflab_plugin_admin_notices() { '; @@ -839,26 +837,26 @@ function perflab_plugin_admin_notices() { } /** - * Returns an array of standalone plugins name which currently active modules. + * Returns an array of active module data with inactive standalone plugins. * * @since n.e.x.t * - * @return string[] + * @return array Returns an array of active module data with inactive standalone plugins, otherwise an empty array. */ -function perflab_get_modules_compatible_with_standalone_plugin() { +function perflab_get_active_module_data_with_inactive_standalone_plugins() { $active_modules_with_plugins = perflab_get_active_modules_with_standalone_plugins(); if ( empty( $active_modules_with_plugins ) ) { - return; + return array(); } $module_data = perflab_get_modules(); - $available_module_names = array(); - foreach ( $active_modules_with_plugins as $module_slug ) { - if ( isset( $module_data[ $module_slug ] ) && ! perflab_is_standalone_plugin_loaded( $module_slug ) ) { - $available_module_names[] = $module_data[ $module_slug ]['name']; + $available_modules_data = array(); + foreach ( $active_modules_with_plugins as $module_dir ) { + if ( isset( $module_data[ $module_dir ] ) && ! perflab_is_standalone_plugin_loaded( $module_dir ) ) { + $available_modules_data[] = $module_data[ $module_dir ]; } } - return $available_module_names; + return $available_modules_data; } /** From 6d4cd74afd51930305f4ca9639efa58327066167 Mon Sep 17 00:00:00 2001 From: Felix Arntz Date: Tue, 19 Dec 2023 07:57:24 -0800 Subject: [PATCH 5/5] Minor update to return doc. --- admin/load.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/admin/load.php b/admin/load.php index 49d0a6435e..fb5e39e29c 100644 --- a/admin/load.php +++ b/admin/load.php @@ -841,7 +841,7 @@ function perflab_plugin_admin_notices() { * * @since n.e.x.t * - * @return array Returns an array of active module data with inactive standalone plugins, otherwise an empty array. + * @return array Array of active module data with inactive standalone plugins, otherwise an empty array. */ function perflab_get_active_module_data_with_inactive_standalone_plugins() { $active_modules_with_plugins = perflab_get_active_modules_with_standalone_plugins();