Skip to content

Commit

Permalink
Merge pull request #126 from bigbite/hotfix/welcome-message-meta-appr…
Browse files Browse the repository at this point in the history
…oach

Adds user meta to admin to prevent the Welcome Message modal appearing in the Gutenberg editor
  • Loading branch information
PaulREnglish authored Aug 8, 2023
2 parents c8f09fe + ffa083e commit 2f113f7
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 2 deletions.
4 changes: 3 additions & 1 deletion lib/cli/commands/reset.js
Original file line number Diff line number Diff line change
Expand Up @@ -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="[email protected]" --skip-email`,
} --title="WP Cypress" --admin_user=${
config.adminUsername
} --admin_password=password --admin_email="[email protected]" --skip-email`,
logFile,
),
'Installing WordPress',
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
1 change: 1 addition & 0 deletions plugin/assets/disable-tooltips.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ jQuery(document).ready(() => {
const nux = select('core/nux');

if (!nux) {
// needed for some earlier versions of WP
if (select('core/edit-post').isFeatureActive('welcomeGuide')) {
dispatch('core/edit-post').toggleFeature('welcomeGuide');
}
Expand Down
10 changes: 10 additions & 0 deletions plugin/src/Fixtures/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -22,6 +25,13 @@ public function defaults(): array {
'description' => $this->faker->realText( 200 ),
'user_registered' => Utils\now(),
'role' => 'administrator',
'meta_input' => [
$user_preferences_meta_key => [
"core/edit-post" => [
"welcomeGuide" => false,
],
],
],
];
}

Expand Down
20 changes: 20 additions & 0 deletions plugin/src/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -89,4 +90,23 @@ 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] );
}

/**
* 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';

if ( !get_user_meta(1, $user_preferences_meta_key) ) {
update_user_meta(1, $user_preferences_meta_key, [
"core/edit-post" => [
"welcomeGuide" => false,
],
]);
}
}
};

0 comments on commit 2f113f7

Please sign in to comment.