Make WordPress Core

Opened 8 months ago

Last modified 6 months ago

#59020 new defect (bug)

Critical error during database update and patterns directory

Reported by: margaritaperc's profile margaritaperc Owned by:
Milestone: Awaiting Review Priority: normal
Severity: critical Version: 6.3
Component: General Keywords:
Focuses: Cc:


Hi there,

The following critical error is triggered when WordPress updates the database, for example now with 6.3.

My theme is using the patterns directory to define patterns. When i echo a constant - that is defined in the theme's functions.php - to one of the pattern files, I get a critical error (undefined constant) during the update process and cannot be complete it. The reason is probably, that WordPress loads the patterns directory during the database process, but not the functions.php.

This is an example of the pattern file (path-to-theme/patterns/pattern-example.php):

 * Title: Pattern Example
 * Slug: theme/pattern-example

<!-- wp:paragraph -->
<p><?php echo esc_html( THEME_CONSTANT ); ?></p>
<!-- /wp:paragraph -->

If I define the constant earlier, for example in the mu-plugins, the problem is solved.

Let me know, if I need to provide more details

Change History (4)

#1 @NekoJonez
8 months ago

Where exactly do you get this error? As soon as the website loads?
Could you show us the full error?

You are talking about multisite... Do you experience this issue also on a non-multisite website?

#2 @margaritaperc
8 months ago

Thank you very much for your fast reply!

  1. If I update through the button in the backend:
[09-Aug-2023 15:00:46 UTC] PHP Fatal error:  Uncaught Error: Undefined constant "THEME_CONSTANT" in /path-to-theme/wp-content/themes/theme-name/pattern-example.php:200
Stack trace:
#0 /path-to-theme/core/wp-includes/block-patterns.php(480): include()
#1 /path-to-theme/core/wp-includes/class-wp-hook.php(310): _register_theme_block_patterns('')
#2 /path-to-theme/core/wp-includes/class-wp-hook.php(334): WP_Hook->apply_filters(NULL, Array)
#3 /path-to-theme/core/wp-includes/plugin.php(517): WP_Hook->do_action(Array)
#4 /path-to-theme/core/wp-settings.php(632): do_action('init')
#5 /path-to-theme/wp-config.php(112): require_once('/Users/...')
#6 /path-to-theme/core/wp-load.php(55): require_once('/Users/...')
#7 /path-to-theme/core/wp-admin/upgrade.php(18): require('/Users/...')
#8 /Users/a/.composer/vendor/laravel/valet/server.php(110): require('/Users/...')
#9 {main} thrown in /path-to-theme/wp-content/themes/theme-name/patterns/pattern-example.php on line 200
  1. If I update through wp cli:

I didn't write that it concerned only multisite. But I've just tested it as well and strangely enough on multisite the update process could be completed, although the wp core update-db still generates the same error on the console.

Let me know, if you need any more infos.

#3 @tahcsudieh
8 months ago

We had the same errors here, when a database update startet.

These errors happenend a few time before when set up a new local instance.

Only solution for now ist commenting out all php code in the patterns except the meta of the patterns. After that, the database update can be accomplished and you can commenting in the php code again.

This ticket was mentioned in Slack in #core by joemcgill. View the logs.

6 months ago

Note: See TracTickets for help on using tickets.