From f9121170690f7ceb9bd2fccc5ab17296ff25a1d5 Mon Sep 17 00:00:00 2001 From: dainemawer Date: Tue, 1 Mar 2022 10:58:08 +0200 Subject: [PATCH 01/13] Added admin pointer --- admin/load.php | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/admin/load.php b/admin/load.php index cb7a77319c..d28a96bf3e 100644 --- a/admin/load.php +++ b/admin/load.php @@ -336,3 +336,67 @@ function perflab_get_module_data( $module_file ) { return $module_data; } + +function perflab_admin_pointer() { + + wp_enqueue_style( 'wp-pointer' ); + wp_enqueue_script( 'wp-pointer', false, array( 'jquery' ) ); + + $current_user = get_current_user_id(); + $meta_key = 'my-pointer-slug-dismissed'; + + $heading = __( 'Performance Lab', 'performance-lab' ); + $content = sprintf(__( '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' ) .''); + + if ( ! get_user_meta( $current_user, $meta_key, true ) ) : ?> + + Date: Tue, 1 Mar 2022 11:13:43 +0200 Subject: [PATCH 02/13] Fixed linting issues --- admin/load.php | 39 ++++++++++++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 9 deletions(-) diff --git a/admin/load.php b/admin/load.php index d28a96bf3e..38ce2012d1 100644 --- a/admin/load.php +++ b/admin/load.php @@ -337,18 +337,29 @@ function perflab_get_module_data( $module_file ) { return $module_data; } +/** + * Initialise Admin Pointer + * + * Handles the bootstrapping of the admin pointer. + * Mainly jQuery code that is self-initialising. + * + * @since 1.0.0 + * @return void + */ function perflab_admin_pointer() { - wp_enqueue_style( 'wp-pointer' ); - wp_enqueue_script( 'wp-pointer', false, array( 'jquery' ) ); + wp_enqueue_style( 'wp-pointer' ); + wp_enqueue_script( 'wp-pointer', false, array( 'jquery' ) ); $current_user = get_current_user_id(); - $meta_key = 'my-pointer-slug-dismissed'; + $meta_key = 'my-pointer-slug-dismissed'; $heading = __( 'Performance Lab', 'performance-lab' ); - $content = sprintf(__( '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' ) .''); + /* translators: %s: settings page link */ + $content = sprintf( __( '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' ) . '' ); - if ( ! get_user_meta( $current_user, $meta_key, true ) ) : ?> + if ( ! get_user_meta( $current_user, $meta_key, true ) ) : + ?> - Date: Wed, 2 Mar 2022 07:08:59 +0200 Subject: [PATCH 03/13] Removed meta calls, only render pointer on certain screens, cleaned up conditional logic flow --- admin/load.php | 118 ++++++++++++++++++++++++------------------------- 1 file changed, 59 insertions(+), 59 deletions(-) diff --git a/admin/load.php b/admin/load.php index 38ce2012d1..749a9eded2 100644 --- a/admin/load.php +++ b/admin/load.php @@ -5,6 +5,8 @@ * @package performance-lab */ +define( 'PERLAB_ADMIN_POINTER', 'perflab-admin-pointer' ); + /** * Adds the modules page to the Settings menu. * @@ -343,81 +345,79 @@ function perflab_get_module_data( $module_file ) { * Handles the bootstrapping of the admin pointer. * Mainly jQuery code that is self-initialising. * + * @param string $hook_suffix The current admin page. * @since 1.0.0 - * @return void */ -function perflab_admin_pointer() { +function perflab_admin_pointer( $hook_suffix ) { - wp_enqueue_style( 'wp-pointer' ); - wp_enqueue_script( 'wp-pointer', false, array( 'jquery' ) ); + if ( ! in_array( $hook_suffix, array( 'index.php', 'plugins.php' ), true ) ) { + return; + } $current_user = get_current_user_id(); - $meta_key = 'my-pointer-slug-dismissed'; - - $heading = __( 'Performance Lab', 'performance-lab' ); - /* translators: %s: settings page link */ - $content = sprintf( __( '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' ) . '' ); - - if ( ! get_user_meta( $current_user, $meta_key, true ) ) : - ?> - - array( + 'href' => array(), + ), + ); + + $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' ) . '' + ); + + ?> + + Date: Fri, 4 Mar 2022 12:17:29 -0600 Subject: [PATCH 04/13] Removal of additional indentation level. --- admin/load.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/admin/load.php b/admin/load.php index 33ac4cbcf6..e66a8d89de 100644 --- a/admin/load.php +++ b/admin/load.php @@ -416,7 +416,7 @@ function perflab_render_pointer() { jQuery( '#menu-settings' ).pointer( options ).pointer( 'open' ); - } ); + } ); Date: Fri, 4 Mar 2022 12:18:10 -0600 Subject: [PATCH 05/13] Create admin url using `admin_url` function. Co-authored-by: Felix Arntz --- admin/load.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/admin/load.php b/admin/load.php index e66a8d89de..f12934d55b 100644 --- a/admin/load.php +++ b/admin/load.php @@ -388,7 +388,7 @@ function perflab_render_pointer() { $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' ) . '' + '' . __( 'Settings > Performance', 'performance-lab' ) . '' ); ?> From 906dea17b715912a699a3ff3d84acd0d0918d152 Mon Sep 17 00:00:00 2001 From: Crisoforo Gaspar Date: Fri, 4 Mar 2022 12:53:46 -0600 Subject: [PATCH 06/13] Update hook and function definition Make sure the function is only added when need it. --- admin/load.php | 60 ++++++++++++++++++++++++-------------------------- 1 file changed, 29 insertions(+), 31 deletions(-) diff --git a/admin/load.php b/admin/load.php index f12934d55b..83879fb624 100644 --- a/admin/load.php +++ b/admin/load.php @@ -341,34 +341,6 @@ function perflab_get_module_data( $module_file ) { return $module_data; } -/** - * Initialise Admin Pointer - * - * Handles the bootstrapping of the admin pointer. - * Mainly jQuery code that is self-initialising. - * - * @param string $hook_suffix The current admin page. - * @since 1.0.0 - */ -function perflab_admin_pointer( $hook_suffix ) { - - if ( ! in_array( $hook_suffix, array( 'index.php', 'plugins.php' ), true ) ) { - return; - } - - $current_user = get_current_user_id(); - $dismissed = explode( ',', (string) get_user_meta( $current_user, 'dismissed_wp_pointers', true ) ); - - if ( in_array( PERLAB_ADMIN_POINTER, $dismissed, true ) ) { - return; - } - - // Enqueue pointer CSS and JS. - wp_enqueue_style( 'wp-pointer' ); - wp_enqueue_script( 'wp-pointer' ); -} -add_action( 'admin_enqueue_scripts', 'perflab_admin_pointer' ); - /** * Renders the Admin Pointer * @@ -377,7 +349,6 @@ function perflab_admin_pointer( $hook_suffix ) { * @since 1.0.0 */ function perflab_render_pointer() { - $heading = __( 'Performance Lab', 'performance-lab' ); $wp_kses_options = array( 'a' => array( @@ -415,12 +386,39 @@ function perflab_render_pointer() { }; jQuery( '#menu-settings' ).pointer( options ).pointer( 'open' ); - } ); Date: Fri, 4 Mar 2022 12:54:24 -0600 Subject: [PATCH 07/13] Replace constant with string literal instead. Co-authored-by: Felix Arntz --- admin/load.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/admin/load.php b/admin/load.php index f12934d55b..3deae228b0 100644 --- a/admin/load.php +++ b/admin/load.php @@ -407,7 +407,7 @@ function perflab_render_pointer() { jQuery.post( window.ajaxurl, { - pointer: '', + pointer: 'perflab-admin-pointer', action: 'dismiss-wp-pointer', } ); From 3a55053e5a77352efa8e4abbcd9d1d8f17ede9d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Crisoforo=20Gaspar=20Hern=C3=A1ndez?= Date: Fri, 4 Mar 2022 12:54:31 -0600 Subject: [PATCH 08/13] Replace constant with string literal instead. Co-authored-by: Felix Arntz --- admin/load.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/admin/load.php b/admin/load.php index 3deae228b0..adf6bdda08 100644 --- a/admin/load.php +++ b/admin/load.php @@ -359,7 +359,7 @@ function perflab_admin_pointer( $hook_suffix ) { $current_user = get_current_user_id(); $dismissed = explode( ',', (string) get_user_meta( $current_user, 'dismissed_wp_pointers', true ) ); - if ( in_array( PERLAB_ADMIN_POINTER, $dismissed, true ) ) { + if ( in_array( 'perflab-admin-pointer', $dismissed, true ) ) { return; } From 33ffd46aed1841aa3ea79b86456f547259b8aaa7 Mon Sep 17 00:00:00 2001 From: Crisoforo Gaspar Date: Fri, 4 Mar 2022 12:56:23 -0600 Subject: [PATCH 09/13] Removal of not used constant --- admin/load.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/admin/load.php b/admin/load.php index dec79834ad..179ccd4a57 100644 --- a/admin/load.php +++ b/admin/load.php @@ -4,9 +4,6 @@ * * @package performance-lab */ - -define( 'PERLAB_ADMIN_POINTER', 'perflab-admin-pointer' ); - /** * Adds the modules page to the Settings menu. * From a4d49a92f619bab95af4993e9d2622b0fb91c5d8 Mon Sep 17 00:00:00 2001 From: Crisoforo Gaspar Date: Fri, 4 Mar 2022 12:57:47 -0600 Subject: [PATCH 10/13] Removal of empty space --- admin/load.php | 1 - 1 file changed, 1 deletion(-) diff --git a/admin/load.php b/admin/load.php index 179ccd4a57..78281dc907 100644 --- a/admin/load.php +++ b/admin/load.php @@ -348,7 +348,6 @@ function perflab_get_module_data( $module_file ) { * @since 1.0.0 */ function perflab_admin_pointer( $hook_suffix ) { - if ( ! in_array( $hook_suffix, array( 'index.php', 'plugins.php' ), true ) ) { return; } From a60ebc175dfb9a737d6b99e3893bda9e5cde8014 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Crisoforo=20Gaspar=20Hern=C3=A1ndez?= Date: Fri, 4 Mar 2022 13:00:28 -0600 Subject: [PATCH 11/13] Removal of non required concatenation. Co-authored-by: Felix Arntz --- admin/load.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/admin/load.php b/admin/load.php index 78281dc907..c343ac3f63 100644 --- a/admin/load.php +++ b/admin/load.php @@ -392,7 +392,7 @@ function perflab_render_pointer() { jQuery( function() { // Pointer Options var options = { - content: '

' + '

', + content: '

', position: { edge: 'left', align: 'right', From ee57d47c56bf621da1fc0347ce8a500363880dd2 Mon Sep 17 00:00:00 2001 From: Crisoforo Gaspar Date: Fri, 4 Mar 2022 13:01:24 -0600 Subject: [PATCH 12/13] Fix linting error --- admin/load.php | 1 + 1 file changed, 1 insertion(+) diff --git a/admin/load.php b/admin/load.php index c343ac3f63..cb170fc4f1 100644 --- a/admin/load.php +++ b/admin/load.php @@ -4,6 +4,7 @@ * * @package performance-lab */ + /** * Adds the modules page to the Settings menu. * From b3ea66e44d4f0505b09d45ddd2601e11ea44c45e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Crisoforo=20Gaspar=20Hern=C3=A1ndez?= Date: Fri, 4 Mar 2022 16:59:21 -0600 Subject: [PATCH 13/13] Removing non required space. Co-authored-by: Adam Silverstein --- admin/load.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/admin/load.php b/admin/load.php index cb170fc4f1..8549efe210 100644 --- a/admin/load.php +++ b/admin/load.php @@ -405,7 +405,7 @@ function perflab_render_pointer() { window.ajaxurl, { pointer: 'perflab-admin-pointer', - action: 'dismiss-wp-pointer', + action: 'dismiss-wp-pointer', } ); }