Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Output admin notice if persistent object caching is not present #1050

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions includes/utils/class-amp-validation-utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ public static function init() {
add_filter( 'bulk_actions-edit-' . self::POST_TYPE_SLUG, array( __CLASS__, 'add_bulk_action' ), 10, 2 );
add_filter( 'handle_bulk_actions-edit-' . self::POST_TYPE_SLUG, array( __CLASS__, 'handle_bulk_action' ), 10, 3 );
add_action( 'admin_notices', array( __CLASS__, 'remaining_error_notice' ) );
add_action( 'admin_notices', array( __CLASS__, 'persistent_object_caching_notice' ) );
add_action( 'post_action_' . self::RECHECK_ACTION, array( __CLASS__, 'handle_inline_recheck' ) );
add_action( 'admin_menu', array( __CLASS__, 'remove_publish_meta_box' ) );
add_action( 'admin_menu', array( __CLASS__, 'add_admin_menu_validation_status_count' ) );
Expand Down Expand Up @@ -1791,4 +1792,21 @@ public static function get_recheck_link( $post, $redirect_url, $recheck_url = nu
);
}

/**
* Outputs an admin notice if persistent object cache is not present.
*
* @return void
*/
public static function persistent_object_caching_notice() {
if ( ! wp_using_ext_object_cache() && 'toplevel_page_amp-options' === get_current_screen()->id ) {
printf(
'<div class="notice notice-warning"><p>%s <a href="%s">%s</a></p></div>',
esc_html__( 'The AMP plugin performs at its best when persistent object cache is enabled.', 'amp' ),
esc_url( 'https://codex.wordpress.org/Class_Reference/WP_Object_Cache#Persistent_Caching' ),
esc_html__( 'More details', 'amp' )
);
}
}

}

35 changes: 35 additions & 0 deletions tests/test-class-amp-validation-utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ public function setUp() {
*/
public function tearDown() {
$GLOBALS['wp_registered_widgets'] = $this->original_wp_registered_widgets; // WPCS: override ok.
unset( $GLOBALS['current_screen'] );
parent::tearDown();
}

Expand All @@ -114,6 +115,7 @@ public function test_init() {
$this->assertEquals( 10, has_filter( 'bulk_actions-edit-' . AMP_Validation_Utils::POST_TYPE_SLUG, self::TESTED_CLASS . '::add_bulk_action' ) );
$this->assertEquals( 10, has_filter( 'handle_bulk_actions-edit-' . AMP_Validation_Utils::POST_TYPE_SLUG, self::TESTED_CLASS . '::handle_bulk_action' ) );
$this->assertEquals( 10, has_action( 'admin_notices', self::TESTED_CLASS . '::remaining_error_notice' ) );
$this->assertEquals( 10, has_action( 'admin_notices', self::TESTED_CLASS . '::persistent_object_caching_notice' ) );
$this->assertEquals( 10, has_action( 'admin_menu', self::TESTED_CLASS . '::remove_publish_meta_box' ) );
$this->assertEquals( 10, has_action( 'add_meta_boxes', self::TESTED_CLASS . '::add_meta_boxes' ) );
}
Expand Down Expand Up @@ -1359,4 +1361,37 @@ public function get_mock_errors() {
);
}

/**
* Test for persistent_object_caching_notice()
*
* @covers AMP_Validation_Utils::persistent_object_caching_notice()
*/
public function test_persistent_object_caching_notice() {
set_current_screen( 'toplevel_page_amp-options' );
$text = 'The AMP plugin performs at its best when persistent object cache is enabled.';

wp_using_ext_object_cache( null );
ob_start();
AMP_Validation_Utils::persistent_object_caching_notice();
$this->assertContains( $text, ob_get_clean() );

wp_using_ext_object_cache( true );
ob_start();
AMP_Validation_Utils::persistent_object_caching_notice();
$this->assertNotContains( $text, ob_get_clean() );

set_current_screen( 'edit.php' );

wp_using_ext_object_cache( null );
ob_start();
AMP_Validation_Utils::persistent_object_caching_notice();
$this->assertNotContains( $text, ob_get_clean() );

wp_using_ext_object_cache( true );
ob_start();
AMP_Validation_Utils::persistent_object_caching_notice();
$this->assertNotContains( $text, ob_get_clean() );

}

}