Skip to content

Instantly share code, notes, and snippets.

@ipokkel
Created May 14, 2025 07:45
Show Gist options
  • Save ipokkel/f0e4e8ee07cdd868b609d2b22982e4a4 to your computer and use it in GitHub Desktop.
Save ipokkel/f0e4e8ee07cdd868b609d2b22982e4a4 to your computer and use it in GitHub Desktop.
<?php
/**
* Flush WordPress user meta cache.
*
* Add the flushmetacache parameter to the admin URL to flush the user meta cache.
* e.g., http://your-site.com/wp-admin/admin.php?flushmetacache=1
*
* You can add this recipe to your site by creating a custom plugin
* or using the Code Snippets plugin available for free in the WordPress repository.
* Read this companion article for step-by-step directions on either method.
* https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*/
function my_clear_user_meta_cache() {
// Only process if the user has administrator privileges, is in the admin area, and the flushmetacache parameter is set.
if ( ! is_admin() || ! current_user_can( 'manage_options' ) || ! isset( $_REQUEST['flushmetacache'] ) || empty( $_REQUEST['flushmetacache'] ) ) {
return;
}
// Flush the user meta cache.
wp_cache_flush();
}
add_action( 'admin_init', 'my_clear_user_meta_cache' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment