Repository navigation
Admin context crashes because of admin.php file formatting #5844
Copy link
Copy link
Closed
Labels
Milestone
Description
Bug Report
- Yes, I reviewed the contribution guidelines.
- Yes, more specifically, I reviewed the guidelines on how to write clear bug reports.
Describe the current, buggy behavior
Using the --context=admin flag causes WP CLI to error out. It appears to be happening with PHP v8.2 and not PHP v8.0. The error message is:
Warning: require_once(phar://*redacted*/wp/vendor/wp-cli/wp-cli/php/WP_CLI/wp-load.php): Failed to open stream: phar error: "vendor/wp-cli/wp-cli/php/WP_CLI/wp-load.php" is not a file in phar "*redacted*/wp" in phar://*redacted*/wp/vendor/wp-cli/wp-cli/php/WP_CLI/Context/Admin.php(126) : eval()'d code on line 33
Fatal error: Uncaught Error: Failed opening required 'phar://*redacted*/wp/vendor/wp-cli/wp-cli/php/WP_CLI/wp-load.php' (include_path='.:') in phar://*redacted*/wp/vendor/wp-cli/wp-cli/php/WP_CLI/Context/Admin.php(126) : eval()'d code:33
Stack trace:
#0 phar://*redacted*/wp/vendor/wp-cli/wp-cli/php/WP_CLI/Context/Admin.php(126): eval()
#1 phar://*redacted*/wp/vendor/wp-cli/wp-cli/php/WP_CLI/Context/Admin.php(45): WP_CLI\Context\Admin->load_admin_environment()
#2 /var/http/www/public/wp-includes/class-wp-hook.php(305): WP_CLI\Context\Admin->WP_CLI\Context\{closure}()
#3 /var/http/www/public/wp-includes/class-wp-hook.php(331): WP_Hook->apply_filters()
#4 /var/http/www/public/wp-includes/plugin.php(476): WP_Hook->do_action()
#5 /var/http/www/public/wp-settings.php(527): do_action()
#6 phar://*redacted*/wp/vendor/wp-cli/wp-cli/php/WP_CLI/Runner.php(1349): require('...')
#7 phar://*redacted*/wp/vendor/wp-cli/wp-cli/php/WP_CLI/Runner.php(1267): WP_CLI\Runner->load_wordpress()
#8 phar://*redacted*/wp/vendor/wp-cli/wp-cli/php/WP_CLI/Bootstrap/LaunchRunner.php(28): WP_CLI\Runner->start()
#9 phar://*redacted*/wp/vendor/wp-cli/wp-cli/php/bootstrap.php(83): WP_CLI\Bootstrap\LaunchRunner->process()
#10 phar://*redacted*/wp/vendor/wp-cli/wp-cli/php/wp-cli.php(32): WP_CLI\bootstrap()
#11 phar://*redacted*/wp/php/boot-phar.php(20): include('...')
#12 *redacted*/wp(4): include('...')
#13 {main}
thrown in phar://*redacted*/wp/vendor/wp-cli/wp-cli/php/WP_CLI/Context/Admin.php(126) : eval()'d code on line 33
Error: There has been a critical error on this website. Please check your site admin email inbox for instructions.Learn more about troubleshooting WordPress. There has been a critical error on this website. Please check your site admin email inbox for instructions.Describe how other contributors can replicate this bug
- Run
wp --context=admin option get admin_email
Describe what you expect as the correct outcome
Commands run when using the flag should complete successfully.
Let us know what environment you are running this on
OS: Linux 5.15.0-1034-gke #39-Ubuntu SMP Wed May 24 02:42:28 UTC 2023 x86_64
Shell: /bin/bash
PHP binary: /usr/bin/php8.2
PHP version: 8.2.8
php.ini used: /etc/php/8.2/cli/php.ini
MySQL binary: /usr/bin/mysql
MySQL version: mysql Ver 8.0.34-0ubuntu0.22.04.1 for Linux on x86_64 ((Ubuntu))
SQL modes: STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION
WP-CLI root dir: phar://wp-cli.phar/vendor/wp-cli/wp-cli
WP-CLI vendor dir: phar://wp-cli.phar/vendor
WP_CLI phar path: *redacted*
WP-CLI packages dir:
WP-CLI cache dir: /home/*redacted*/.wp-cli/cache
WP-CLI global config: /home/*redacted*/.wp-cli/config.yml
WP-CLI project config:
WP-CLI version: 2.8.1
Reactions are currently unavailable
Activity
willrowe commentedon Oct 24, 2023
I did some further testing and if I change the regex from
wp-cli/php/WP_CLI/Context/Admin.php
Line 117 in 4a908aa
It seems like the issue may be due to the line endings and not the PHP version. I was testing on PHP v8.0 with a project that uses
\nin which it worked, but the PHP v8.2 project uses\r\n.danielbachhuber commentedon Oct 24, 2023
Darn line endings! Thanks for the report 😊
Feel free to submit a pull request, if you'd like. Here is some guidance on our pull request best practices.
willrowe commentedon Oct 24, 2023
I'm guessing that adding
\s*would be the correct fix? Since it would match\rand still allow$to match the end of the line? Unless there's a better way to have$match\r\n.danielbachhuber commentedon Oct 24, 2023
I think it will be easier to grok if you can get a test case going in a pull request.
[-]Admin context crashing[/-][+]Admin context crashes because of admin.php file formatting[/+]sejas commentedon Nov 10, 2023
I reproduced this issue on version
2.7.1, but it seems solved for wp-cli2.9.0.Testing instructions:
wp --context=admin option get admin_emailusing the version2.7.12.9.0by runningwp cli updatewp --context=admin option get admin_emailAdmin Context: Fix PHP fatals when admin.php has CRLF line endings