gmb_v2_upgrades

Upgrade from Google Reference ID to Places ID.

Description

gmb_v2_upgrades(); 

Usage

  1. if ( !function_exists( 'gmb_v2_upgrades' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'maps-builder/includes/admin/upgrades/upgrade-functions.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = gmb_v2_upgrades(); 
  7.  

Defined (2)

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

/includes/admin/upgrades/upgrade-functions.php  
  1. function gmb_v2_upgrades() { 
  2.  
  3. //Set key variables 
  4. $google_api_key = gmb_get_option( 'gmb_api_key' ); 
  5.  
  6. //Loop through maps 
  7. $args = array( 
  8. 'post_type' => 'google_maps',  
  9. 'posts_per_page' => - 1 
  10. ); 
  11.  
  12. // The Query 
  13. $the_query = new WP_Query( $args ); 
  14.  
  15. // The CPT Loop 
  16. if ( $the_query->have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post(); 
  17.  
  18. //Repeater markers data 
  19. $markers = get_post_meta( get_the_ID(), 'gmb_markers_group', true ); 
  20.  
  21. //If no markers skip 
  22. if ( ! empty( $markers ) ) { 
  23.  
  24. //Markers loop 
  25. foreach ( $markers as $key => $marker ) { 
  26.  
  27. $ref_id = isset( $marker['reference'] ) ? $marker['reference'] : ''; 
  28. $place_id = isset( $marker['place_id'] ) ? $marker['place_id'] : ''; 
  29.  
  30. //No ref ID -> skip; If place_id already there skip 
  31. if ( empty( $ref_id ) ) { 
  32. continue; 
  33. if ( ! empty( $place_id ) ) { 
  34. continue; 
  35. //cURL the Google API for the Google Place ID 
  36. $google_places_url = add_query_arg( 
  37. array( 
  38. 'reference' => $ref_id,  
  39. 'key' => $google_api_key 
  40. ),  
  41. 'https://maps.googleapis.com/maps/api/place/details/json' 
  42. ); 
  43.  
  44. $response = wp_remote_get( $google_places_url,  
  45. array( 
  46. 'timeout' => 15,  
  47. 'sslverify' => false 
  48. ); 
  49.  
  50. // make sure the response came back okay 
  51. if ( is_wp_error( $response ) ) { 
  52. return; 
  53.  
  54. // decode the license data 
  55. $response = json_decode( $response['body'], true ); 
  56.  
  57. //Place ID is there, now let's update the widget data 
  58. if ( isset( $response['result']['place_id'] ) ) { 
  59.  
  60. //Add Place ID to markers array 
  61. $markers[ $key ]['place_id'] = $response['result']['place_id']; 
  62.  
  63.  
  64. //Pause for 2 seconds so we don't overwhelm the Google API with requests 
  65. sleep( 2 ); 
  66.  
  67.  
  68. } //end foreach 
  69.  
  70. //Update repeater data with new data 
  71. update_post_meta( get_the_ID(), 'gmb_markers_group', $markers ); 
  72.  
  73. } //endif 
  74.  
  75. endwhile; endif; 
  76.  
  77. // Reset Post Data 
  78. wp_reset_postdata(); 
  79.  
  80. //Update our options and GTF out 
  81. update_option( 'gmb_refid_upgraded', 'upgraded' ); 
  82.  
/vendor/wordimpress/maps-builder-core/includes/admin/upgrades/upgrades.php  
  1. function gmb_v2_upgrades() { 
  2.  
  3. //Set key variables 
  4. $google_api_key = gmb_get_option( 'gmb_api_key' ); 
  5.  
  6. //Loop through maps 
  7. $args = array( 
  8. 'post_type' => 'google_maps',  
  9. 'posts_per_page' => - 1 
  10. ); 
  11.  
  12. // The Query 
  13. $the_query = new WP_Query( $args ); 
  14.  
  15. // The CPT Loop 
  16. if ( $the_query->have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post(); 
  17.  
  18. //Repeater markers data 
  19. $markers = get_post_meta( get_the_ID(), 'gmb_markers_group', true ); 
  20.  
  21. //If no markers skip 
  22. if ( ! empty( $markers ) ) { 
  23.  
  24. //Markers loop 
  25. foreach ( $markers as $key => $marker ) { 
  26.  
  27. $ref_id = isset( $marker['reference'] ) ? $marker['reference'] : ''; 
  28. $place_id = isset( $marker['place_id'] ) ? $marker['place_id'] : ''; 
  29.  
  30. //No ref ID -> skip; If place_id already there skip 
  31. if ( empty( $ref_id ) ) { 
  32. continue; 
  33. if ( ! empty( $place_id ) ) { 
  34. continue; 
  35. //cURL the Google API for the Google Place ID 
  36. $google_places_url = add_query_arg( 
  37. array( 
  38. 'reference' => $ref_id,  
  39. 'key' => $google_api_key 
  40. ),  
  41. 'https://maps.googleapis.com/maps/api/place/details/json' 
  42. ); 
  43.  
  44. $response = wp_remote_get( $google_places_url,  
  45. array( 
  46. 'timeout' => 15,  
  47. 'sslverify' => false 
  48. ); 
  49.  
  50. // make sure the response came back okay 
  51. if ( is_wp_error( $response ) ) { 
  52. return; 
  53.  
  54. // decode the license data 
  55. $response = json_decode( $response['body'], true ); 
  56.  
  57. //Place ID is there, now let's update the widget data 
  58. if ( isset( $response['result']['place_id'] ) ) { 
  59.  
  60. //Add Place ID to markers array 
  61. $markers[ $key ]['place_id'] = $response['result']['place_id']; 
  62.  
  63.  
  64. //Pause for 2 seconds so we don't overwhelm the Google API with requests 
  65. sleep( 2 ); 
  66.  
  67.  
  68. } //end foreach 
  69.  
  70. //Update repeater data with new data 
  71. update_post_meta( get_the_ID(), 'gmb_markers_group', $markers ); 
  72.  
  73. } //endif 
  74.  
  75. endwhile; endif; 
  76.  
  77. // Reset Post Data 
  78. wp_reset_postdata(); 
  79.  
  80. //Update our options and GTF out 
  81. gmb_set_upgrade_complete( 'gmb_refid_upgraded' ); 
  82. update_option( 'gmb_refid_upgraded', 'upgraded' ); 
  83.