Make WordPress Core

Opened 9 years ago

Closed 9 years ago

#31392 closed defect (bug) (invalid)

Undefined function error on mu-plugin during update/upgrade

Reported by: jadpm's profile jadpm Owned by:
Milestone: Priority: normal
Severity: normal Version: 4.2
Component: Upgrade/Install Keywords:
Focuses: Cc:


It seems that there is a weird issue on callbacks added to proper action hooks inside mu-plugins. Somehow, it seems that theme and plugin functions are not available during some actions while performing an update/upgrade.

Steps to reproduce:

Create a dummy function inside your active theme functions.php file or create a generic plugin containing a dummy function definition:

function prefix_mu_init_callback() {

Create a dummy mu-plugin containing a callback hooked into init and calling that dummy function:

add_action( 'init', 'prefix_mu_init_test' );
function prefix_mu_init_test() {

All in all, everything works fine. Now, if you perform an update/upgrade, you will get the following error:

Fatal error:  Call to undefined function prefix_mu_init_callback() in C:\wamp\www\wp_dev\wp-content\mu-plugins\prefix_mu_plugin.php on line 14
PHP Stack trace:
PHP   1. {main}() C:\wamp\www\wp_dev\wp-admin\upgrade.php:0
PHP   2. require() C:\wamp\www\wp_dev\wp-admin\upgrade.php:18
PHP   3. require_once() C:\wamp\www\wp_dev\wp-load.php:37
PHP   4. require_once() C:\wamp\www\wp_dev\wp-config.php:97
PHP   5. do_action() C:\wamp\www\wp_dev\wp-settings.php:353
PHP   6. call_user_func_array() C:\wamp\www\wp_dev\wp-includes\plugin.php:496
PHP   7. prefix_mu_init_test() C:\wamp\www\wp_dev\wp-includes\plugin.php:496

I managed to reproduce this issue on two different scenarios. First, doing a manual upgrade from 3.X to 4.1.1. Also, you can easily reproduce it by using the WordPress Beta Tester plugin, as this happens every time an update is installed.

I am not sure whether this is indeed a bug or not, since mu-plugins should not depend on things defined on the active theme or a third-party plugin, so I'm using function_exists() to workaround it. But it feels like things hooked on init should be ready to use on real init, that is, after plugins_loaded and after_setup_theme.

Possible related: #28668

Change History (2)

#1 @agm65
9 years ago

Related ?

"Use wp_loaded instead. That runs after init and after ms_site_check() was called. This way you avoid to run your plugin on an invalid sub site in a multi-site installation. Everything else is the same."

#2 @jeremyfelt
9 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to invalid
  • Status changed from new to closed

Hi jadpm, thanks for opening a ticket.

Standard plugins are not available during the upgrade process. When upgrade.php is called, the WP_INSTALLING constant is defined and wp_get_active_and_valid_plugins() will provide an empty array of plugins so that the upgrade process can do its thing.

The best way around this is to add a check of your own in the mu-plugin for defined( 'WP_INSTALLING' ).

Note: See TracTickets for help on using tickets.