create-block-theme icon indicating copy to clipboard operation
create-block-theme copied to clipboard

PHP Namespaces in functions.php can lead to fatal error

Open Retrofitterdk opened this issue 1 year ago • 1 comments

I’m not sure whether this should actually be characterised as a bug in create-block-theme, but cloning a theme that uses a PHP Namespace in functions.php can lead to fatal error.

If you want to clone eg. Ollie theme, which uses

namespace Ollie;

in the functions.php file.

And you chose to give the new, cloned theme a name with a space like "My Theme", then the namespace in functions.php in the cloned theme will be set to

namespace My Theme;

This will immediately cause a fatal php error and make the site inaccessible and you would need to switch theme by making a change in the database.

Thanks a lot for all the hard work with create-block-theme - it really brings a huge amount of value to the community.

Retrofitterdk avatar Oct 01 '24 07:10 Retrofitterdk

This will immediately cause a fatal php error and make the site inaccessible and you would need to switch theme by making a change in the database.

Obviously removing spaces from the one line of code in functions.php will also fix the problem.

Retrofitterdk avatar Oct 01 '24 11:10 Retrofitterdk

Thanks for the report. I have created https://github.com/WordPress/create-block-theme/issues/777 to discuss this more extensively, so let's close this issue.

t-hamano avatar May 18 '25 05:05 t-hamano