Created
May 14, 2025 07:45
-
-
Save ipokkel/f0e4e8ee07cdd868b609d2b22982e4a4 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 | |
/** | |
* 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