fullsiteediting icon indicating copy to clipboard operation
fullsiteediting copied to clipboard

Question: Theme patterns with custom PHP functions & WP-CLI

Open thomasplevy opened this issue 3 years ago • 1 comments

Hey @carolinan I have a question and I can't figure out if this is a bug in core, or in WP-CLI, or both or neither...

My team and I have been building a FSE theme and we've been reading and referring to your fullsiteediting.com website (and the related examples here in GitHub) and we've stumbled into an issue I can recreate with at least one of your starter themes:

  1. Using the advanced-60 theme
  2. Install and activate it
  3. From the terminal, executed wp core is-installed

Resulting error:

PHP Fatal error:  Uncaught Error: Call to undefined function full_site_editing_privacy() in /XXX/wp-content/themes/advanced-60/patterns/footer-links.php:19
Stack trace:
#0 /XXX/wp-includes/block-patterns.php(322): include()
#1 /XXX/wp-includes/class-wp-hook.php(307): _register_theme_block_patterns()
#2 /XXX/wp-includes/class-wp-hook.php(331): WP_Hook->apply_filters()
#3 /XXX/wp-includes/plugin.php(476): WP_Hook->do_action()
#4 /XXX/wp-settings.php(598): do_action()
#5 phar:///usr/local/bin/wp/vendor/wp-cli/wp-cli/php/WP_CLI/Runner.php(1317): require('...')
#6 phar:///usr/local/bin/wp/vendor/wp-cli/wp-cli/php/WP_CLI/Runner.php(1235): WP_CLI\Runner->load_wordpress()
#7 phar:///usr/local/bin/wp/vendor/wp-cli/wp-cli/php/WP_CLI/Bootstrap/LaunchRunner.php(28): WP_CLI\Runner->start()
#8 phar:///usr/local/bin/wp/vendor/wp-cli/wp-cli/php/bootstrap.php(78): WP_CLI\Bootstrap\LaunchRunner->process()
#9 phar:///usr/local/bin/wp/vendor/wp-cli/wp-cli/php/wp-cli.php(27): WP_CLI\bootstrap()
#10 phar:///usr/local/bin/wp/php/boot-phar.php(11): include('...')
#11 /usr/local/bin/wp(4): include('...')
#12 {main}
  thrown in /XXX/wp-content/themes/advanced-60/patterns/footer-links.php on line 19

I've first been trying to review pattern-related code and guides and I don't see anything that explicitly prohibits or says theme devs should not be using custom PHP functions in the pattern . It seems like the whole point of the pattern being in PHP is to allow using custom functions.

It seems WP Core functions are allowed.

I think it comes down to, really, that the theme isn't "loaded" for some of these wp-cli commands but the pattern is still evaluated due to core bootstrapping? I'm not sure... I figured I'd ask you what you thought about this first because you seem to be know all things FSE pretty well.

Thanks!

thomasplevy avatar Oct 13 '22 16:10 thomasplevy

Hi There was a similar report here https://github.com/carolinan/fullsiteediting/issues/31 But I haven't been able to figure out why it is happening, or how we can reproduce it consistently enough for us to open an issue on the Gutenberg GitHub repository.

I think you may be right that is about when the patterns are initialized. Patterns are registered on init: https://github.com/WordPress/wordpress-develop/blob/trunk/src/wp-includes/block-patterns.php#L198

carolinan avatar Oct 14 '22 02:10 carolinan