Running WP-CLI with WP_ADMIN causes redirect
-
Hi,
I’ve been using your plugin on many websites and works as advertised! Thanks for putting in all the hard work! ??
Recently I’ve come across a few scenarios where I need to run WP-CLI as admin (using the –exec=”define(‘WP_ADMIN’, true);” flag). This is because some plugins will only be updated via wp-cli if is_admin() returns true. Right or wrong is irrelevant, quite a few (paid) plugins use this.
If WPS Hide Login is enabled, this causes the following error:
# wp plugin list --exec="define('WP_ADMIN', true);" Warning: Some code is trying to do a URL redirect. Backtrace: #0 WP_CLI\Utils\wp_redirect_handler(https://mydomain.ext/404/) called at [/var/www/mydomain.ext/wp-includes/class-wp-hook.php:305] #1 WP_Hook->apply_filters(https://mydomain.ext/404/, Array ([0] => https://mydomain.ext/404/,[1] => 302)) called at [/var/www/mydomain.ext/wp-includes/plugin.php:189] #2 apply_filters(wp_redirect, https://mydomain.ext/404/, 302) called at [/var/www/mydomain.ext/wp-includes/pluggable.php:1301] #3 wp_redirect(https://mydomain.ext/404/, 302, WordPress) called at [/var/www/mydomain.ext/wp-includes/pluggable.php:1448] #4 wp_safe_redirect(https://mydomain.ext/404/) called at [/var/www/mydomain.ext/wp-content/plugins/wps-hide-login/classes/plugin.php:532] #5 WPS\WPS_Hide_Login\Plugin->wp_loaded() called at [/var/www/mydomain.ext/wp-includes/class-wp-hook.php:303] #6 WP_Hook->apply_filters(, Array ([0] => )) called at [/var/www/mydomain.ext/wp-includes/class-wp-hook.php:327] #7 WP_Hook->do_action(Array ([0] => )) called at [/var/www/mydomain.ext/wp-includes/plugin.php:470] #8 do_action(wp_loaded) called at [/var/www/mydomain.ext/wp-settings.php:600] #9 require(/var/www/mydomain.ext/wp-settings.php) called at [phar:///usr/local/bin/wp/vendor/wp-cli/wp-cli/php/WP_CLI/Runner.php:1271] #10 WP_CLI\Runner->load_wordpress() called at [phar:///usr/local/bin/wp/vendor/wp-cli/wp-cli/php/WP_CLI/Runner.php:1192] #11 WP_CLI\Runner->start() called at [phar:///usr/local/bin/wp/vendor/wp-cli/wp-cli/php/WP_CLI/Bootstrap/LaunchRunner.php:23] #12 WP_CLI\Bootstrap\LaunchRunner->process(WP_CLI\Bootstrap\BootstrapState Object ([WP_CLI\Bootstrap\BootstrapStatestate] => Array ())) called at [phar:///usr/local/bin/wp/vendor/wp-cli/wp-cli/php/bootstrap.php:77] #13 WP_CLI\bootstrap() called at [phar:///usr/local/bin/wp/vendor/wp-cli/wp-cli/php/wp-cli.php:27] #14 include(phar:///usr/local/bin/wp/vendor/wp-cli/wp-cli/php/wp-cli.php) called at [phar:///usr/local/bin/wp/php/boot-phar.php:11] #15 include(phar:///usr/local/bin/wp/php/boot-phar.php) called at [/usr/local/bin/wp:4]
After doing some digging in the plugin code, it seems to be easily fixed by changing line 531 in classes/plugin.php to (note the added ! defined( ‘WP_CLI’ )):
if ( is_admin() && ! is_user_logged_in() && ! defined( 'WP_CLI' ) && ! defined( 'DOING_AJAX' ) && ! defined( 'DOING_CRON' ) && $pagenow !== 'admin-post.php' && $request['path'] !== '/wp-admin/options.php' ) {
After that, the plugin no longer tries to redirect when using WP-CLI.
I’m hoping you can add this in the next release! ??Wordpress version: 5.8.2
WPS Hide Login version: 1.9.1Regards,
Rinck
- The topic ‘Running WP-CLI with WP_ADMIN causes redirect’ is closed to new replies.