Last active
August 29, 2015 14:04
-
-
Save DrewAPicture/37dc1ccfec3ad1a3a3d8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Retrieve a variable cache key via RegEx. | |
* | |
* A good use for this would be where an incrementer is part of the key and you can't | |
* necessarily predict what it is, though you can predict the format it will take. | |
*/ | |
function get_variable_cache_key() { | |
/** | |
* @global WP_Object_Cache $wp_object_cache | |
*/ | |
global $wp_object_cache; | |
if ( ! is_object( $wp_object_cache ) ) { | |
return; | |
} | |
$matches = $cleaned_matches = array(); | |
$group = 'whatever'; | |
if ( ! empty( $wp_object_cache->group_ops[ $group ] ) ) { | |
$matches = preg_grep( 'pattern-here', $wp_object_cache->group_ops[ $group ] ); | |
} | |
if ( ! empty( $matches ) ) { | |
foreach ( $matches as $match ) { | |
$cleaned_matches[] = str_replace( 'get ', '', $match ); | |
} | |
} | |
// Do stuff. | |
} | |
add_action( 'wp_after_admin_bar_render', 'get_variable_cache_key', 100 ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment