/** * 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; }
/** * ## OPTIONS * * <url> * : URL for the WordPress site * * @when before_wp_load */ public function status($args) { $locator = new Locator(); try { $url = $locator->locate($args[0]); $auth = Authenticator::get_for_site($url); if (empty($auth)) { WP_CLI::error(sprintf('No authentication found for %s', $url)); } $token = $auth->get_token(); $consumer = $auth->get_consumer(); WP_CLI::line(sprintf('Consumer key: %s', $consumer->key)); WP_CLI::line(sprintf('Consumer secret: %s', $consumer->secret)); WP_CLI::line(sprintf('Token key: %s', $token->key)); WP_CLI::line(sprintf('Token secret: %s', $token->secret)); } catch (Exception $e) { WP_CLI::error($e->getMessage()); } }