WP-Mix

A fresh mix of code snippets and tutorials

Fix “Function Not Found” Error in WordPress Must-Use Plugins

Posting these notes in case they are useful to anyone looking for related information. This may or may not be related to must-use plugins. I am still testing on vanilla WordPress installation. Update: after some further experimenting, it looks like the issue was resolved by uploading a fresh set of WordPress core files. So try that first, and if the issue persists then maybe the following notes will help..

Possible Bug

I uploaded a simple mu (must-use) plugin to WordPress and got a weird fatal error happening in the Admin Area, apparently related to heartbeat Ajax requests:

PHP Fatal error: Uncaught TypeError: call_user_func_array(): 
Argument #1 ($callback) must be a valid callback, 
function "wp_refresh_metabox_loader_nonces" 
not found or invalid function name in 
/wp-includes/class-wp-hook.php:310

Stack trace:

#0 /wp-includes/plugin.php(205): WP_Hook->apply_filters()
#1 /wp-admin/includes/ajax-actions.php(3446): apply_filters()
#2 /wp-includes/class-wp-hook.php(308): wp_ajax_heartbeat()
#3 /wp-includes/class-wp-hook.php(332): WP_Hook->apply_filters()
#4 /wp-includes/plugin.php(517): WP_Hook->do_action()
#5 /wp-admin/admin-ajax.php(188): do_action()
#6 {main}

thrown in /wp-includes/class-wp-hook.php on line 310

After some troubleshooting and digging around in WordPress core, found the related functions:

wp_refresh_nonces
wp_refresh_metabox_loader_nonces

Apparently these functions are expecting a $response, even when the mu-plugin is not doing anything Ajax-related, or anything at all for that matter. In any case, here is the workaround solution for anyone dealing with the same issue:

if (!function_exists('wp_refresh_metabox_loader_nonces')) {
	
	function wp_refresh_metabox_loader_nonces($response = array(), $data = '') { return $response; }
	
}

Add that to the top of your mu-plugin and done.

Fixing similar “not found or invalid function name” errors:

The same general technique theoretically may be applied to workaround any “not found or invalid function name” errors when working with must-use plugins. Get the name of the missing function and search WordPress core. Find out what’s expected return/output wise. then use !function_exists() and define the function (as in the above example).

Reminder: these are just notes that I was working thru while trying to fix the “Function Not Found” error related to WP must-use (mu) plugins. The actual solution (in my case) was to just re-upload the core WordPress files; apparently something was missing, and thus causing the error.

Learn more

Digging Into WordPressWordPress Themes In DepthWizard’s SQL Recipes for WordPress