Skip to content

Commit

Permalink
Remove the user meta as a condition for displaying this message
Browse files Browse the repository at this point in the history
As Weston mentioned,
it's not necessary to hide this after the first time it shows
  • Loading branch information
kienstra committed Sep 18, 2018
1 parent 05092d7 commit 3a75250
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 25 deletions.
9 changes: 0 additions & 9 deletions includes/options/class-amp-options-menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -585,13 +585,6 @@ public function render_screen() {
*/
public function possibly_replace_settings_saved_notice() {
global $wp_settings_errors;
$meta_key = 'amp_view_your_site_notice';
$user_id = get_current_user_id();

// Exit if this setting isn't present, or if this notice has already displayed.
if ( ! get_settings_errors( 'general' ) || get_user_meta( $user_id, $meta_key, true ) ) {
return;
}

foreach ( $wp_settings_errors as $key => $setting ) {
if ( 'general' === $setting['setting'] && 'settings_updated' === $setting['code'] ) {
Expand All @@ -609,8 +602,6 @@ public function possibly_replace_settings_saved_notice() {

if ( isset( $message ) ) {
$wp_settings_errors[ $key ]['message'] = $message; // WPCS: Global override OK.
// Ensure that this notice does not display again.
update_user_meta( get_current_user_id(), $meta_key, true );
}

break;
Expand Down
17 changes: 1 addition & 16 deletions tests/test-class-amp-options-menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,6 @@ public function test_render_screen_for_admin_user() {
*/
public function test_possibly_replace_settings_saved_notice() {
$GLOBALS['wp_settings_errors'] = array(); // WPCS: Global override OK.
$meta_key = 'amp_view_your_site_notice';
$user_id = $this->factory()->user->create();
wp_set_current_user( $user_id );

/**
* There should now only be one error in $wp_settings_errors, which is taken from privacy.php.
Expand All @@ -121,27 +118,15 @@ public function test_possibly_replace_settings_saved_notice() {
$this->instance->possibly_replace_settings_saved_notice();
$this->assertEquals( $inital_wp_settings_errors, get_settings_errors() );

/*
* The 'Settings saved' error is now present, but 'View your site as AMP...' has already shown
* as the meta value is true.
* So this should not change the message.
*/
// The 'Settings saved' error is now present, so this should change its message.
add_settings_error( 'general', 'settings_updated', 'Settings saved.', 'updated' );
update_user_meta( $user_id, $meta_key, true );
$inital_wp_settings_errors = get_settings_errors();
$this->instance->possibly_replace_settings_saved_notice();
$this->assertEquals( $inital_wp_settings_errors, get_settings_errors() );

// Now that the the meta value indicates that this notice hasn't shown yet, this should change the message.
update_user_meta( $user_id, $meta_key, false );
$template_mode_messages = array(
'native' => 'Native Mode activated! View your site as AMP now or Review Errors',
'paired' => 'Paired Mode activated! View your site as AMP now or Review Errors',
'classic' => 'Classic Mode activated! View your site as AMP now. We recommend upgrading to Native or Paired mode.',
);
foreach ( $template_mode_messages as $mode => $message ) {
$this->assert_template_mode_message( $mode, $message );
update_user_meta( $user_id, $meta_key, false );
}
}

Expand Down

0 comments on commit 3a75250

Please sign in to comment.