Plugin Directory

Changeset 2054291


Ignore:
Timestamp:
03/20/2019 10:13:52 PM (7 years ago)
Author:
andrew.taylor
Message:

Version 1.5.2

Location:
embed-gutenberg-block-google-maps/trunk
Files:
2 added
2 deleted
2 edited

Legend:

Unmodified
Added
Removed
  • embed-gutenberg-block-google-maps/trunk/embed-gutenberg-block-google-maps.php

    r2020814 r2054291  
    55 * Author: Pantheon, Andrew Taylor
    66 * Author URI: https://pantheon.io/
    7  * Version: 1.5.1
    8  * License: GPL2
    9  * License URI: http://www.gnu.org/licenses/gpl-2.0.txt
     7 * Version: 1.5.2
     8 * License: MIT
     9 * License URI: https://opensource.org/licenses/MIT
    1010 * Text Domain: pantheon-google-map-block
    1111 * Requires PHP: 5.6
     
    4343{
    4444    // Make paths variables so we don't write em twice ;)
    45     $hash = 'aef3c8c366ce19f8c0b4';
     45    $hash = '836e5da587e9ec9692c0';
    4646    $blockPath = "assets/js/index.$hash.js";
    4747    $stylePath = "assets/css/style.$hash.css";
     
    6363                wp_json_encode(
    6464                    array(
     65                        'APIKeyConstantDefined' => defined( 'GOOGLE_MAPS_API_KEY' ),
    6566                        'APIKey' => getGoogleMapAPIKey(),
    6667                        'userCanManageOptions' => current_user_can( 'manage_options' ),
     
    126127    // Set the API url based to embed or static maps based on the interactive setting
    127128    $apiURL = ( $interactive ) ? "https://www.google.com/maps/embed/v1/place?key=${APIkey}&q=${location}&zoom=${zoom}&maptype=${mapType}" : "https://maps.googleapis.com/maps/api/staticmap?center=${location}&zoom=${zoom}&size=${maxWidth}x${maxHeight}&maptype=${mapType}&key=${APIkey}";
    128    
    129     // Check status code of apiURL
    130     $ch = curl_init($apiURL);
    131     curl_setopt($ch, CURLOPT_HEADER, true);
    132     curl_setopt($ch, CURLOPT_NOBODY, true);
    133     curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
    134     curl_setopt($ch, CURLOPT_TIMEOUT,10);
    135     $output = curl_exec($ch);
    136     $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    137     curl_close($ch);
    138 
    139     // Don't output anything if the response from Google Maps isn't a 200
     129
     130    // Look for a cached response code for the map URL.
     131    $httpcode = get_transient( 'pantheon_google_map_block_url_response_code' );
     132
     133    // Ensure the status code from cache is an integer.
     134    if( false !== $httpcode ) {
     135        $httpcode = intval( $httpcode );
     136    }
     137
     138    // If the response code is not found in the cache
     139    // Or the current response code is not a 200
     140    if( false === $httpcode || $httpcode !== 200 ) {
     141        // Get a new response code for the map URL
     142        $response = wp_remote_head( $apiURL );
     143        $httpcode = wp_remote_retrieve_response_code( $response );
     144        // Set a transient to cache the response code.
     145        set_transient( 'pantheon_google_map_block_url_response_code', $httpcode, DAY_IN_SECONDS );
     146    }
     147
     148    // Don't output anything if the response from Google Maps isn't a 200.
    140149    if( $httpcode !== 200 ){
    141150        return;
     
    147156    // Create the output
    148157    $output = "<div class='$classNames'><div class='map'>";
     158
    149159    // If the map is interactive show the iframe
    150160    if( $interactive ){
     
    166176 */
    167177function registerMapBlock() {
    168     if( \function_exists('register_block_type') ){
     178    if( function_exists('register_block_type') ){
    169179        blockScripts();
    170         \register_block_type( 'pantheon/google-map', array(
     180        register_block_type( 'pantheon/google-map', array(
    171181            'editor_script' => 'pantheon-google-map-block-js',
    172182            'style' => 'pantheon-google-map-block-css',
  • embed-gutenberg-block-google-maps/trunk/readme.txt

    r2020814 r2054291  
    55Plugin URI: https://github.com/pantheon-systems/google-map-gutenberg-block
    66Requires at least: 5.0
    7 Tested up to: 5.0.3
     7Tested up to: 5.1.1
    88Requires PHP: 5.6
    9 Stable tag: 1.5.1
    10 License: GPLv2 or later
    11 License URI: http://www.gnu.org/licenses/gpl-2.0.html
     9Stable tag: 1.5.2
     10License: MIT
     11License URI: https://opensource.org/licenses/MIT
    1212 
    1313This plugin provides a Google Maps embed block for the Gutenberg editor.
     
    6868== Changelog ==
    6969
     70= 1.5.2 =
     71Use the [WordPress HTTP API](https://developer.wordpress.org/plugins/http-api/) instead of `curl` to check the response code of the map URL. Additionally, cache the map URL response code in a transient to avoid making a request on each page load.
     72
     73Hide the API key input section in the map block settings when the Google Map API key is defined with the `GOOGLE_MAPS_API_KEY` constant. Additionally, add the `api-key-input-container` class to the `div` surrounding the API key input field in the map block settings for easier styling.
     74
    7075= 1.5.1 =
    7176Aspect ratio bug fixes to address [this WordPress.org issue](https://circleci.com/docs/api/#trigger-a-new-job).
Note: See TracChangeset for help on using the changeset viewer.