Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Display a custom error message when themes/functions.php fatals#5817

Merged
danielbachhuber merged 4 commits into
mainwp-cli/wp-cli:mainfrom
fix/themes-functionswp-cli/wp-cli:fix/themes-functionsCopy head branch name to clipboard
Aug 14, 2023
Merged

Display a custom error message when themes/functions.php fatals#5817
danielbachhuber merged 4 commits into
mainwp-cli/wp-cli:mainfrom
fix/themes-functionswp-cli/wp-cli:fix/themes-functionsCopy head branch name to clipboard

Conversation

@danielbachhuber

@danielbachhuber danielbachhuber commented Jul 24, 2023

Copy link
Copy Markdown
Member

Fixes #5240

Trying to fix this upstream is too much of a rabbit hole. Instead, let's give the user a more helpful pointer:

$ wp --skip-themes option get home
Fatal error: Uncaught Error: Call to undefined function genesis_register_sidebar() in /Users/danielbachhuber/projects/vanilla/wp-content/themes/functions.php:3
Stack trace:
#0 /Users/danielbachhuber/projects/vanilla/wp-settings.php(599): include()
#1 /Users/danielbachhuber/projects/wp-cli-dev/wp-cli/php/WP_CLI/Runner.php(1349): require('/Users/danielba...')
#2 /Users/danielbachhuber/projects/wp-cli-dev/wp-cli/php/WP_CLI/Runner.php(1267): WP_CLI\Runner->load_wordpress()
#3 /Users/danielbachhuber/projects/wp-cli-dev/wp-cli/php/WP_CLI/Bootstrap/LaunchRunner.php(28): WP_CLI\Runner->start()
#4 /Users/danielbachhuber/projects/wp-cli-dev/wp-cli/php/bootstrap.php(83): WP_CLI\Bootstrap\LaunchRunner->process(Object(WP_CLI\Bootstrap\BootstrapState))
#5 /Users/danielbachhuber/projects/wp-cli-dev/wp-cli/php/wp-cli.php(32): WP_CLI\bootstrap()
#6 /Users/danielbachhuber/projects/wp-cli-dev/wp-cli/php/boot-fs.php(17): require_once('/Users/danielba...')
#7 {main}
  thrown in /Users/danielbachhuber/projects/vanilla/wp-content/themes/functions.php on line 3
Error: An unexpected functions.php file in the themes directory may have caused this internal server error.

@swissspidy swissspidy left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have to say it's quite the edge case but alas 🤷‍♂️

Comment thread php/utils-wp.php
if ( ! empty( $error_data['error']['file'] )
&& false !== stripos( $error_data['error']['file'], 'themes/functions.php' ) ) {
$text_message = 'There was an internal server error that may have been caused by an unexpected functions.php file in the themes directory.';
$text_message = 'An unexpected functions.php file in the themes directory may have caused this internal server error.';

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, what about the original error message? Shouldn't that be kept and displayed as well?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@schlessera I don't think the original error message is particularly helpful.

Original output

$ wp --skip-themes option get home
Fatal error: Uncaught Error: Call to undefined function genesis_register_sidebar() in /Users/danielbachhuber/projects/vanilla/wp-content/themes/functions.php:3
Stack trace:
#0 /Users/danielbachhuber/projects/vanilla/wp-settings.php(600): include()
#1 /Users/danielbachhuber/projects/wp-cli-dev/wp-cli/php/WP_CLI/Runner.php(1349): require('/Users/danielba...')
#2 /Users/danielbachhuber/projects/wp-cli-dev/wp-cli/php/WP_CLI/Runner.php(1267): WP_CLI\Runner->load_wordpress()
#3 /Users/danielbachhuber/projects/wp-cli-dev/wp-cli/php/WP_CLI/Bootstrap/LaunchRunner.php(28): WP_CLI\Runner->start()
#4 /Users/danielbachhuber/projects/wp-cli-dev/wp-cli/php/bootstrap.php(83): WP_CLI\Bootstrap\LaunchRunner->process(Object(WP_CLI\Bootstrap\BootstrapState))
#5 /Users/danielbachhuber/projects/wp-cli-dev/wp-cli/php/wp-cli.php(32): WP_CLI\bootstrap()
#6 /Users/danielbachhuber/projects/wp-cli-dev/wp-cli/php/boot-fs.php(17): require_once('/Users/danielba...')
#7 {main}
  thrown in /Users/danielbachhuber/projects/vanilla/wp-content/themes/functions.php on line 3
Error: There has been a critical error on this website.Learn more about troubleshooting WordPress. There has been a critical error on this website.

New output

$  wp --skip-themes option get home
Fatal error: Uncaught Error: Call to undefined function genesis_register_sidebar() in /Users/danielbachhuber/projects/vanilla/wp-content/themes/functions.php:3
Stack trace:
#0 /Users/danielbachhuber/projects/vanilla/wp-settings.php(600): include()
#1 /Users/danielbachhuber/projects/wp-cli-dev/wp-cli/php/WP_CLI/Runner.php(1349): require('/Users/danielba...')
#2 /Users/danielbachhuber/projects/wp-cli-dev/wp-cli/php/WP_CLI/Runner.php(1267): WP_CLI\Runner->load_wordpress()
#3 /Users/danielbachhuber/projects/wp-cli-dev/wp-cli/php/WP_CLI/Bootstrap/LaunchRunner.php(28): WP_CLI\Runner->start()
#4 /Users/danielbachhuber/projects/wp-cli-dev/wp-cli/php/bootstrap.php(83): WP_CLI\Bootstrap\LaunchRunner->process(Object(WP_CLI\Bootstrap\BootstrapState))
#5 /Users/danielbachhuber/projects/wp-cli-dev/wp-cli/php/wp-cli.php(32): WP_CLI\bootstrap()
#6 /Users/danielbachhuber/projects/wp-cli-dev/wp-cli/php/boot-fs.php(17): require_once('/Users/danielba...')
#7 {main}
  thrown in /Users/danielbachhuber/projects/vanilla/wp-content/themes/functions.php on line 3
Error: An unexpected functions.php file in the themes directory may have caused this internal server error.

@danielbachhuber danielbachhuber merged commit a33e0f8 into main Aug 14, 2023
@danielbachhuber danielbachhuber deleted the fix/themes-functions branch August 14, 2023 22:11
@swissspidy

Copy link
Copy Markdown
Member

@danielbachhuber Hmm looks like the automated tests for the Phar build are now failing because of this: https://github.com/wp-cli/automated-tests/actions/runs/5885136682/job/15961097291#step:14:263

@danielbachhuber

Copy link
Copy Markdown
Member Author

@swissspidy I think updating the bundle should fix wp-cli/wp-cli-bundle#566

@swissspidy

Copy link
Copy Markdown
Member

@danielbachhuber doesn't look like it, see this latest run: https://github.com/wp-cli/automated-tests/actions/runs/5903479397/job/16013536710

What am I missing?

@danielbachhuber

Copy link
Copy Markdown
Member Author

What am I missing?

@swissspidy It looks like the tests are running against the nightly Phar build, but it's not being deployed right now wp-cli/wp-cli-bundle#568

@danielbachhuber

Copy link
Copy Markdown
Member Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Top level themes/functions.php file breaks --skip-themes

3 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.