gmb_v21_marker_upgrades

Upgrade Marker Paths.

Description

gmb_v21_marker_upgrades(); 

Marker paths were hard coded into the db causing issues when structures change.


Usage

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

Defined (1)

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

/vendor/wordimpress/maps-builder-core/includes/admin/upgrades/upgrades.php  
  1. function gmb_v21_marker_upgrades() { 
  2.  
  3. //Loop through maps 
  4. $args = array( 
  5. 'post_type' => 'google_maps',  
  6. 'posts_per_page' => - 1 
  7. ); 
  8.  
  9. // The Query 
  10. $the_query = new WP_Query( $args ); 
  11.  
  12. // The CPT Loop 
  13. if ( $the_query->have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post(); 
  14.  
  15. /** 
  16. * Individual Markers 
  17. */ 
  18. $markers = get_post_meta( get_the_ID(), 'gmb_markers_group', true ); 
  19.  
  20. //If no markers skip 
  21. if ( ! empty( $markers ) ) { 
  22.  
  23. //Markers loop 
  24. foreach ( $markers as $key => $marker ) { 
  25.  
  26. //Conditional: 
  27. //a) check for a marker image 
  28. if ( isset( $marker['marker_img'] ) && ! empty( $marker['marker_img'] ) && 
  29.  
  30. // AND b) If this marker has an included 
  31. // image associate with it that has not been uploaded 
  32. ( isset( $marker['marker_img_id'] ) && empty( $marker['marker_img_id'] ) || 
  33. strpos( $marker['marker_img'], GMB_PLUGIN_URL ) !== false ) 
  34. ) { 
  35.  
  36. $new_marker_path = str_replace( GMB_PLUGIN_URL, '', $marker['marker_img'] ); 
  37. $markers[ $key ]['marker_included_img'] = $new_marker_path; 
  38.  
  39. //Save default markers into a new meta option without full path 
  40. unset( $markers[ $key ]['marker_img'] ); 
  41. unset( $markers[ $key ]['marker_img_id'] ); 
  42. unset( $markers[ $key ]['marker'] ); 
  43. } else { 
  44. //This is an uploaded marker 
  45. unset( $markers[ $key ]['marker_included_img'] ); 
  46.  
  47.  
  48.  
  49. //Update repeater data with new data 
  50. update_post_meta( get_the_ID(), 'gmb_markers_group', $markers ); 
  51.  
  52. /** 
  53. * Mashups 
  54. */ 
  55. $mashup_markers = get_post_meta( get_the_ID(), 'gmb_mashup_group', true ); 
  56.  
  57. //If no $mashup_markers skip 
  58. if ( ! empty( $mashup_markers ) ) { 
  59.  
  60. //Markers loop 
  61. foreach ( $mashup_markers as $key => $marker ) { 
  62.  
  63. //Conditional: 
  64. //a) check for a marker image 
  65. if ( isset( $marker['marker_img'] ) && ! empty( $marker['marker_img'] ) && 
  66.  
  67. // AND b) If this marker has an included 
  68. // image associate with it that has not been uploaded 
  69. ( isset( $marker['marker_img_id'] ) && empty( $marker['marker_img_id'] ) || 
  70. strpos( $marker['marker_img'], GMB_PLUGIN_URL ) !== false ) 
  71. ) { 
  72.  
  73. $new_marker_path = str_replace( GMB_PLUGIN_URL, '', $marker['marker_img'] ); 
  74. $mashup_markers[ $key ]['marker_included_img'] = $new_marker_path; 
  75.  
  76. //Save default markers into a new meta option without full path 
  77. unset( $mashup_markers[ $key ]['marker_img'] ); 
  78. unset( $mashup_markers[ $key ]['marker_img_id'] ); 
  79. unset( $mashup_markers[ $key ]['marker'] ); 
  80. } else { 
  81. //This is an uploaded marker 
  82. unset( $mashup_markers[ $key ]['marker_included_img'] ); 
  83.  
  84.  
  85. //Update repeater data with new data 
  86. update_post_meta( get_the_ID(), 'gmb_mashup_group', $mashup_markers ); 
  87.  
  88.  
  89. endwhile; endif; 
  90.  
  91. // Reset Post Data 
  92. wp_reset_postdata(); 
  93.  
  94. //Update our options and GTF out 
  95. gmb_set_upgrade_complete( 'gmb_markers_upgraded' ); 
  96.