Skip to content

Admin context crashes because of admin.php file formatting #5844

Closed

Description

@willrowe

Bug Report

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

Activity

  1. willrowe commented on Oct 24, 2023

    @willrowe
    Author

    I did some further testing and if I change the regex from

    $admin_php_file = preg_replace( '/^\s*(?:include|require).*[\'"]\/?wp-(?:load|config)\.php[\'"]\s*\)?;$/m', '', $admin_php_file );
    to either of the following, it works:

    /^\s*(?:include|require).*[\'"]\/?wp-(?:load|config)\.php[\'"]\s*\)?;/m
    /^\s*(?:include|require).*[\'"]\/?wp-(?:load|config)\.php[\'"]\s*\)?;\s*$/m

    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 \n in which it worked, but the PHP v8.2 project uses \r\n.

  2. danielbachhuber commented on Oct 24, 2023

    @danielbachhuber
    Member

    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.

  3. willrowe commented on Oct 24, 2023

    @willrowe
    Author

    I'm guessing that adding \s* would be the correct fix? Since it would match \r and still allow $ to match the end of the line? Unless there's a better way to have $ match \r\n.

  4. danielbachhuber commented on Oct 24, 2023

    @danielbachhuber
    Member

    I think it will be easier to grok if you can get a test case going in a pull request.

  5. added this to the 2.10.0 milestone on Oct 27, 2023
  6. changed the title [-]Admin context crashing[/-] [+]Admin context crashes because of admin.php file formatting[/+] on Nov 4, 2023
  7. sejas commented on Nov 10, 2023

    @sejas

    I reproduced this issue on version 2.7.1, but it seems solved for wp-cli 2.9.0.

    Testing instructions:

    1. Executed wp --context=admin option get admin_email using the version 2.7.1
    2. Observed the mentioned warnings
    3. Updated wp-cli to the latest version 2.9.0 by running wp cli update
    4. Repeated wp --context=admin option get admin_email
    5. Observed the correct output without warnings
    wp --context=admin option get admin_email
    admin@example.com
    
  8. removed this from the 2.10.0 milestone on Nov 16, 2023
  9. added this to the 2.10.0 milestone on Nov 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      Sponsor
      SponsoredKunjungi sekarang
      Promo