Skip to content

Commit

Permalink
Mapbox: query for an API key differently depending on platform (#14442)
Browse files Browse the repository at this point in the history
An alternative to #14440
  • Loading branch information
jeherve authored Jan 23, 2020
1 parent 40154a3 commit baeb9e4
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions extensions/blocks/map/map.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,27 @@
* @return string
*/
function jetpack_get_mapbox_api_key() {
if ( ! class_exists( 'WPCOM_REST_API_V2_Endpoint_Service_API_Keys' ) || ! Jetpack::is_active() ) {
return Jetpack_Options::get_option( 'mapbox_api_key' );
if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) {
$endpoint = sprintf(
'https://public-api.wordpress.com/wpcom/v2/sites/%d/service-api-keys/mapbox',
get_current_blog_id()
);
} else {
$endpoint = sprintf(
'%swpcom/v2/service-api-keys/mapbox',
rest_url()
);
}

$response = wp_remote_get( esc_url_raw( $endpoint ) );
$response_code = wp_remote_retrieve_response_code( $response );

if ( 200 === $response_code ) {
$response_body = json_decode( wp_remote_retrieve_body( $response ) );
return $response_body->service_api_key;
}
$response = WPCOM_REST_API_V2_Endpoint_Service_API_Keys::get_service_api_key( array( 'service' => 'mapbox' ) );
return $response['service_api_key'];

return Jetpack_Options::get_option( 'mapbox_api_key' );
}

/**
Expand Down

0 comments on commit baeb9e4

Please sign in to comment.