Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Kevin Vess

    (@kevinvess)

    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

    Plugin Author Kevin Vess

    (@kevinvess)

    Try adding this to the plugin code:
    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.

    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

    (@kevinvess)

    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.