Title: wp-cli not working
Last modified: August 22, 2016

---

# wp-cli not working

 *  Resolved [shonej](https://wordpress.org/support/users/shonej/)
 * (@shonej)
 * [11 years, 2 months ago](https://wordpress.org/support/topic/wp-cli-not-working/)
 * Hi,
    wp-cli commands are not working when this is activated. Getting error in
   console.
 * Warning: Some code is trying to do a URL redirect. Backtrace:
    #0 WP_CLI\Utils\
   wp_redirect_handler([http://10.0.0.18/html/wordpress/wp-login.php?redirect_to=http%3A%2F%2F%3A](http://10.0.0.18/html/wordpress/wp-login.php?redirect_to=http%3A%2F%2F%3A))#
   1 call_user_func_array(WP_CLI\Utils\wp_redirect_handler, Array ([0] => [http://10.0.0.18/html/wordpress/wp-login.php?redirect_to=http%3A%2F%2F%3A](http://10.0.0.18/html/wordpress/wp-login.php?redirect_to=http%3A%2F%2F%3A)))
   called at [/var/www/html/wordpress/wp-includes/plugin.php:213] #2 apply_filters(
   wp_redirect, [http://10.0.0.18/html/wordpress/wp-login.php?redirect_to=http%3A%2F%2F%3A](http://10.0.0.18/html/wordpress/wp-login.php?redirect_to=http%3A%2F%2F%3A),
   302) called at [/var/www/html/wordpress/wp-includes/pluggable.php:1158] #3 wp_redirect(
   [http://10.0.0.18/html/wordpress/wp-login.php?redirect_to=http%3A%2F%2F%3A](http://10.0.0.18/html/wordpress/wp-login.php?redirect_to=http%3A%2F%2F%3A),
   302) called at [/var/www/html/wordpress/wp-includes/pluggable.php:1226] #4 wp_safe_redirect(
   [http://10.0.0.18/html/wordpress/wp-login.php?redirect_to=http%3A%2F%2F%3A](http://10.0.0.18/html/wordpress/wp-login.php?redirect_to=http%3A%2F%2F%3A),
   302) called at [/var/www/html/wordpress/wp-content/plugins/wp-force-login/wp-
   force-login.php:38] #5 v_forcelogin() #6 call_user_func_array(v_forcelogin, Array([
   0] => )) called at [/var/www/html/wordpress/wp-includes/plugin.php:496] #7 do_action(
   init) called at [phar:///usr/bin/wp-cli/php/wp-settings-cli.php:349] #8 require(
   phar:///usr/bin/wp-cli/php/wp-settings-cli.php) called at [phar:///usr/bin/wp-
   cli/php/wp-cli.php:26] #9 include(phar:///usr/bin/wp-cli/php/wp-cli.php) called
   at [phar:///usr/bin/wp-cli/php/boot-phar.php:5] #10 include(phar:///usr/bin/wp-
   cli/php/boot-phar.php) called at [/usr/bin/wp-cli:4]
 * [https://wordpress.org/plugins/wp-force-login/](https://wordpress.org/plugins/wp-force-login/)

Viewing 4 replies - 1 through 4 (of 4 total)

 *  Plugin Author [Kevin Vess](https://wordpress.org/support/users/kevinvess/)
 * (@kevinvess)
 * [11 years, 2 months ago](https://wordpress.org/support/topic/wp-cli-not-working/#post-5867743)
 * This plugin was not built with _WP-CLI_ in mind.
 * However, you could try adding a conditional statement to the v_forcelogin() function
   that adds an exception for requests by localhost or whatever IP address your 
   command-line tool is making it’s requests from:
 * [https://gist.github.com/kevinvess/bf965291460eee1e6e2d#file-wp-force-login-alt-php-L6](https://gist.github.com/kevinvess/bf965291460eee1e6e2d#file-wp-force-login-alt-php-L6)
 *  Plugin Author [Kevin Vess](https://wordpress.org/support/users/kevinvess/)
 * (@kevinvess)
 * [11 years, 1 month ago](https://wordpress.org/support/topic/wp-cli-not-working/#post-5868075)
 * Try adding this to the plugin code:
    [https://gist.github.com/kevinvess/b121851ec52c53b6cbb6#file-wp-force-login-cli-php-L3-L9](https://gist.github.com/kevinvess/b121851ec52c53b6cbb6#file-wp-force-login-cli-php-L3-L9)
 * Add the new _v\_is\_cli()_ function on lines 3 to 9; also add the condition statement
   on line 13 to 15.
 * Let me know if this resolves your issue and I might incorporate it into a new
   version.
 *  [thomaswp](https://wordpress.org/support/users/thomaswp/)
 * (@thomaswp)
 * [11 years ago](https://wordpress.org/support/topic/wp-cli-not-working/#post-5868115)
 * Nice plugin, althought same issue with wp-cli here, hade to make a minor change
   to your gist. Would be great to incorporate this in a new version of the plugin.
 *     ```
       function v_is_cli() {
         if(php_sapi_name() == 'cli' && empty($_SERVER['REMOTE_ADDR']) || $_SERVER['REMOTE_ADDR'] == '127.0.0.1') {
           return true;
         } else {
           return false;
         }
       }
       ```
   
 *  Plugin Author [Kevin Vess](https://wordpress.org/support/users/kevinvess/)
 * (@kevinvess)
 * [11 years ago](https://wordpress.org/support/topic/wp-cli-not-working/#post-5868117)
 * Thanks for trying my gist suggestion and offering some feedback!
 * Since I originally posted that gist, I’ve released a new version (ver 3.0) and
   with it I believe anyone looking to allow _wp-cil_ commands to work should try
   adding the following code to their theme’s functions.php file:
 *     ```
       /**
        * Filter Force Login to allow exceptions for specific URLs.
        *
        * @return array An array of URLs. Must be absolute.
        **/
       function my_forcelogin_whitelist() {
         // list of single page URLs
         $my_whitelist = array(
           //site_url( '/mypage/' )
         );
         // allow wp-cil commands
         if(php_sapi_name() == 'cli' && empty($_SERVER['REMOTE_ADDR']) || $_SERVER['REMOTE_ADDR'] == '127.0.0.1') {
           $my_whitelist[] = site_url($_SERVER['REQUEST_URI']);
         }
         return $my_whitelist;
       }
       add_filter('v_forcelogin_whitelist', 'my_forcelogin_whitelist', 10, 1);
       ```
   

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘wp-cli not working’ is closed to new replies.

 * ![](https://ps.w.org/wp-force-login/assets/icon.svg?rev=1904031)
 * [Force Login](https://wordpress.org/plugins/wp-force-login/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/wp-force-login/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/wp-force-login/)
 * [Active Topics](https://wordpress.org/support/plugin/wp-force-login/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wp-force-login/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wp-force-login/reviews/)

## Tags

 * [wp-cli](https://wordpress.org/support/topic-tag/wp-cli/)

 * 4 replies
 * 3 participants
 * Last reply from: [Kevin Vess](https://wordpress.org/support/users/kevinvess/)
 * Last activity: [11 years ago](https://wordpress.org/support/topic/wp-cli-not-working/#post-5868117)
 * Status: resolved