Ejemplo n.º 1
0
 /**
  * Get a connection object for making requests.
  *
  * @return WPAPI
  */
 protected function get_connection($url)
 {
     $locator = new Locator();
     $url = $locator->locate($url);
     $auth = Authenticator::get_for_site($url);
     if (empty($auth)) {
         throw new Exception('No authentication available; use `wp api oauth1 connect` first');
     }
     $api = new WPAPI($url);
     $api->setAuth($auth);
     return $api;
 }
Ejemplo n.º 2
0
 /**
  * ## OPTIONS
  *
  * <url>
  * : URL for the WordPress site
  *
  * @when before_wp_load
  */
 public function disconnect($args)
 {
     try {
         // Find the API
         $locator = new Locator();
         $url = $locator->locate($args[0]);
         if (!Authenticator::delete_for_site($url)) {
             WP_CLI::error("Could not disconnect client");
         } else {
             WP_CLI::success(sprintf('Disconnected from %s', $url));
         }
     } catch (Exception $e) {
         WP_CLI::error($e->getMessage());
     }
 }