Google Reviews Widget - Version 1.6.3

Version Description

  • Important note: Google has changed the Places API and now this is limited to 1 request per day for new accounts, we have changed the plugin according to this limitation
  • Improve: added feature to upload custom place photo
Download this release

Release Info

Developer widgetpack
Plugin Icon 128x128 Google Reviews Widget
Version 1.6.3
Comparing to
See all releases

Code changes from version 1.6.2 to 1.6.3

grw-finder.php CHANGED
@@ -1,8 +1,20 @@
1
- <!-- 1. Find Place -->
2
  <div class="form-group">
 
 
 
 
 
 
 
 
 
 
 
 
 
3
  <div class="col-sm-12">
4
  <h4 class="text-left"><span class="grw-step">1</span><?php echo grw_i('Find Place'); ?></h4>
5
- <input type="text" class="grw-place-search form-control" value="" placeholder="Location of place (e.g. name, address)" />
6
  </div>
7
  </div>
8
  <div class="form-group">
@@ -10,14 +22,12 @@
10
  <button class="grw-search-btn btn btn-block btn-primary"><?php echo grw_i('Search Place'); ?></button>
11
  </div>
12
  </div>
13
- <!-- 2. Select Place -->
14
  <div class="form-group">
15
  <div class="col-sm-12">
16
  <h4 class="text-left"><span class="grw-step">2</span><?php echo grw_i('Select Place'); ?></h4>
17
  <div class="grw-places"></div>
18
  </div>
19
  </div>
20
- <!-- 3. Save Reviews -->
21
  <div class="form-group">
22
  <div class="col-sm-12">
23
  <h4 class="text-left"><span class="grw-step">3</span><?php echo grw_i('Save Place and Reviews'); ?></h4>
@@ -25,4 +35,4 @@
25
  <div class="grw-five-reviews-note" style="display:none"><?php echo grw_i('Google returns 5 reviews only'); ?></div>
26
  <div class="grw-save-reviews-container"></div>
27
  </div>
28
- </div>
 
1
  <div class="form-group">
2
+ <div class="col-sm-12">
3
+ <h4><?php echo grw_i('Enter Place ID of your Google business. If you don\'t know this, you can simply find it by <a href="https://www.launch2success.com/guide/find-any-google-id/" target="_blank">this instruction</a>.'); ?></h4>
4
+ <input type="text" class="grw-place-id form-control" value="" placeholder="Place ID" />
5
+ <small class="grw-error"></small>
6
+ </div>
7
+ </div>
8
+ <div class="form-group">
9
+ <div class="col-sm-12">
10
+ <button class="grw-connect-btn btn btn-block btn-primary"><?php echo grw_i('Connect Google'); ?></button>
11
+ </div>
12
+ </div>
13
+
14
+ <!--div class="form-group">
15
  <div class="col-sm-12">
16
  <h4 class="text-left"><span class="grw-step">1</span><?php echo grw_i('Find Place'); ?></h4>
17
+ <input type="text" class="grw-place-search form-control" value="" placeholder="Place ID" />
18
  </div>
19
  </div>
20
  <div class="form-group">
22
  <button class="grw-search-btn btn btn-block btn-primary"><?php echo grw_i('Search Place'); ?></button>
23
  </div>
24
  </div>
 
25
  <div class="form-group">
26
  <div class="col-sm-12">
27
  <h4 class="text-left"><span class="grw-step">2</span><?php echo grw_i('Select Place'); ?></h4>
28
  <div class="grw-places"></div>
29
  </div>
30
  </div>
 
31
  <div class="form-group">
32
  <div class="col-sm-12">
33
  <h4 class="text-left"><span class="grw-step">3</span><?php echo grw_i('Save Place and Reviews'); ?></h4>
35
  <div class="grw-five-reviews-note" style="display:none"><?php echo grw_i('Google returns 5 reviews only'); ?></div>
36
  <div class="grw-save-reviews-container"></div>
37
  </div>
38
+ </div-->
grw-options.php CHANGED
@@ -6,6 +6,16 @@
6
  </div>
7
  <?php } ?>
8
 
 
 
 
 
 
 
 
 
 
 
9
  <div class="form-group">
10
  <div class="col-sm-12">
11
  <input type="text" id="<?php echo $this->get_field_id('place_name'); ?>" name="<?php echo $this->get_field_name('place_name'); ?>" value="<?php echo $place_name; ?>" class="form-control grw-google-place-name" placeholder="<?php echo grw_i('Google Place Name'); ?>" readonly />
@@ -81,13 +91,6 @@
81
  <!-- Display Options -->
82
  <h4 class="rplg-options-toggle"><?php echo grw_i('Display Options'); ?></h4>
83
  <div class="rplg-options" style="display:none">
84
- <div class="form-group rplg-disabled">
85
- <div class="col-sm-12">
86
- <label>
87
- <?php echo grw_i('Custom Place photo'); ?>
88
- </label>
89
- </div>
90
- </div>
91
  <div class="form-group rplg-disabled">
92
  <div class="col-sm-12">
93
  <label>
6
  </div>
7
  <?php } ?>
8
 
9
+ <?php global $wp_version; if (version_compare($wp_version, '3.5', '>=')) { wp_enqueue_media(); ?>
10
+ <div class="form-group">
11
+ <div class="col-sm-12">
12
+ <img id="<?php echo $this->get_field_id('place_photo_img'); ?>" src="<?php echo $place_photo; ?>" alt="<?php echo $place_name; ?>" class="grw-place-photo-img" style="display:<?php if ($place_photo) { ?>inline-block<?php } else { ?>none<?php } ?>;width:32px;height:32px;border-radius:50%;">
13
+ <a id="<?php echo $this->get_field_id('place_photo_btn'); ?>" href="#" class="grw-place-photo-btn"><?php echo grw_i('Change Place photo'); ?></a>
14
+ <input type="hidden" id="<?php echo $this->get_field_id('place_photo'); ?>" name="<?php echo $this->get_field_name('place_photo'); ?>" value="<?php echo $place_photo; ?>" class="form-control grw-place-photo" tabindex="2"/>
15
+ </div>
16
+ </div>
17
+ <?php } ?>
18
+
19
  <div class="form-group">
20
  <div class="col-sm-12">
21
  <input type="text" id="<?php echo $this->get_field_id('place_name'); ?>" name="<?php echo $this->get_field_name('place_name'); ?>" value="<?php echo $place_name; ?>" class="form-control grw-google-place-name" placeholder="<?php echo grw_i('Google Place Name'); ?>" readonly />
91
  <!-- Display Options -->
92
  <h4 class="rplg-options-toggle"><?php echo grw_i('Display Options'); ?></h4>
93
  <div class="rplg-options" style="display:none">
 
 
 
 
 
 
 
94
  <div class="form-group rplg-disabled">
95
  <div class="col-sm-12">
96
  <label>
grw-reviews-helper.php CHANGED
@@ -1,8 +1,7 @@
1
  <?php
2
- function grw_place($rating, $place, $reviews, $dark_theme, $show_powered = true) {
3
  ?>
4
  <div class="wp-google-left">
5
- <?php $place_img = strlen($place->photo) > 0 ? $place->photo : $place->icon; ?>
6
  <img src="<?php echo $place_img; ?>" alt="<?php echo $place->name; ?>">
7
  </div>
8
  <div class="wp-google-right">
1
  <?php
2
+ function grw_place($rating, $place, $place_img, $reviews, $dark_theme, $show_powered = true) {
3
  ?>
4
  <div class="wp-google-left">
 
5
  <img src="<?php echo $place_img; ?>" alt="<?php echo $place->name; ?>">
6
  </div>
7
  <div class="wp-google-right">
grw-reviews.php CHANGED
@@ -22,6 +22,7 @@ if ($place->rating > 0) {
22
  $rating = round($rating / count($reviews), 1);
23
  }
24
  $rating = number_format((float)$rating, 1, '.', '');
 
25
  ?>
26
 
27
  <?php if ($view_mode != 'list') { ?>
@@ -56,7 +57,7 @@ $rating = number_format((float)$rating, 1, '.', '');
56
  <div class="wp-google-form" style="display:none">
57
  <div class="wp-google-head">
58
  <div class="wp-google-head-inner">
59
- <?php grw_place($rating, $place, $reviews, $dark_theme, false); ?>
60
  </div>
61
  <button class="wp-google-close" type="button" onclick="this.parentNode.parentNode.style.display='none'">×</button>
62
  </div>
@@ -78,7 +79,7 @@ $rating = number_format((float)$rating, 1, '.', '');
78
  <div class="wp-gr wpac" style="<?php if (isset($max_width) && strlen($max_width) > 0) { ?>max-width:<?php echo $max_width;?>!important;<?php } ?><?php if (isset($max_height) && strlen($max_height) > 0) { ?>max-height:<?php echo $max_height;?>!important;overflow-y:auto!important;<?php } ?>">
79
  <div class="wp-google-list<?php if ($dark_theme) { ?> wp-dark<?php } ?>">
80
  <div class="wp-google-place">
81
- <?php grw_place($rating, $place, $reviews, $dark_theme); ?>
82
  </div>
83
  <div class="wp-google-content-inner">
84
  <?php grw_place_reviews($place, $reviews, $place_id, $text_size, $pagination); ?>
22
  $rating = round($rating / count($reviews), 1);
23
  }
24
  $rating = number_format((float)$rating, 1, '.', '');
25
+ $place_img = strlen($place_photo) > 0 ? $place_photo : (strlen($place->photo) > 0 ? $place->photo : $place->icon);
26
  ?>
27
 
28
  <?php if ($view_mode != 'list') { ?>
57
  <div class="wp-google-form" style="display:none">
58
  <div class="wp-google-head">
59
  <div class="wp-google-head-inner">
60
+ <?php grw_place($rating, $place, $place_img, $reviews, $dark_theme, false); ?>
61
  </div>
62
  <button class="wp-google-close" type="button" onclick="this.parentNode.parentNode.style.display='none'">×</button>
63
  </div>
79
  <div class="wp-gr wpac" style="<?php if (isset($max_width) && strlen($max_width) > 0) { ?>max-width:<?php echo $max_width;?>!important;<?php } ?><?php if (isset($max_height) && strlen($max_height) > 0) { ?>max-height:<?php echo $max_height;?>!important;overflow-y:auto!important;<?php } ?>">
80
  <div class="wp-google-list<?php if ($dark_theme) { ?> wp-dark<?php } ?>">
81
  <div class="wp-google-place">
82
+ <?php grw_place($rating, $place, $place_img, $reviews, $dark_theme); ?>
83
  </div>
84
  <div class="wp-google-content-inner">
85
  <?php grw_place_reviews($place, $reviews, $place_id, $text_size, $pagination); ?>
grw-setting.php CHANGED
@@ -110,8 +110,9 @@ if (isset($_POST['grw_active']) && isset($_GET['grw_active'])) {
110
 
111
  if (isset($_POST['grw_setting'])) {
112
  update_option('grw_language', $_POST['grw_language']);
 
113
 
114
- $grw_google_api_key = $_POST['grw_google_api_key'];
115
  if (strlen($grw_google_api_key) > 0) {
116
  $test_url = "https://maps.googleapis.com/maps/api/place/details/json?placeid=ChIJ3TH9CwFZwokRIvNO1SP0WLg&key=" . $grw_google_api_key;
117
  $test_response = rplg_urlopen($test_url);
@@ -121,7 +122,7 @@ if (isset($_POST['grw_setting'])) {
121
  $grw_google_api_key_error = $test_response_json->error_message;
122
  }
123
  update_option('grw_google_api_key', $grw_google_api_key);
124
- }
125
  $grw_setting_page = true;
126
  } else {
127
  $grw_setting_page = false;
@@ -248,7 +249,7 @@ $grw_language = get_option('grw_language');
248
  <form method="POST" enctype="multipart/form-data">
249
  <?php wp_nonce_field('grw-wpnonce_grw_settings', 'grw-form_nonce_grw_settings'); ?>
250
  <div class="form-group">
251
- <label class="control-label" for="grw_google_api_key"><?php echo grw_i('Google API Places Key'); ?></label>
252
  <input class="form-control" type="text" id="grw_google_api_key" name="grw_google_api_key" value="<?php echo esc_attr($grw_google_api_key); ?>">
253
  <?php if (isset($grw_google_api_key_error)) {?>
254
  <div class="alert alert-dismissible alert-danger">
@@ -257,10 +258,10 @@ $grw_language = get_option('grw_language');
257
  </div>
258
  <?php } ?>
259
  <small>
260
- Instruction to get Google Places API server key:<br>
261
- 1. Go to <a href="https://developers.google.com/places/web-service/get-api-key" target="_blank">Google Places API</a><br>
262
- 2. Click by 'GET A KEY' button<br>
263
- 3. Agree term and click by 'CREATE AND ENABLE API'<br>
264
  4. Copy key to plugin field<br>
265
  <iframe src="//www.youtube.com/embed/uW-PTKeZAXs?rel=0" allowfullscreen=""></iframe>
266
  </small>
110
 
111
  if (isset($_POST['grw_setting'])) {
112
  update_option('grw_language', $_POST['grw_language']);
113
+ update_option('grw_google_api_key', $_POST['grw_google_api_key']);
114
 
115
+ /*$grw_google_api_key = $_POST['grw_google_api_key'];
116
  if (strlen($grw_google_api_key) > 0) {
117
  $test_url = "https://maps.googleapis.com/maps/api/place/details/json?placeid=ChIJ3TH9CwFZwokRIvNO1SP0WLg&key=" . $grw_google_api_key;
118
  $test_response = rplg_urlopen($test_url);
122
  $grw_google_api_key_error = $test_response_json->error_message;
123
  }
124
  update_option('grw_google_api_key', $grw_google_api_key);
125
+ }*/
126
  $grw_setting_page = true;
127
  } else {
128
  $grw_setting_page = false;
249
  <form method="POST" enctype="multipart/form-data">
250
  <?php wp_nonce_field('grw-wpnonce_grw_settings', 'grw-form_nonce_grw_settings'); ?>
251
  <div class="form-group">
252
+ <label class="control-label" for="grw_google_api_key"><?php echo grw_i('Google Places API Key'); ?></label>
253
  <input class="form-control" type="text" id="grw_google_api_key" name="grw_google_api_key" value="<?php echo esc_attr($grw_google_api_key); ?>">
254
  <?php if (isset($grw_google_api_key_error)) {?>
255
  <div class="alert alert-dismissible alert-danger">
258
  </div>
259
  <?php } ?>
260
  <small>
261
+ <b>How to get Google Places API key</b>:<br>
262
+ 1. Go to <a href="https://developers.google.com/places/web-service/get-api-key#get_an_api_key" target="_blank">Google Places API Key</a><br>
263
+ 2. Click by '<b>GET A KEY</b>' button<br>
264
+ 3. Fill the name, agree term and click by '<b>NEXT</b>' button<br>
265
  4. Copy key to plugin field<br>
266
  <iframe src="//www.youtube.com/embed/uW-PTKeZAXs?rel=0" allowfullscreen=""></iframe>
267
  </small>
grw-widget.php CHANGED
@@ -18,6 +18,7 @@ class Goog_Reviews_Widget extends WP_Widget {
18
  'title' => '',
19
  'place_name' => '',
20
  'place_id' => '',
 
21
  'text_size' => '',
22
  'dark_theme' => '',
23
  'view_mode' => '',
@@ -143,17 +144,17 @@ class Goog_Reviews_Widget extends WP_Widget {
143
  <li>
144
  <span class="grw-step">1</span>
145
  <?php echo grw_i('Go to '); ?>
146
- <a href="https://developers.google.com/places/web-service/get-api-key" target="_blank">
147
  <?php echo grw_i('Google Places API Key'); ?>
148
  </a>
149
  </li>
150
  <li>
151
  <span class="grw-step">2</span>
152
- <?php echo grw_i('Find the topic \'<b>If you are using the standard Google Places API Web Service</b>\' and click by \'<b>GET A KEY</b>\' button'); ?>
153
  </li>
154
  <li>
155
  <span class="grw-step">3</span>
156
- <?php echo grw_i('Agree term and click by \'<b>CREATE AND ENABLE API</b>\''); ?>
157
  </li>
158
  <li>
159
  <span class="grw-step">4</span>
18
  'title' => '',
19
  'place_name' => '',
20
  'place_id' => '',
21
+ 'place_photo' => '',
22
  'text_size' => '',
23
  'dark_theme' => '',
24
  'view_mode' => '',
144
  <li>
145
  <span class="grw-step">1</span>
146
  <?php echo grw_i('Go to '); ?>
147
+ <a href="https://developers.google.com/places/web-service/get-api-key#get_an_api_key" target="_blank">
148
  <?php echo grw_i('Google Places API Key'); ?>
149
  </a>
150
  </li>
151
  <li>
152
  <span class="grw-step">2</span>
153
+ <?php echo grw_i('Click by \'<b>GET A KEY</b>\' button'); ?>
154
  </li>
155
  <li>
156
  <span class="grw-step">3</span>
157
+ <?php echo grw_i('Fill the name, agree term and click by \'<b>NEXT</b>\' button'); ?>
158
  </li>
159
  <li>
160
  <span class="grw-step">4</span>
grw.php CHANGED
@@ -4,7 +4,7 @@ Plugin Name: Google Reviews Widget
4
  Plugin URI: https://richplugins.com/google-reviews-pro-wordpress-plugin
5
  Description: Instantly Google Places Reviews on your website to increase user confidence and SEO.
6
  Author: RichPlugins <support@richplugins.com>
7
- Version: 1.6.2
8
  Author URI: https://richplugins.com
9
  */
10
 
@@ -13,7 +13,7 @@ require(ABSPATH . 'wp-includes/version.php');
13
  include_once(dirname(__FILE__) . '/api/urlopen.php');
14
  include_once(dirname(__FILE__) . '/helper/debug.php');
15
 
16
- define('GRW_VERSION', '1.6.2');
17
  define('GRW_GOOGLE_PLACE_API', 'https://maps.googleapis.com/maps/api/place/');
18
  define('GRW_GOOGLE_AVATAR', 'https://lh3.googleusercontent.com/-8hepWJzFXpE/AAAAAAAAAAI/AAAAAAAAAAA/I80WzYfIxCQ/s64-c/114307615494839964028.jpg');
19
  define('GRW_PLUGIN_URL', plugins_url(basename(plugin_dir_path(__FILE__ )), basename(__FILE__)));
@@ -289,13 +289,16 @@ function grw_request_handler() {
289
  $response_data = $response['data'];
290
  $response_json = rplg_json_decode($response_data);
291
 
292
- if ($response_json && $response_json->result) {
 
293
  grw_save_reviews($response_json->result);
 
294
  $status = 'success';
295
  } else {
 
296
  $status = 'failed';
297
  }
298
- $response = compact('status');
299
  }
300
  header('Content-type: text/javascript');
301
  echo json_encode($response);
@@ -314,14 +317,14 @@ function grw_save_reviews($place, $min_filter = 0) {
314
  if ($google_place_id) {
315
  $wpdb->update($wpdb->prefix . 'grp_google_place', array(
316
  'name' => $place->name,
317
- 'photo' => grw_business_avatar($place),
318
  'rating' => $place->rating
319
  ), array('ID' => $google_place_id));
320
  } else {
321
  $wpdb->insert($wpdb->prefix . 'grp_google_place', array(
322
  'place_id' => $place->place_id,
323
  'name' => $place->name,
324
- 'photo' => grw_business_avatar($place),
325
  'icon' => $place->icon,
326
  'address' => $place->formatted_address,
327
  'rating' => isset($place->rating) ? $place->rating : null,
4
  Plugin URI: https://richplugins.com/google-reviews-pro-wordpress-plugin
5
  Description: Instantly Google Places Reviews on your website to increase user confidence and SEO.
6
  Author: RichPlugins <support@richplugins.com>
7
+ Version: 1.6.3
8
  Author URI: https://richplugins.com
9
  */
10
 
13
  include_once(dirname(__FILE__) . '/api/urlopen.php');
14
  include_once(dirname(__FILE__) . '/helper/debug.php');
15
 
16
+ define('GRW_VERSION', '1.6.3');
17
  define('GRW_GOOGLE_PLACE_API', 'https://maps.googleapis.com/maps/api/place/');
18
  define('GRW_GOOGLE_AVATAR', 'https://lh3.googleusercontent.com/-8hepWJzFXpE/AAAAAAAAAAI/AAAAAAAAAAA/I80WzYfIxCQ/s64-c/114307615494839964028.jpg');
19
  define('GRW_PLUGIN_URL', plugins_url(basename(plugin_dir_path(__FILE__ )), basename(__FILE__)));
289
  $response_data = $response['data'];
290
  $response_json = rplg_json_decode($response_data);
291
 
292
+ if ($response_json && isset($response_json->result)) {
293
+ $response_json->result->business_photo = grw_business_avatar($response_json->result);
294
  grw_save_reviews($response_json->result);
295
+ $result = $response_json->result;
296
  $status = 'success';
297
  } else {
298
+ $result = $response_json;
299
  $status = 'failed';
300
  }
301
+ $response = compact('status', 'result');
302
  }
303
  header('Content-type: text/javascript');
304
  echo json_encode($response);
317
  if ($google_place_id) {
318
  $wpdb->update($wpdb->prefix . 'grp_google_place', array(
319
  'name' => $place->name,
320
+ 'photo' => $place->business_photo,
321
  'rating' => $place->rating
322
  ), array('ID' => $google_place_id));
323
  } else {
324
  $wpdb->insert($wpdb->prefix . 'grp_google_place', array(
325
  'place_id' => $place->place_id,
326
  'name' => $place->name,
327
+ 'photo' => $place->business_photo,
328
  'icon' => $place->icon,
329
  'address' => $place->formatted_address,
330
  'rating' => isset($place->rating) ? $place->rating : null,
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: https://richplugins.com/google-reviews-pro-wordpress-plugin
4
  Tags: google, reviews, google reviews, google places, google places reviews, testimonials, google review widget, google business reviews, slider, google review, review, google place review, google map reviews, google reviews pro, facebook reviews, facebook page reviews, yelp reviews, yelp business reviews
5
  Requires at least: 2.8
6
  Tested up to: 4.9
7
- Stable tag: 1.6.2
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -74,6 +74,10 @@ Why limit your reviews to just Google Reviews? Check out our other free business
74
 
75
  == Changelog ==
76
 
 
 
 
 
77
  = 1.6.2 =
78
  * Bugfix: remove deprecated function create_function()
79
 
4
  Tags: google, reviews, google reviews, google places, google places reviews, testimonials, google review widget, google business reviews, slider, google review, review, google place review, google map reviews, google reviews pro, facebook reviews, facebook page reviews, yelp reviews, yelp business reviews
5
  Requires at least: 2.8
6
  Tested up to: 4.9
7
+ Stable tag: 1.6.3
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
74
 
75
  == Changelog ==
76
 
77
+ = 1.6.3 =
78
+ * Important note: Google has changed the Places API and now this is limited to 1 request per day for new accounts, we have changed the plugin according to this limitation
79
+ * Improve: added feature to upload custom place photo
80
+
81
  = 1.6.2 =
82
  * Bugfix: remove deprecated function create_function()
83
 
static/css/rplg-wp.css CHANGED
@@ -228,6 +228,11 @@
228
  color: #444;
229
  }
230
 
 
 
 
 
 
231
  /*-------------------------------- yelp finder --------------------------------*/
232
  .yrw-step {
233
  display: inline-block;
228
  color: #444;
229
  }
230
 
231
+ .grw-error {
232
+ color: #e60909;
233
+ font-size: 13px;
234
+ }
235
+
236
  /*-------------------------------- yelp finder --------------------------------*/
237
  .yrw-step {
238
  display: inline-block;
static/js/grw-finder.js CHANGED
@@ -37,6 +37,65 @@ function grw_init(data) {
37
  return false;
38
  });
39
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
40
  grw_jquery_init(el, data.cb);
41
  }
42
 
@@ -159,6 +218,9 @@ function grw_jquery_init(el, cb) {
159
  place_photo_img.attr('src', attachment.url);
160
  place_photo_img.show();
161
 
 
 
 
162
  cb && cb();
163
  });
164
  file_frame.open();
37
  return false;
38
  });
39
 
40
+ var connectBtn = el.querySelector('.grw-connect-btn');
41
+ WPacFastjs.on(connectBtn, 'click', function() {
42
+
43
+ var placeIdEl = el.querySelector('.grw-place-id'),
44
+ placeId = placeIdEl.value;
45
+ if (!placeId) {
46
+ placeIdEl.focus();
47
+ return false;
48
+ }
49
+
50
+ var errorEl = el.querySelector('.grw-error');
51
+ if (/^ChIJ.*$/.test(placeId)) {
52
+ errorEl.innerHTML = '';
53
+ } else {
54
+ errorEl.innerHTML = 'Place ID is incorrect, it should like ChIJ...';
55
+ }
56
+
57
+ connectBtn.innerHTML = 'Please wait...';
58
+ connectBtn.disabled = true;
59
+
60
+ jQuery.post(grw_request_url('save'), {
61
+ placeid: placeId,
62
+ grw_wpnonce: jQuery('#grw_nonce').val()
63
+ }, function(res) {
64
+
65
+ console.log('grw_debug:', res);
66
+
67
+ connectBtn.innerHTML = 'Connect Google';
68
+ connectBtn.disabled = false;
69
+
70
+ if (res.status == 'success') {
71
+
72
+ errorEl.innerHTML = '';
73
+ el.querySelector('.grw-google-place-name').value = res.result.name;
74
+ el.querySelector('.grw-google-place-id').value = res.result.place_id;
75
+ el.querySelector('.grw-place-photo').value = res.result.business_photo || res.result.icon;
76
+
77
+ var img = el.querySelector('.grw-place-photo-img');
78
+ img.src = res.result.business_photo || res.result.icon;
79
+ img.style.display = '';
80
+
81
+ var controlEl = el.parentNode.parentNode.querySelector('.widget-control-actions');
82
+ if (controlEl) {
83
+ grw_show_tooltip(controlEl, 'Please don\'t forget to <b>Save</b> the widget.');
84
+ }
85
+
86
+ } else {
87
+
88
+ errorEl.innerHTML = '<b>Google error</b>: ' + res.result.error_message;
89
+ if (res.result.status == 'OVER_QUERY_LIMIT') {
90
+ errorEl.innerHTML += '<br><br>More recently, Google has limited the API to 1 request per day for new users, try to create new <a href="https://developers.google.com/places/web-service/get-api-key#get_an_api_key" target="_blank">Google API key</a>, save in the setting and Connect Google again.';
91
+ }
92
+
93
+ }
94
+
95
+ }, 'json');
96
+ return false;
97
+ });
98
+
99
  grw_jquery_init(el, data.cb);
100
  }
101
 
218
  place_photo_img.attr('src', attachment.url);
219
  place_photo_img.show();
220
 
221
+ // To make 'Save' button enable in the widget
222
+ jQuery(place_photo_hidden).change();
223
+
224
  cb && cb();
225
  });
226
  file_frame.open();