Skip to content

Commit

Permalink
Output admin notice if persistent object caching is not present
Browse files Browse the repository at this point in the history
  • Loading branch information
oscarssanchez committed Mar 30, 2018
1 parent 4f2f8dd commit 59e15fb
Showing 2 changed files with 59 additions and 0 deletions.
20 changes: 20 additions & 0 deletions includes/utils/class-amp-validation-utils.php
Original file line number Diff line number Diff line change
@@ -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_caching_object_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' ) );
@@ -1791,4 +1792,23 @@ 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_caching_object_notice() {
$screen = get_current_screen();
if ( 'toplevel_page_amp-options' === $screen->id ) {
if ( ! wp_using_ext_object_cache() ) {
?>
<div class="notice notice-warning">
<p><?php esc_html_e( 'The AMP plugin performs at its best when persistent object cache is enabled.', 'amp' ); ?></p>
<p><a href="<?php echo esc_url( 'https://codex.wordpress.org/Class_Reference/WP_Object_Cache#Persistent_Caching' ); ?>">More details</a></p>
</div>
<?php
}
}
}

}
39 changes: 39 additions & 0 deletions tests/test-class-amp-validation-utils.php
Original file line number Diff line number Diff line change
@@ -114,6 +114,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_caching_object_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' ) );
}
@@ -1359,4 +1360,42 @@ public function get_mock_errors() {
);
}

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

$using = null;
wp_using_ext_object_cache( $using );
ob_start();
AMP_Validation_Utils::persistent_caching_object_notice();
$this->assertContains( $needle, ob_get_clean() );

$using = true;
wp_using_ext_object_cache( $using );
ob_start();
AMP_Validation_Utils::persistent_caching_object_notice();
$this->assertNotContains( $needle, ob_get_clean() );

set_current_screen( 'edit.php' );

$using = null;
wp_using_ext_object_cache( $using );
ob_start();
AMP_Validation_Utils::persistent_caching_object_notice();
$this->assertNotContains( $needle, ob_get_clean() );

$using = true;
wp_using_ext_object_cache( $using );
ob_start();
AMP_Validation_Utils::persistent_caching_object_notice();
$this->assertNotContains( $needle, ob_get_clean() );

unset( $GLOBALS['current_screen'] );
}

}

0 comments on commit 59e15fb

Please sign in to comment.