Skip to content
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
22 changes: 22 additions & 0 deletions features/utils-wp.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Feature: Utilities that depend on WordPress code

Scenario: Clear WP cache
Given a WP install
And a test.php file:
"""
<?php
WP_CLI::add_hook( 'after_wp_load', function () {
global $wp_object_cache;
echo empty( $wp_object_cache->cache ) . ',' . isset( $wp_object_cache->group_ops ) . ',' . isset( $wp_object_cache->stats ) . ',' . isset( $wp_object_cache->memcache_debug ) . "\n";
WP_CLI\Utils\wp_clear_object_cache();
echo empty( $wp_object_cache->cache ) . ',' . isset( $wp_object_cache->group_ops ) . ',' . isset( $wp_object_cache->stats ) . ',' . isset( $wp_object_cache->memcache_debug ) . "\n";
} );
"""

When I run `wp post create --post_title="Foo Bar" --porcelain`
And I run `wp --require=test.php eval ''`
Then STDOUT should be:
"""
,,,
1,,,
"""
21 changes: 14 additions & 7 deletions php/utils-wp.php
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ function wp_get_cache_type() {
*
* @access public
* @category System
* @deprecated 1.5.0
*/
function wp_clear_object_cache() {
global $wpdb, $wp_object_cache;
Expand All @@ -287,13 +288,19 @@ function wp_clear_object_cache() {
return;
}

$wp_object_cache->group_ops = array();
$wp_object_cache->stats = array();
$wp_object_cache->memcache_debug = array();
$wp_object_cache->cache = array();

if ( is_callable( $wp_object_cache, '__remoteset' ) ) {
$wp_object_cache->__remoteset(); // important
// The following are Memcached (Redux) plugin specific (see https://core.trac.wordpress.org/ticket/31463).
if ( isset( $wp_object_cache->group_ops ) ) {
$wp_object_cache->group_ops = array();
}
if ( isset( $wp_object_cache->stats ) ) {
$wp_object_cache->stats = array();
}
if ( isset( $wp_object_cache->memcache_debug ) ) {
$wp_object_cache->memcache_debug = array();
}
// Used by `WP_Object_Cache` also.
if ( isset( $wp_object_cache->cache ) ) {
$wp_object_cache->cache = array();
}
}

Expand Down