diff --git a/lib/WCTokyo/WpCheckin/Command.php b/lib/WCTokyo/WpCheckin/Command.php index 6fdaef5..531d6f5 100644 --- a/lib/WCTokyo/WpCheckin/Command.php +++ b/lib/WCTokyo/WpCheckin/Command.php @@ -20,12 +20,9 @@ class Command extends \WP_CLI_Command { * @return void */ public function is_valid() { - $me = $this->rest_request( '/wp/v2/users/me', 'GET', [ + $me = $this->rest_request( '/wp/v2/users/me', 'GET', [ 'context' => 'edit', ] ); - if ( is_wp_error( $me ) ) { - \WP_CLI::error( $me->get_error_message() ); - } $table = new Table(); $table->setHeaders( [ 'Property', 'Value' ] ); foreach ( $me as $key => $value ) { @@ -42,4 +39,30 @@ public function is_valid() { $table->display(); \WP_CLI::success( __( 'ユーザー情報を取得しました。', 'wp-checkin' ) ); } + + /** + * Display API. + * + * @return void + */ + public function namespaces() { + $response = $this->rest_request( '/' ); + foreach ( $response['namespaces'] as $namespace ) { + \WP_CLI::line( sprintf( '%s/wp-json/%s', trailingslashit( get_option( 'wordcamp_site_url' ) ), $namespace ) ); + } + \WP_CLI::line( '' ); + // translators: %d is number of namespaces. + \WP_CLI::success( sprintf( __( '%dの名前空間があります。', 'wp-checkin' ), count( $response['namespaces'] ) ) ); + } + + /** + * {@see Request::rest_request()} + */ + private function request( $path, $method = 'GET', $data = [] ) { + $response = $this->rest_request( $path, $method, $data ); + if ( is_wp_error( $response ) ) { + \WP_CLI::error( $response->get_error_message() ); + } + return $response; + } } diff --git a/lib/WCTokyo/WpCheckin/Screen/Setting.php b/lib/WCTokyo/WpCheckin/Screen/Setting.php index 5e470e3..bc2d65f 100644 --- a/lib/WCTokyo/WpCheckin/Screen/Setting.php +++ b/lib/WCTokyo/WpCheckin/Screen/Setting.php @@ -30,7 +30,7 @@ public function register_option() { 'wp_checkin_settings', __( 'WordCamp チェックイン設定', 'wp-checkin' ), function() { - printf( '

%s

', esc_html__( 'WordCampのチェックインシステムに必要な設定を行います。', 'wp-checkin' ) ); + printf( '

%s

', esc_html__( 'WordCampのチェックインシステムに必要な設定を行います。', 'wp-checkin' ) ); }, 'general' ); diff --git a/lib/WCTokyo/WpCheckin/Utilities/Request.php b/lib/WCTokyo/WpCheckin/Utilities/Request.php index f32bbe9..449021a 100644 --- a/lib/WCTokyo/WpCheckin/Utilities/Request.php +++ b/lib/WCTokyo/WpCheckin/Utilities/Request.php @@ -24,7 +24,7 @@ protected function rest_request( $path, $method = 'GET', $data = [] ) { 'status' => 400, ] ); } - $url = get_option( 'wordcamp_site_url' ); + $url = get_option( 'wordcamp_site_url' ); $user = get_option( 'wordcamp_user_login' ); $pass = get_option( 'application_password' ); if ( ! $url || ! $user || ! $pass ) { @@ -33,7 +33,7 @@ protected function rest_request( $path, $method = 'GET', $data = [] ) { ] ); } $endpoint = trailingslashit( $url ) . 'wp-json/' . ltrim( $path, '/' ); - $args = [ + $args = [ 'method' => $method, 'timeout' => (int) apply_filters( 'wp_checkin_timeout', 30, $path, $method, $data ), 'headers' => [