-
Notifications
You must be signed in to change notification settings - Fork 4.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Block Theme Previews does not work if we call the get_template
or get_stylesheet
functions early
#53284
Comments
I had an idea for how to solve this here: WordPress/wordpress-develop#4959 |
For example, it breaks if a user has the CoBlocks plugin activated. Update: This issue happens on the site with a plugin like Elementor, and WooCommerce. |
Thanks for trying this out, @scruffian!
This alternative seems more fitting to me, as I feel that performing capability checks before defining pluggable functions itself might not be the optimal approach. What are your thoughts? |
… theme live preview functionality.
@okmttdhr @scruffian, this has been shipped and backported to WP 6.3.2, should we close this issue? |
Closing, as this issue has been solved at https://core.trac.wordpress.org/ticket/59000! |
Description
Block Theme Previews does not work if we call the
get_template
orget_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;
stylesheet
andtemplate
. https://github.com/WordPress/wordpress-develop/blob/4417367/src/wp-includes/theme-previews.php#L80-L81current_user_can( 'switch_themes' )
, which useswp_get_current_user
inside of it. https://github.com/WordPress/wordpress-develop/blob/4417367/src/wp-includes/theme-previews.php#L17-L19wp_get_current_user
is initialized afterpluggable.php
is called. https://github.com/WordPress/wordpress-develop/blob/1d7554d/src/wp-settings.php#L482-L484A possible solution would be one of the following;
theme-previews.php
after the pluggable functionstheme-previews.php
Step-by-step reproduction instructions
wp-content/plugins/sample-plugin/sample-plugin.php
on your site./wp-admin/themes.php
and clickLive Preview
button on your installed Block theme.Uncaught Error: Call to undefined function wp_get_current_user()
Screenshots, screen recording, code snippet
Environment info
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
The text was updated successfully, but these errors were encountered: