From 23273e2c4e583543fc1ce9a87033a30f31ebfb83 Mon Sep 17 00:00:00 2001 From: Mike Selander Date: Fri, 15 Jul 2016 16:56:34 +0200 Subject: [PATCH 1/4] Added new API key custom argument for the gapi field --- classes.fields.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/classes.fields.php b/classes.fields.php index 9e539996..c3b6897f 100644 --- a/classes.fields.php +++ b/classes.fields.php @@ -1651,6 +1651,7 @@ public function get_default_args() { 'default_long' => '-0.12775829999998223', 'default_zoom' => '8', 'string-marker-title' => __( 'Drag to set the exact location', 'cmb' ), + 'google_api_key' => '', ) ); } @@ -1659,7 +1660,12 @@ public function enqueue_scripts() { parent::enqueue_scripts(); - wp_enqueue_script( 'cmb-google-maps', '//maps.google.com/maps/api/js?libraries=places' ); + $key = ''; + if ( ! empty( $this->args['google_api_key'] ) ){ + $key = $this->args['google_api_key']; + } + + wp_enqueue_script( 'cmb-google-maps', '//maps.google.com/maps/api/js?libraries=places&key=' . $key ); wp_enqueue_script( 'cmb-google-maps-script', trailingslashit( CMB_URL ) . 'js/field-gmap.js', array( 'jquery', 'cmb-google-maps' ) ); wp_localize_script( 'cmb-google-maps-script', 'CMBGmaps', array( From e5dd6fcfce3a72c32c6bb9ef2abdbc48be47fa77 Mon Sep 17 00:00:00 2001 From: Mike Selander Date: Fri, 15 Jul 2016 16:58:55 +0200 Subject: [PATCH 2/4] Updated example functions and fixed spelling error in readme --- example-functions.php | 2 +- readme.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/example-functions.php b/example-functions.php index eb18a71c..8339f11c 100644 --- a/example-functions.php +++ b/example-functions.php @@ -44,7 +44,7 @@ function cmb_sample_metaboxes( array $meta_boxes ) { array( 'id' => 'field-22', 'name' => 'Color', 'type' => 'colorpicker' ), - array( 'id' => 'field-23', 'name' => 'Location', 'type' => 'gmap' ), + array( 'id' => 'field-23', 'name' => 'Location', 'type' => 'gmap', 'google_api_key' => '{CUSTOM_KEY}' ), array( 'id' => 'field-24', 'name' => 'Title Field', 'type' => 'title' ), diff --git a/readme.md b/readme.md index 8eb69c8a..4f8aabcd 100644 --- a/readme.md +++ b/readme.md @@ -47,7 +47,7 @@ See [CONTRIBUTING.md](https://github.com/humanmade/Custom-Meta-Boxes/blob/master * Add hide_on field argument * Add Composer support * Enhancement - enable for attachments -* Fix bug with unnatached images on custom post types +* Fix bug with unattached images on custom post types * Fix error in WYSIWYG * Fix fields not getting correctly initialized if meta box is collapsed on page load * Fix bug with page-template restricted meta boxes showing if the post hasn't been saved at all. From 84a5c90032f5ec8a77428083f90df18288ed9035 Mon Sep 17 00:00:00 2001 From: Mike Selander Date: Wed, 10 Aug 2016 20:34:24 +0100 Subject: [PATCH 3/4] Added Google key constant in addition to field variable --- classes.fields.php | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/classes.fields.php b/classes.fields.php index 1c516d90..ad0e206e 100644 --- a/classes.fields.php +++ b/classes.fields.php @@ -1661,12 +1661,22 @@ public function enqueue_scripts() { parent::enqueue_scripts(); - $key = ''; + $maps_src = '//maps.google.com/maps/api/js?libraries=places'; + + // Check for our key with either a field argument or constant. if ( ! empty( $this->args['google_api_key'] ) ){ $key = $this->args['google_api_key']; + } if ( defined( 'CMB_GAPI_KEY' ) ) { + $key = CMB_GAPI_KEY; + } + + // Only add the key argument if it's been set. + if ( ! empty( $key ) ) { + $maps_src = add_query_arg( 'key', $key, $maps_src ); } - wp_enqueue_script( 'cmb-google-maps', '//maps.google.com/maps/api/js?libraries=places&key=' . $key ); + // Enqueue our scripts. + wp_enqueue_script( 'cmb-google-maps', $maps_src ); wp_enqueue_script( 'cmb-google-maps-script', trailingslashit( CMB_URL ) . 'js/field-gmap.js', array( 'jquery', 'cmb-google-maps' ) ); wp_localize_script( 'cmb-google-maps-script', 'CMBGmaps', array( From a844f252317b503a894694a806d20e0265d04b3d Mon Sep 17 00:00:00 2001 From: Mike Selander Date: Wed, 10 Aug 2016 20:36:58 +0100 Subject: [PATCH 4/4] Fixed elseif statement --- classes.fields.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/classes.fields.php b/classes.fields.php index ad0e206e..5ee29555 100644 --- a/classes.fields.php +++ b/classes.fields.php @@ -1666,7 +1666,7 @@ public function enqueue_scripts() { // Check for our key with either a field argument or constant. if ( ! empty( $this->args['google_api_key'] ) ){ $key = $this->args['google_api_key']; - } if ( defined( 'CMB_GAPI_KEY' ) ) { + } elseif ( defined( 'CMB_GAPI_KEY' ) ) { $key = CMB_GAPI_KEY; }