From 6ee4ab84f98b4ce402865fb29ecf3c5409d73a15 Mon Sep 17 00:00:00 2001 From: Paul English Date: Thu, 13 Jul 2023 12:45:31 +0100 Subject: [PATCH 01/10] fix: uses WP meta to stop the welcome message appearing --- plugin/src/Plugin.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/plugin/src/Plugin.php b/plugin/src/Plugin.php index 2f3e53c..fa54d21 100644 --- a/plugin/src/Plugin.php +++ b/plugin/src/Plugin.php @@ -9,6 +9,7 @@ class Plugin { public function __construct() { add_action( 'init', [ $this, 'add_seed_command' ], 1 ); + add_action( 'init', [ $this, 'initialize_admin_user_meta' ], 0 ); add_action( 'enqueue_block_editor_assets', [ $this, 'enqueue_assets' ], 1 ); $this->add_user_command(); @@ -89,4 +90,12 @@ public function set_user( $args, array $assoc_args ): void { file_put_contents( $user_id_file, $user_id ); WP_CLI::success( 'Current User set to ' . $args[0] ); } + + public function initialize_admin_user_meta(): void { + update_user_meta(1, 'wp_persisted_preferences', [ + "core/edit-post" => [ + "welcomeGuide" => false, + ], + ]); + } }; From 7c4deccf203dc9f20fc790cfa886c841ab690d91 Mon Sep 17 00:00:00 2001 From: Paul English Date: Fri, 14 Jul 2023 16:34:08 +0100 Subject: [PATCH 02/10] fix: removes welcome guide modal for non-admin users in WP 6.2 --- plugin/src/Fixtures/User.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/plugin/src/Fixtures/User.php b/plugin/src/Fixtures/User.php index 27cde56..abc8c0f 100644 --- a/plugin/src/Fixtures/User.php +++ b/plugin/src/Fixtures/User.php @@ -22,6 +22,13 @@ public function defaults(): array { 'description' => $this->faker->realText( 200 ), 'user_registered' => Utils\now(), 'role' => 'administrator', + 'meta_input' => [ + 'wp_persisted_preferences' => [ + "core/edit-post" => [ + "welcomeGuide" => false, + ], + ], + ], ]; } From c0646e67cce61e070a2a1777c227c743e8d3b2d5 Mon Sep 17 00:00:00 2001 From: Paul English Date: Fri, 14 Jul 2023 16:45:18 +0100 Subject: [PATCH 03/10] refactor: removes redundnant js for removing the welcome guide modal this is no longer necessary since we are using user meta to do this. --- plugin/assets/disable-tooltips.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/plugin/assets/disable-tooltips.js b/plugin/assets/disable-tooltips.js index acca5aa..c3f4b63 100755 --- a/plugin/assets/disable-tooltips.js +++ b/plugin/assets/disable-tooltips.js @@ -6,10 +6,6 @@ jQuery(document).ready(() => { const nux = select('core/nux'); if (!nux) { - if (select('core/edit-post').isFeatureActive('welcomeGuide')) { - dispatch('core/edit-post').toggleFeature('welcomeGuide'); - } - return; } From af59dc102e19b1dd9069f274ac54041e196070ee Mon Sep 17 00:00:00 2001 From: Paul English Date: Wed, 19 Jul 2023 14:52:17 +0100 Subject: [PATCH 04/10] refator: dynamically creates wp_persisted_preferences meta key --- plugin/src/Fixtures/User.php | 5 ++++- plugin/src/Plugin.php | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/plugin/src/Fixtures/User.php b/plugin/src/Fixtures/User.php index abc8c0f..a4c79dd 100644 --- a/plugin/src/Fixtures/User.php +++ b/plugin/src/Fixtures/User.php @@ -11,6 +11,9 @@ class User extends Fixture { * @return array */ public function defaults(): array { + global $wpdb; + $user_preferences_meta_key = $wpdb->get_blog_prefix() . 'persisted_preferences'; + return [ 'user_pass' => 'password', 'user_login' => $this->faker->unique()->userName(), @@ -23,7 +26,7 @@ public function defaults(): array { 'user_registered' => Utils\now(), 'role' => 'administrator', 'meta_input' => [ - 'wp_persisted_preferences' => [ + $user_preferences_meta_key => [ "core/edit-post" => [ "welcomeGuide" => false, ], diff --git a/plugin/src/Plugin.php b/plugin/src/Plugin.php index fa54d21..7beecf3 100644 --- a/plugin/src/Plugin.php +++ b/plugin/src/Plugin.php @@ -92,7 +92,10 @@ public function set_user( $args, array $assoc_args ): void { } public function initialize_admin_user_meta(): void { - update_user_meta(1, 'wp_persisted_preferences', [ + global $wpdb; + $user_preferences_meta_key = $wpdb->get_blog_prefix() . 'persisted_preferences'; + + update_user_meta(1, $user_preferences_meta_key, [ "core/edit-post" => [ "welcomeGuide" => false, ], From be983ed1c4990e02fe3aeaabcde449818e910918 Mon Sep 17 00:00:00 2001 From: Paul English Date: Wed, 19 Jul 2023 14:55:34 +0100 Subject: [PATCH 05/10] refactor: adds js for removing welcome guide back in this is necessary for versions of WP 6.0 and below. This also reverses commit c0646e67cce61e070a2a1777c227c743e8d3b2d --- plugin/assets/disable-tooltips.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/plugin/assets/disable-tooltips.js b/plugin/assets/disable-tooltips.js index c3f4b63..70234eb 100755 --- a/plugin/assets/disable-tooltips.js +++ b/plugin/assets/disable-tooltips.js @@ -6,6 +6,11 @@ jQuery(document).ready(() => { const nux = select('core/nux'); if (!nux) { + // needed for WP version <=6.0 + if (select('core/edit-post').isFeatureActive('welcomeGuide')) { + dispatch('core/edit-post').toggleFeature('welcomeGuide'); + } + return; } From f4f1e238580f8219dd835b400123b794f0faddf0 Mon Sep 17 00:00:00 2001 From: Paul English Date: Mon, 31 Jul 2023 14:02:38 +0100 Subject: [PATCH 06/10] docs: adds doc block on initialize_admin_user_meta --- plugin/src/Plugin.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/plugin/src/Plugin.php b/plugin/src/Plugin.php index 7beecf3..097659d 100644 --- a/plugin/src/Plugin.php +++ b/plugin/src/Plugin.php @@ -91,6 +91,12 @@ public function set_user( $args, array $assoc_args ): void { WP_CLI::success( 'Current User set to ' . $args[0] ); } + /** + * Sets default meta values on the root/admin user (this has to be done + * separately from the other users) + * + * @return void + */ public function initialize_admin_user_meta(): void { global $wpdb; $user_preferences_meta_key = $wpdb->get_blog_prefix() . 'persisted_preferences'; From 1393295ba192b5b01873b5cfb6c2dc31fc419056 Mon Sep 17 00:00:00 2001 From: Paul English Date: Mon, 31 Jul 2023 14:13:24 +0100 Subject: [PATCH 07/10] refactor: only sets preferences meta on admin if not yet set --- plugin/src/Plugin.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/plugin/src/Plugin.php b/plugin/src/Plugin.php index 097659d..2147542 100644 --- a/plugin/src/Plugin.php +++ b/plugin/src/Plugin.php @@ -101,10 +101,12 @@ public function initialize_admin_user_meta(): void { global $wpdb; $user_preferences_meta_key = $wpdb->get_blog_prefix() . 'persisted_preferences'; - update_user_meta(1, $user_preferences_meta_key, [ - "core/edit-post" => [ - "welcomeGuide" => false, - ], - ]); + if ( !get_user_meta(1, $user_preferences_meta_key) ) { + update_user_meta(1, $user_preferences_meta_key, [ + "core/edit-post" => [ + "welcomeGuide" => false, + ], + ]); + } } }; From 34eecaf3a93327ac75b4f66a165c8abc3d5666a1 Mon Sep 17 00:00:00 2001 From: Paul English Date: Mon, 31 Jul 2023 14:43:43 +0100 Subject: [PATCH 08/10] docs: amends code comment on welcome msg js fix for earlier WP versions --- plugin/assets/disable-tooltips.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin/assets/disable-tooltips.js b/plugin/assets/disable-tooltips.js index 70234eb..65749c9 100755 --- a/plugin/assets/disable-tooltips.js +++ b/plugin/assets/disable-tooltips.js @@ -6,7 +6,7 @@ jQuery(document).ready(() => { const nux = select('core/nux'); if (!nux) { - // needed for WP version <=6.0 + // needed for some earlier versions of WP if (select('core/edit-post').isFeatureActive('welcomeGuide')) { dispatch('core/edit-post').toggleFeature('welcomeGuide'); } From 27b0e351a6d69b7bfd299cfbb981e4ee11dc711f Mon Sep 17 00:00:00 2001 From: Paul English Date: Mon, 7 Aug 2023 09:38:22 +0100 Subject: [PATCH 09/10] chore: patch version update --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index c61b39c..4af7c41 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@bigbite/wp-cypress", - "version": "0.13.0", + "version": "0.13.1", "description": "WordPress end to end testing with Cypress.io", "repository": "https://github.com/bigbite/wp-cypress", "author": { From ffa083e63a5a592f26a9b9181758a895cfbaf4e9 Mon Sep 17 00:00:00 2001 From: Paul English Date: Mon, 7 Aug 2023 09:41:32 +0100 Subject: [PATCH 10/10] style: fixes tabs/new lines that was causing lint error --- lib/cli/commands/reset.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/cli/commands/reset.js b/lib/cli/commands/reset.js index 8fed183..dc11e59 100644 --- a/lib/cli/commands/reset.js +++ b/lib/cli/commands/reset.js @@ -88,7 +88,9 @@ if( file_exists ( ABSPATH . '.userid' ) ) { wpcli( `core ${getWPInstallType(config.multisite)} --url=${ config.url - } --title="WP Cypress" --admin_user=${config.adminUsername} --admin_password=password --admin_email="admin@test.com" --skip-email`, + } --title="WP Cypress" --admin_user=${ + config.adminUsername + } --admin_password=password --admin_email="admin@test.com" --skip-email`, logFile, ), 'Installing WordPress',