-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Closed
Automattic/wp-calypso
#81337Labels
[Type] BugAn existing feature does not function as intendedAn existing feature does not function as intended
Description
Description
Block Theme Previews does not work if we call the get_template or get_stylesheet functions before the pluggable functions are not ready. So, if a 3rd party plugin (e.g. CoBlocks, Elementor, Classic Editor, and WooCommerce) needs to access the template or stylesheet before the pluggable functions are ready, then the site with such a plugin will break (see the reproduction instruction below).
The reason this error happens is;
- Block Theme Previews adds hooks to
stylesheetandtemplate. https://github.com/WordPress/wordpress-develop/blob/4417367/src/wp-includes/theme-previews.php#L80-L81 - It checks
current_user_can( 'switch_themes' ), which useswp_get_current_userinside of it. https://github.com/WordPress/wordpress-develop/blob/4417367/src/wp-includes/theme-previews.php#L17-L19 wp_get_current_useris initialized afterpluggable.phpis called. https://github.com/WordPress/wordpress-develop/blob/1d7554d/src/wp-settings.php#L482-L484
A possible solution would be one of the following;
- Load the pluggable functions early
- Load
theme-previews.phpafter the pluggable functions - Load the pluggable functions on demand in
theme-previews.php - Tell developers for the 3rd party plugins not to access the template or stylesheet directly when loading plugins (a developer guide should be covered, maybe)
- Something else
Step-by-step reproduction instructions
- Add a file in
wp-content/plugins/sample-plugin/sample-plugin.phpon your site.
<?php
/*
Plugin Name: Sample plugin
*/
$wp_theme = wp_get_theme();
$wp_theme->get_stylesheet();- Go to
/wp-admin/themes.phpand clickLive Previewbutton on your installed Block theme. - See the error:
Uncaught Error: Call to undefined function wp_get_current_user()
Screenshots, screen recording, code snippet
Environment info
- WordPress: 6.3-RC3-56344
- Gutenberg: 16.3.0
Please confirm that you have searched existing issues in the repo.
Yes
Please confirm that you have tested with all plugins deactivated except Gutenberg.
Yes
autumnfjeld
Metadata
Metadata
Assignees
Labels
[Type] BugAn existing feature does not function as intendedAn existing feature does not function as intended