WordPress.org

Make WordPress Core

Opened 5 months ago

#48610 new defect (bug)

Fatal Error during upgrade (upgrade.php) caused by theme unavailability

Reported by: thomasfw Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 5.3
Component: Upgrade/Install Keywords:
Focuses: Cc:

Description

Some Context

We have a number of mu-plugins that handle core functionality in our client's website. Within one of these mu-plugins, we're using a class that's defined in the active theme in order to load a template part. I'm aware that this wouldn't be advised for either a distributed plugin or theme, but our project utilises Bedrock, Composer etc. to lock everything down, so the active theme and (mu-)plugins cannot be changed.

The mu-plugin in question registers a shortcode with add_shortcode(), and we're using the theme's helper class in the callback to output some pagination within the shortcode.

The Issue

After upgrading WP, the dashboard redirect to "mywebsite.test/wp-admin/upgrade.php" results in a blank screen, and i'm not able to upgrade the database or view the dashboard.

Because upgrade.php is seemingly not loading the theme (whilst all mu-plugins are loaded), a fatal error occurs because the class dependency inside our mu-plugin can't be found.

In an attempt to resolve this I tried registering the shortcode only after the theme was initialised, by hooking on the after_setup_theme action, instead of on init.

The after_setup_theme action as described in the WP docs - "This is the first action hook available to themes, triggered immediately after the active theme's functions.php file is loaded.".

So one would assume that this action would only be fired when the theme was available, making it a suitable candidate, but the fatal error still occurs. Why does this action still fire when it appears that the theme is not loaded during the upgrade process?

What does fix this for me is using an even later hook (template_redirect) to register the shortcode. In this case, the upgrade.php page loads without a fatal error and I am able to upgrade the site, but i'm unsure of any potential side effects of registering a shortcode so late on, and i'm hoping there's a potential fix available in the core to prevent this issue reoccurring.

Change History (0)

Note: See TracTickets for help on using tickets.