diff options
Diffstat (limited to 'plugins/jetpack/_inc/lib/core-api/wpcom-endpoints/service-api-keys.php')
-rw-r--r-- | plugins/jetpack/_inc/lib/core-api/wpcom-endpoints/service-api-keys.php | 36 |
1 files changed, 25 insertions, 11 deletions
diff --git a/plugins/jetpack/_inc/lib/core-api/wpcom-endpoints/service-api-keys.php b/plugins/jetpack/_inc/lib/core-api/wpcom-endpoints/service-api-keys.php index 8f279ea9..fde032ca 100644 --- a/plugins/jetpack/_inc/lib/core-api/wpcom-endpoints/service-api-keys.php +++ b/plugins/jetpack/_inc/lib/core-api/wpcom-endpoints/service-api-keys.php @@ -1,4 +1,10 @@ -<?php +<?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName +/** + * Get and save API keys for a site. + * + * @package automattic/jetpack + */ + /** * Service API Keys: Exposes 3rd party api keys that are used on a site. * @@ -17,13 +23,19 @@ */ class WPCOM_REST_API_V2_Endpoint_Service_API_Keys extends WP_REST_Controller { - function __construct() { + /** + * Constructor. + */ + public function __construct() { $this->namespace = 'wpcom/v2'; $this->rest_base = 'service-api-keys'; add_action( 'rest_api_init', array( $this, 'register_routes' ) ); } + /** + * Register endpoint routes. + */ public function register_routes() { register_rest_route( 'wpcom/v2', @@ -54,6 +66,9 @@ class WPCOM_REST_API_V2_Endpoint_Service_API_Keys extends WP_REST_Controller { ); } + /** + * Permission check. + */ public static function edit_others_posts_check() { if ( current_user_can( 'edit_others_posts' ) ) { return true; @@ -133,7 +148,7 @@ class WPCOM_REST_API_V2_Endpoint_Service_API_Keys extends WP_REST_Controller { $option = self::key_for_api_service( $service ); $service_api_key = Jetpack_Options::get_option( $option, '' ); $service_api_key_source = 'site'; - }; + } $message = esc_html__( 'API key retrieved successfully.', 'jetpack' ); @@ -160,10 +175,10 @@ class WPCOM_REST_API_V2_Endpoint_Service_API_Keys extends WP_REST_Controller { if ( ! $service ) { return self::service_api_invalid_service_response(); } - $json_params = $request->get_json_params(); - $params = ! empty( $json_params ) ? $json_params : $request->get_body_params(); - $service_api_key = trim( $params['service_api_key'] ); - $option = self::key_for_api_service( $service ); + $json_params = $request->get_json_params(); + $params = ! empty( $json_params ) ? $json_params : $request->get_body_params(); + $service_api_key = trim( $params['service_api_key'] ); + $option = self::key_for_api_service( $service ); $validation = self::validate_service_api_key( $service_api_key, $service, $params ); if ( ! $validation['status'] ) { @@ -211,7 +226,7 @@ class WPCOM_REST_API_V2_Endpoint_Service_API_Keys extends WP_REST_Controller { default: $service_api_key = Jetpack_Options::get_option( $option, '' ); $service_api_key_source = 'site'; - }; + } return array( 'code' => 'success', @@ -298,9 +313,9 @@ class WPCOM_REST_API_V2_Endpoint_Service_API_Keys extends WP_REST_Controller { $mapbox_geocode_response = wp_safe_remote_get( esc_url_raw( $mapbox_geocode_url ) ); $mapbox_geocode_body = wp_remote_retrieve_body( $mapbox_geocode_response ); $mapbox_geocode_json = json_decode( $mapbox_geocode_body ); - if ( isset( $mapbox_geocode_json->message ) && ! isset( $mapbox_geocode_json->query ) ) { + if ( isset( $mapbox_geocode_json->message ) || ! isset( $mapbox_geocode_json->query ) ) { $status = false; - $msg = $mapbox_geocode_json->message; + $msg = isset( $mapbox_geocode_json->message ) ? $mapbox_geocode_json->message : 'Unknown error'; } return array( 'status' => $status, @@ -317,5 +332,4 @@ class WPCOM_REST_API_V2_Endpoint_Service_API_Keys extends WP_REST_Controller { return $service . '_api_key'; } } - wpcom_rest_api_v2_load_plugin( 'WPCOM_REST_API_V2_Endpoint_Service_API_Keys' ); |