Opened 19 months ago
Last modified 16 months ago
#59020 new defect (bug)
Critical error during database update and patterns directory
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | Awaiting Review | Priority: | normal |
Severity: | critical | Version: | 6.3 |
Component: | General | Keywords: | |
Focuses: | Cc: |
Description
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):
<?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)
#2
@
19 months ago
Thank you very much for your fast reply!
- If I update through the button in the backend:
- in the browser I see the critical error page: http://example.com/wp-admin/upgrade.php?_wp_http_referer=%2Fcore%2Fwp-admin%2Fabout.php%3Fupdated
- and on debug.log, I get the following message:
[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
- If I update through wp cli:
- the wp core update shows no error on the console, but in the browser I can see again the critical error page: http://example.com/wp-admin/upgrade.php?_wp_http_referer=%2Fcore%2Fwp-admin%2Fabout.php%3Fupdated
- and when i run wp core update-db I can see the same error as in the debug.log.
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
@
18 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.
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?