gpr_v13_upgrades

Upgrade from Google Reference ID to Places ID.

Description

gpr_v13_upgrades(); 

Usage

  1. if ( !function_exists( 'gpr_v13_upgrades' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'google-places-reviews/inc/upgrades/upgrade-functions.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = gpr_v13_upgrades(); 
  7.  

Defined (1)

The function is defined in the following location(s).

/inc/upgrades/upgrade-functions.php  
  1. function gpr_v13_upgrades() { 
  2.  
  3. //Upgrade the Reference ID 
  4. $gpr_widget_options = get_option( 'widget_gpr_widget' ); 
  5. $plugin_options = get_option( 'googleplacesreviews_options' ); 
  6. $google_api_key = $plugin_options['google_places_api_key']; 
  7.  
  8. //Loop through widgets' options 
  9. foreach ( $gpr_widget_options as $key => $widget ) { 
  10.  
  11. $ref_id = isset( $widget['reference'] ) ? $widget['reference'] : ''; 
  12. $place_id = isset( $widget['place_id'] ) ? $widget['place_id'] : ''; 
  13.  
  14. //If no place AND there's a ref ID proceed 
  15. if ( empty( $place_id ) && ! empty( $ref_id ) ) { 
  16.  
  17. //cURL the Google API for the Google Place ID 
  18. $google_places_url = add_query_arg( 
  19. array( 
  20. 'reference' => $ref_id,  
  21. 'key' => $google_api_key 
  22. ),  
  23. 'https://maps.googleapis.com/maps/api/place/details/json' 
  24. ); 
  25.  
  26. $response = wp_remote_get( $google_places_url,  
  27. array( 
  28. 'timeout' => 15,  
  29. 'sslverify' => false 
  30. ) ); 
  31.  
  32. // make sure the response came back okay 
  33. if ( is_wp_error( $response ) ) { 
  34. return; 
  35.  
  36. // decode the license data 
  37. $response = json_decode( $response['body'], true ); 
  38.  
  39. //Place ID is there, now let's update the widget data 
  40. if ( isset( $response['result']['place_id'] ) ) { 
  41.  
  42. //Add Place ID to GPR widgets options array 
  43. $gpr_widget_options[ $key ]['place_id'] = $response['result']['place_id']; 
  44.  
  45.  
  46.  
  47. //Pause for 3 seconds so we don't overwhelm the Google API with requests 
  48. sleep( 2 ); 
  49.  
  50. //Update our options and GTF out 
  51. update_option( 'gpr_refid_upgraded', 'upgraded' ); 
  52. update_option( 'widget_gpr_widget', $gpr_widget_options ); 
  53.