PluginProbe
Property Hive / 2.3.1
Property Hive v2.3.1
2.3.1 2.3.0 2.2.6 2.2.5 2.2.4 2.2.3 2.2.2 1.4.46 1.4.47 1.4.48 1.4.49 1.4.5 1.4.50 1.4.51 1.4.52 1.4.53 1.4.54 1.4.55 1.4.56 1.4.57 1.4.58 1.4.59 1.4.6 1.4.60 1.4.61 All 261 releases
← All changes | includes/ph-property-functions.php +766 -72 1.4.62.3.1 View file →
@@ -1,5 +1,10 @@
1 1 <?php
2 +
3 +if ( ! defined( 'ABSPATH' ) ) {
4 + exit;
5 +}
6 +
2 7 /**
3 8 * PropertyHive Property Functions
4 9 *
5 10 * Functions for property specific things.
@@ -16,8 +21,9 @@
16 21 * @param mixed $the_property Post object or post ID of the property.
17 22 * @param array $args (default: array()) Contains all arguments to be used to get this property.
18 23 * @return PH_Property
19 24 */
25 +// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound -- Legacy public global helper get_property; the established callable name is part of the plugin/extension API and must remain stable.
20 26 function get_property( $the_property = false, $args = array() ) {
21 27 return new PH_Property( $the_property );
22 28 }
23 29
@@ -26,8 +32,9 @@
26 32 *
27 33 * @access public
28 34 * @return array
29 35 */
36 +// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound -- Legacy public global helper ph_get_featured_property_ids; the established callable name is part of the plugin/extension API and must remain stable.
30 37 function ph_get_featured_property_ids() {
31 38
32 39 // Load from cache
33 40 $featured_property_ids = get_transient( 'ph_featured_properties' );
@@ -39,15 +46,16 @@
39 46 $featured = get_posts( array(
40 47 'post_type' => 'property',
41 48 'posts_per_page' => -1,
42 49 'post_status' => 'publish',
50 + // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query -- Featured/on-market flags use existing property metadata; all matching IDs are cached in the existing transient.
43 51 'meta_query' => array(
44 52 array(
45 - 'key' => 'on_market',
46 - 'value' => 'yes'
47 - ),
53 + 'key' => '_on_market',
54 + 'value' => 'yes'
55 + ),
48 56 array(
49 - 'key' => 'featured',
57 + 'key' => '_featured',
50 58 'value' => 'yes'
51 59 )
52 60 ),
53 61 'fields' => 'id=>parent'
@@ -52,9 +60,9 @@
52 60 ),
53 61 'fields' => 'id=>parent'
54 62 ) );
55 63
56 - $featured_property_ids = array_keys( $property_ids );
64 + $featured_property_ids = array_keys( $featured );
57 65
58 66 set_transient( 'ph_featured_properties', $featured_property_ids, YEAR_IN_SECONDS );
59 67
60 68 return $featured_property_ids;
@@ -65,8 +73,9 @@
65 73 *
66 74 * @access public
67 75 * @return string
68 76 */
77 +// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound -- Legacy public global helper ph_placeholder_img_src; the established callable name is part of the plugin/extension API and must remain stable.
69 78 function ph_placeholder_img_src() {
70 79 return apply_filters( 'propertyhive_placeholder_img_src', PH()->plugin_url() . '/assets/images/placeholder.png' );
71 80 }
72 81
@@ -75,17 +84,19 @@
75 84 *
76 85 * @access public
77 86 * @return string
78 87 */
88 +// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound -- Legacy public global helper ph_placeholder_img; the established callable name is part of the plugin/extension API and must remain stable.
79 89 function ph_placeholder_img( $size = 'thumbnail' ) {
80 90 $dimensions = ph_get_image_size( $size );
81 91
82 - return apply_filters('propertyhive_placeholder_img', '<img src="' . ph_placeholder_img_src() . '" alt="Placeholder" width="' . esc_attr( $dimensions['width'] ) . '" class="property-placeholder wp-post-image" height="' . esc_attr( $dimensions['height'] ) . '" />' );
92 + return apply_filters('propertyhive_placeholder_img', '<img src="' . esc_url( ph_placeholder_img_src() ) . '" alt="Placeholder" width="' . esc_attr( $dimensions['width'] ) . '" class="property-placeholder wp-post-image" height="' . esc_attr( $dimensions['height'] ) . '" />' );
83 93 }
84 94
85 95 /**
86 96 * Track property views
87 97 */
98 +// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound -- Legacy public global helper ph_track_property_view; the established callable name is part of the plugin/extension API and must remain stable.
88 99 function ph_track_property_view() {
89 100 if ( ! is_singular( 'property' ) )
90 101 return;
91 102
@@ -93,18 +104,22 @@
93 104
94 105 // Track in cookie
95 106 if ( apply_filters( 'propertyhive_store_in_recently_viewed_cookie', true ) )
96 107 {
97 - if ( empty( $_COOKIE['propertyhive_recently_viewed'] ) )
98 - $viewed_properties = array();
99 - else
100 - $viewed_properties = (array) explode( '|', $_COOKIE['propertyhive_recently_viewed'] );
108 + $viewed_properties = array();
109 + $viewed_cookie = isset( $_COOKIE['propertyhive_recently_viewed'] ) && is_string( $_COOKIE['propertyhive_recently_viewed'] ) ? sanitize_text_field( wp_unslash( $_COOKIE['propertyhive_recently_viewed'] ) ) : '';
110 + foreach ( explode( '|', $viewed_cookie ) as $viewed_id ) {
111 + if ( ctype_digit( $viewed_id ) && absint( $viewed_id ) > 0 ) {
112 + $viewed_properties[] = absint( $viewed_id );
113 + }
114 + }
115 + $viewed_properties = array_values( array_unique( $viewed_properties ) );
101 116
102 117 if ( ! in_array( $post->ID, $viewed_properties ) )
103 118 $viewed_properties[] = $post->ID;
104 119
105 - if ( sizeof( $viewed_properties ) > 15 )
106 - array_shift( $viewed_properties );
120 + if ( count( $viewed_properties ) > 15 )
121 + $viewed_properties = array_slice( $viewed_properties, -15 );
107 122
108 123 // Store for session only
109 124 ph_setcookie( 'propertyhive_recently_viewed', implode( '|', $viewed_properties ) );
110 125 }
@@ -120,14 +135,14 @@
120 135 {
121 136 $view_counts = array();
122 137 }
123 138
124 - if ( !isset($view_counts[date("Y-m-d")]) )
139 + if ( !isset($view_counts[gmdate("Y-m-d")]) )
125 140 {
126 - $view_counts[date("Y-m-d")] = 0;
141 + $view_counts[gmdate("Y-m-d")] = 0;
127 142 }
128 143
129 - ++$view_counts[date("Y-m-d")];
144 + ++$view_counts[gmdate("Y-m-d")];
130 145
131 146 update_post_meta( $post->ID, '_view_statistics', $view_counts );
132 147 }
133 148 }
@@ -133,8 +148,9 @@
133 148 }
134 149
135 150 add_action( 'template_redirect', 'ph_track_property_view', 20 );
136 151
152 +// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound -- Legacy public global helper get_property_map; the established callable name is part of the plugin/extension API and must remain stable.
137 153 function get_property_map( $args = array() )
138 154 {
139 155 global $property;
140 156
@@ -139,25 +155,247 @@
139 155 global $property;
140 156
141 157 if ( $property->latitude != '' && $property->latitude != '0' && $property->longitude != '' && $property->longitude != '0' )
142 158 {
143 - $api_key = get_option('propertyhive_google_maps_api_key');
144 - wp_register_script('googlemaps', '//maps.googleapis.com/maps/api/js?' . ( ( $api_key != '' && $api_key !== FALSE ) ? 'key=' . $api_key : '' ), false, '3');
145 - wp_enqueue_script('googlemaps');
159 + $id_suffix = ( ( isset($args['id']) && $args['id'] != '' ) ? '_' . $args['id'] : '' );
146 160
147 - echo '<div id="property_map_canvas" style="height:' . str_replace( "px", "", ( ( isset($args['height']) && !empty($args['height']) ) ? $args['height'] : '400' ) ) . 'px"></div>';
161 + if ( get_option('propertyhive_maps_provider') == 'mapbox' )
162 + {
163 + echo '<div id="property_map_canvas' . esc_attr($id_suffix) . '" style="background:#EEE; height:' . esc_attr( ( ( isset($args['height']) && !empty($args['height']) && is_numeric($args['height']) ) ? (int)$args['height'] : 400 ) ) . 'px"></div>';
164 +
165 + $assets_path = str_replace( array( 'http:', 'https:' ), '', PH()->plugin_url() ) . '/assets/js/mapbox/';
166 +
167 + wp_register_style('mapbox', $assets_path . 'mapbox-gl.css', array(), '3.8.0');
168 + wp_enqueue_style('mapbox');
169 +
170 + wp_register_script('mapbox', $assets_path . 'mapbox-gl.js', array(), '3.8.0', false);
171 + wp_enqueue_script('mapbox');
148 172 ?>
149 173 <script>
150 174
151 - // We declare vars globally so developers can access them
152 - var property_map; // Global declaration of the map
153 - var property_marker; // Global declaration of the marker
175 + var property_map<?php echo esc_js($id_suffix); ?>;
176 +
177 + function initialize_property_map<?php echo esc_js($id_suffix); ?>()
178 + {
179 + if ( property_map<?php echo esc_js($id_suffix); ?> != undefined ) { property_map<?php echo esc_js($id_suffix); ?>.remove(); }
180 +
181 + mapboxgl.accessToken = '<?php echo esc_js(get_option( 'propertyhive_mapbox_api_key', '' )); ?>';
182 + property_map<?php echo esc_js($id_suffix); ?> = new mapboxgl.Map({
183 + container: "property_map_canvas<?php echo esc_js($id_suffix); ?>", // container ID
184 + center: [<?php echo (float)$property->longitude; ?>, <?php echo (float)$property->latitude; ?>], // starting position [lng, lat]. Note that lat must be set between -90 and 90
185 + zoom: <?php echo ( ( isset($args['zoom']) && !empty($args['zoom']) ) ? (int)$args['zoom'] : '14' ); ?> // starting zoom
186 + });
187 +
188 + <?php
189 + $marker_set = false;
190 + if ( class_exists( 'PH_Map_Search' ) )
191 + {
192 + $map_add_on_settings = get_option( 'propertyhive_map_search', array() );
193 +
194 + if ( isset($map_add_on_settings['icon_type']) && $map_add_on_settings['icon_type'] == 'custom_single' && isset($map_add_on_settings['custom_icon_attachment_id']) && $map_add_on_settings['custom_icon_attachment_id'] != '' )
195 + {
196 + $marker_icon_url = wp_get_attachment_url( $map_add_on_settings['custom_icon_attachment_id'] );
197 + if ( $marker_icon_url !== FALSE )
198 + {
199 + $size = getimagesize( get_attached_file( $map_add_on_settings['custom_icon_attachment_id'] ) );
200 + if ( $size !== FALSE && !empty($size) )
201 + {
202 + $icon_anchor_width = $size[0];
203 + $icon_anchor_height = $size[1];
204 +
205 + /*if (isset($map_add_on_settings['custom_icon_anchor_position']) && $map_add_on_settings['custom_icon_anchor_position'] == 'center')
206 + {
207 + $icon_anchor_width = floor($size[0] / 2);
208 + $icon_anchor_height = floor($size[1] / 2);
209 + }
210 + else
211 + {
212 + $icon_anchor_width = floor($size[0] / 2);
213 + $icon_anchor_height = $size[1];
214 + }*/
215 + ?>
216 + const el = document.createElement('div');
217 + el.className = 'marker';
218 + el.style.backgroundImage = 'url(<?php echo esc_url($marker_icon_url); ?>)';
219 + el.style.width = '<?php echo (int)$icon_anchor_width; ?>px';
220 + el.style.height = '<?php echo (int)$icon_anchor_height; ?>px';
221 + el.style.backgroundSize = '100%';
222 +
223 + new mapboxgl.Marker(el, {<?php if (isset($map_add_on_settings['custom_icon_anchor_position']) && $map_add_on_settings['custom_icon_anchor_position'] == 'center') { echo 'anchor:\'center\''; }else{ echo 'anchor:\'bottom\''; } ?>})
224 + .setLngLat([<?php echo (float)$property->longitude; ?>, <?php echo (float)$property->latitude; ?>])
225 + .addTo(property_map<?php echo esc_js($id_suffix); ?>);
226 + <?php
227 + $marker_set = true;
228 + }
229 + }
230 + }
231 + }
232 + if ( !$marker_set )
233 + {
234 + ?>
235 + marker = new mapboxgl.Marker({
236 + //color: "#FFFFFF",
237 + draggable: false
238 + }).setLngLat([<?php echo (float)$property->longitude; ?>, <?php echo (float)$property->latitude; ?>])
239 + .addTo(property_map<?php echo esc_js($id_suffix); ?>);
240 + <?php
241 + }
242 + do_action( 'propertyhive_property_map_actions', $property, $args, $id_suffix );
243 + ?>
244 +
245 + }
246 +
247 + <?php if ( !isset($args['init_on_load']) || ( isset($args['init_on_load']) && ($args['init_on_load'] === 'true' || $args['init_on_load'] === TRUE) ) ) { ?>
248 + if (window.addEventListener) {
249 + window.addEventListener('load', initialize_property_map<?php echo esc_js($id_suffix); ?>);
250 + }else{
251 + window.attachEvent('onload', initialize_property_map<?php echo esc_js($id_suffix); ?>);
252 + }
253 + <?php } ?>
254 +
255 +</script>
256 +<?php
257 + }
258 + elseif ( get_option('propertyhive_maps_provider') == 'osm' )
259 + {
260 + echo '<div id="property_map_canvas' . esc_attr($id_suffix) . '" style="background:#EEE; height:' . esc_attr( ( ( isset($args['height']) && !empty($args['height']) && is_numeric($args['height']) ) ? (int)$args['height'] : 400 ) ) . 'px"></div>';
261 +
262 + $assets_path = str_replace( array( 'http:', 'https:' ), '', PH()->plugin_url() ) . '/assets/js/leaflet/';
263 +
264 + wp_register_style('leaflet', $assets_path . 'leaflet.css', array(), '1.9.4');
265 + wp_enqueue_style('leaflet');
266 +
267 + wp_register_script('leaflet', $assets_path . 'leaflet.js', array(), '1.9.4', false);
268 + wp_enqueue_script('leaflet');
269 +?>
270 +<script>
271 +
272 + var property_map<?php echo esc_js($id_suffix); ?>;
273 +
274 + function initialize_property_map<?php echo esc_js($id_suffix); ?>()
275 + {
276 + if ( property_map<?php echo esc_js($id_suffix); ?> != undefined ) { property_map<?php echo esc_js($id_suffix); ?>.remove(); }
277 +
278 + L.Icon.Default.imagePath = '<?php echo esc_url($assets_path); ?>/images/';
279 +
280 + property_map<?php echo esc_js($id_suffix); ?> = L.map("property_map_canvas<?php echo esc_js($id_suffix); ?>"<?php echo ( ( isset($args['scrollwheel']) && ($args['scrollwheel'] === 'false' || $args['scrollwheel'] === FALSE) ) ? ', { scrollWheelZoom: false, dragging: !L.Browser.mobile }' : '' ); ?>).setView([<?php echo (float)$property->latitude; ?>, <?php echo (float)$property->longitude; ?>], <?php echo ( ( isset($args['zoom']) && !empty($args['zoom']) ) ? (int)$args['zoom'] : '14' ); ?>);
281 +
282 + L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
283 + attribution: '&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
284 + }).addTo(property_map<?php echo esc_js($id_suffix); ?>);
285 +
286 + <?php
287 + $icon_code = '';
288 + if ( class_exists( 'PH_Map_Search' ) )
289 + {
290 + $map_add_on_settings = get_option( 'propertyhive_map_search', array() );
291 +
292 + if ( isset($map_add_on_settings['icon_type']) && $map_add_on_settings['icon_type'] == 'custom_single' && isset($map_add_on_settings['custom_icon_attachment_id']) && $map_add_on_settings['custom_icon_attachment_id'] != '' )
293 + {
294 + $marker_icon_url = wp_get_attachment_url( $map_add_on_settings['custom_icon_attachment_id'] );
295 + if ( $marker_icon_url !== FALSE )
296 + {
297 + ?>
298 + var icon_options = { iconUrl: '<?php echo esc_url($marker_icon_url); ?>' }
299 + <?php
300 + $icon_width = '';
301 + $icon_height = '';
302 +
303 + $icon_anchor_width = '';
304 + $icon_anchor_height = '';
305 +
306 + $size = getimagesize( get_attached_file( $map_add_on_settings['custom_icon_attachment_id'] ) );
307 + if ( $size !== FALSE && !empty($size) )
308 + {
309 + $icon_width = (int)$size[0];
310 + $icon_height = (int)$size[1];
311 +
312 + if (isset($map_add_on_settings['custom_icon_anchor_position']) && $map_add_on_settings['custom_icon_anchor_position'] == 'center')
313 + {
314 + $icon_anchor_width = floor($size[0] / 2);
315 + $icon_anchor_height = floor($size[1] / 2);
316 + }
317 + else
318 + {
319 + $icon_anchor_width = floor($size[0] / 2);
320 + $icon_anchor_height = $size[1];
321 + }
322 + }
323 +
324 + $icon_width = apply_filters( 'propertyhive_property_map_osm_icon_width', $icon_width );
325 + $icon_height = apply_filters( 'propertyhive_property_map_osm_icon_height', $icon_height );
326 +
327 + $icon_anchor_width = apply_filters( 'propertyhive_property_map_osm_icon_anchor_width', $icon_anchor_width );
328 + $icon_anchor_height = apply_filters( 'propertyhive_property_map_osm_icon_anchor_height', $icon_anchor_height );
329 +
330 + if ( !empty($icon_width) && !empty($icon_height) )
331 + {
332 + ?>
333 + icon_options.iconSize = [<?php echo (int)$icon_width; ?>, <?php echo (int)$icon_height; ?>];
334 + <?php
335 + }
336 + if ( $icon_anchor_width != '' && $icon_anchor_height != '' )
337 + {
338 + ?>
339 + icon_options.iconAnchor = [<?php echo (int)$icon_anchor_width; ?>, <?php echo (int)$icon_anchor_height; ?>];
340 + <?php
341 + }
342 + ?>
343 + var custom_icon = L.icon(icon_options);
344 + <?php
345 + $icon_code = ', { icon: custom_icon }';
346 + }
347 + }
348 + }
349 + do_action( 'propertyhive_property_map_actions', $property, $args, $id_suffix );
350 + ?>
351 +
352 + L.marker([<?php echo (float)$property->latitude; ?>, <?php echo (float)$property->longitude; ?>]<?php echo $icon_code === ', { icon: custom_icon }' ? ', { icon: custom_icon }' : ''; ?>).addTo(property_map<?php echo esc_js($id_suffix); ?>);
353 + }
354 +
355 + <?php if ( !isset($args['init_on_load']) || ( isset($args['init_on_load']) && ($args['init_on_load'] === 'true' || $args['init_on_load'] === TRUE) ) ) { ?>
356 + if (window.addEventListener) {
357 + window.addEventListener('load', initialize_property_map<?php echo esc_js($id_suffix); ?>);
358 + }else{
359 + window.attachEvent('onload', initialize_property_map<?php echo esc_js($id_suffix); ?>);
360 + }
361 + <?php } ?>
362 +
363 +</script>
364 +<?php
365 + }
366 + else
367 + {
368 + $api_key = get_option('propertyhive_google_maps_api_key');
369 + if ( isset($args['embed']) && ($args['embed'] === 'true' || $args['embed'] === TRUE) )
370 + {
371 + echo '<iframe
372 + width="100%"
373 + height="' . ( ( isset($args['height']) && !empty($args['height']) && is_numeric($args['height']) ) ? (int)$args['height'] : 400 ) . '"
374 + style="border:0"
375 + loading="lazy"
376 + allowfullscreen
377 + referrerpolicy="no-referrer-when-downgrade"
378 + src="' . esc_url( 'https://www.google.com/maps/embed/v1/place?key=' . $api_key . '&q=' . $property->latitude . ',' . $property->longitude ) . '">
379 + </iframe>';
380 + }
381 + else
382 + {
383 + echo '<div id="property_map_canvas' . esc_attr($id_suffix) . '" style="background:#EEE; height:' . esc_attr( ( ( isset($args['height']) && !empty($args['height']) && is_numeric($args['height']) ) ? (int)$args['height'] : 400 ) ) . 'px"></div>';
384 +
385 + wp_register_script('googlemaps', '//maps.googleapis.com/maps/api/js?' . ( ( $api_key != '' && $api_key !== FALSE ) ? 'key=' . $api_key : '' ), false, '3', true );
386 + wp_enqueue_script('googlemaps');
387 +?>
388 +<script>
389 +
390 + var property_map<?php echo esc_js($id_suffix); ?>;
391 + var property_marker<?php echo esc_js($id_suffix); ?>;
154 392
155 - function initialize_property_map() {
393 + function initialize_property_map<?php echo esc_js($id_suffix); ?>() {
156 394
157 - var myLatlng = new google.maps.LatLng(<?php echo $property->latitude; ?>, <?php echo $property->longitude; ?>);
395 + var myLatlng = new google.maps.LatLng(<?php echo (float)$property->latitude; ?>, <?php echo (float)$property->longitude; ?>);
158 396 var map_options = {
159 - zoom: <?php echo ( ( isset($args['zoom']) && !empty($args['zoom']) ) ? $args['zoom'] : '14' ); ?>,
397 + zoom: <?php echo ( ( isset($args['zoom']) && !empty($args['zoom']) ) ? (int)$args['zoom'] : '14' ); ?>,
160 398 center: myLatlng,
161 399 mapTypeId: google.maps.MapTypeId.ROADMAP,
162 400 scrollwheel: <?php echo ( ( isset($args['scrollwheel']) && ($args['scrollwheel'] === 'false' || $args['scrollwheel'] === FALSE) ) ? 'false' : 'true' ); ?>
163 401 }
@@ -165,95 +403,527 @@
165 403 if ( class_exists( 'PH_Map_Search' ) )
166 404 {
167 405 $map_add_on_settings = get_option( 'propertyhive_map_search', array() );
168 406
169 - if ( isset($map_add_on_settings['style_js']) && trim($map_add_on_settings['style_js']) != '' )
407 + if ( isset($map_add_on_settings['style_js']) && is_string($map_add_on_settings['style_js']) && trim($map_add_on_settings['style_js']) != '' )
170 408 {
171 - echo 'map_options.styles = ' . trim($map_add_on_settings['style_js']) . ';';
409 + // Google Maps styles are JSON arrays, including legacy Snazzy Maps style properties.
410 + $map_styles = json_decode( $map_add_on_settings['style_js'] );
411 + if ( is_array( $map_styles ) ) {
412 + echo 'map_options.styles = ' . wp_json_encode( $map_styles, JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_APOS | JSON_HEX_QUOT ) . ';';
413 + }
172 414 }
173 415 }
174 416
175 - do_action( 'propertyhive_property_map_options' );
417 + do_action( 'propertyhive_property_map_options', $property, $args, $id_suffix );
176 418 ?>
177 - property_map = new google.maps.Map(document.getElementById("property_map_canvas"), map_options);
419 + property_map<?php echo esc_js($id_suffix); ?> = new google.maps.Map(document.getElementById("property_map_canvas<?php echo esc_js($id_suffix); ?>"), map_options);
178 420
179 - var myLatlng = new google.maps.LatLng(<?php echo $property->latitude; ?>, <?php echo $property->longitude; ?>);
421 + var myLatlng = new google.maps.LatLng(<?php echo (float)$property->latitude; ?>, <?php echo (float)$property->longitude; ?>);
180 422
181 423 var marker_options = {
182 - map: property_map,
424 + map: property_map<?php echo esc_js($id_suffix); ?>,
183 425 position: myLatlng
184 426 };
185 427
428 + <?php
429 + if ( class_exists( 'PH_Map_Search' ) )
430 + {
431 + $map_add_on_settings = get_option( 'propertyhive_map_search', array() );
432 +
433 + if ( isset($map_add_on_settings['icon_type']) && $map_add_on_settings['icon_type'] == 'custom_single' && isset($map_add_on_settings['custom_icon_attachment_id']) && $map_add_on_settings['custom_icon_attachment_id'] != '' )
434 + {
435 + $marker_icon_url = wp_get_attachment_url( $map_add_on_settings['custom_icon_attachment_id'] );
436 + if ( $marker_icon_url !== FALSE )
437 + {
438 + echo 'var ph_map_icon = {
439 + url: \'' . esc_url($marker_icon_url) . '\'';
440 + if ( isset($map_add_on_settings['custom_icon_anchor_position']) && $map_add_on_settings['custom_icon_anchor_position'] == 'center' )
441 + {
442 + $size = getimagesize( get_attached_file( $map_add_on_settings['custom_icon_attachment_id'] ) );
443 + if ( $size !== FALSE && !empty($size) )
444 + {
445 + echo ', anchor: new google.maps.Point(' . (int) floor( (int)$size[0] / 2 ) . ', ' . (int) floor( (int)$size[1] / 2 ) . ')';
446 + }
447 + }
448 + echo '};';
449 + echo 'marker_options.icon = ph_map_icon;';
450 + }
451 + }
452 + }
453 + ?>
454 +
186 455 <?php do_action( 'propertyhive_property_map_marker_options' ); ?>
187 456
188 - property_marker = new google.maps.Marker(marker_options);
457 + property_marker<?php echo esc_js($id_suffix); ?> = new google.maps.Marker(marker_options);
458 +
459 + <?php do_action( 'propertyhive_property_map_actions' ); ?>
189 460 }
190 461
462 + <?php if ( !isset($args['init_on_load']) || ( isset($args['init_on_load']) && ($args['init_on_load'] === 'true' || $args['init_on_load'] === TRUE) ) ) { ?>
191 463 if(window.addEventListener) {
192 - window.addEventListener('load', initialize_property_map);
464 + window.addEventListener('load', initialize_property_map<?php echo esc_js($id_suffix); ?>);
193 465 }else{
194 - window.attachEvent('onload', initialize_property_map);
466 + window.attachEvent('onload', initialize_property_map<?php echo esc_js($id_suffix); ?>);
195 467 }
468 + <?php } ?>
196 469
197 470 </script>
198 471 <?php
472 + }
473 + }
474 + do_action( 'propertyhive_property_map_after' );
199 475 }
200 476 }
201 477
478 +// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound -- Legacy public global helper get_property_static_map; the established callable name is part of the plugin/extension API and must remain stable.
479 +function get_property_static_map( $args = array() )
480 +{
481 + global $property;
482 +
483 + if ( get_option('propertyhive_maps_provider') == 'osm' )
484 + {
485 +
486 +
487 + }
488 + else
489 + {
490 + if ( $property->latitude != '' && $property->latitude != '0' && $property->longitude != '' && $property->longitude != '0' )
491 + {
492 + $api_key = get_option('propertyhive_google_maps_api_key');
493 +
494 + $id_suffix = ( ( isset($args['id']) && $args['id'] != '' ) ? '_' . $args['id'] : '' );
495 +
496 + $link = ( ( isset($args['link']) && ($args['link'] === 'false' || $args['link'] === FALSE) ) ? 'false' : 'true' );
497 +
498 + $map_url = 'https://maps.googleapis.com/maps/api/staticmap?' .
499 + 'center=' . (float)$property->latitude . ',' . (float)$property->longitude .
500 + '&size=1024x' . ( ( isset($args['height']) && !empty($args['height']) && is_numeric($args['height']) ) ? (int)$args['height'] : 400 ) .
501 + '&zoom=' . ( ( isset($args['zoom']) && !empty($args['zoom']) ) ? (int)$args['zoom'] : '14' ) .
502 + '&maptype=roadmap' .
503 + '&markers=%7C%7C' . (float)$property->latitude . ',' . (float)$property->longitude .
504 + '&key=' . urlencode($api_key);
505 +
506 + echo '<style type="text/css">
507 + #property_static_map' . esc_attr($id_suffix) . ' {
508 + height:' . ( ( isset($args['height']) && !empty($args['height']) && is_numeric($args['height']) ) ? (int)$args['height'] : 400 ) . 'px;
509 + display: block;
510 + background-image: url("' . esc_url($map_url) . '");
511 + background-repeat: no-repeat;
512 + background-position: 50% 50%;
513 + line-height: 0;
514 + }
515 + </style>';
516 +
517 + if ( $link === true )
518 + {
519 + echo '<a id="property_static_map' . esc_attr($id_suffix) . '" href="https://maps.google.com?q=' . (float)$property->latitude . ',' . (float)$property->longitude . '" target="_blank" rel="nofollow"></a>';
520 + }
521 + else
522 + {
523 + echo '<div id="property_static_map' . esc_attr($id_suffix) . '" ></div>';
524 + }
525 + }
526 + }
527 +}
528 +
529 +// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound -- Legacy public global helper get_property_street_view; the established callable name is part of the plugin/extension API and must remain stable.
202 530 function get_property_street_view( $args = array() )
203 531 {
204 532 global $property;
205 533
206 - if ( $property->latitude != '' && $property->latitude != '0' && $property->longitude != '' && $property->longitude != '0' )
534 + if ( get_option('propertyhive_maps_provider') == 'osm' || get_option('propertyhive_maps_provider') == 'mapbox' )
207 535 {
208 - $api_key = get_option('propertyhive_google_maps_api_key');
209 - wp_register_script('googlemaps', '//maps.googleapis.com/maps/api/js?' . ( ( $api_key != '' && $api_key !== FALSE ) ? 'key=' . $api_key : '' ), false, '3');
210 - wp_enqueue_script('googlemaps');
211 536
212 - echo '<div id="property_street_view_canvas" style="height:' . str_replace( "px", "", ( ( isset($args['height']) && !empty($args['height']) ) ? $args['height'] : '400' ) ) . 'px"></div>';
213 -?>
214 -<script>
215 537
216 - // We declare vars globally so developers can access them
217 - var property_street_view; // Global declaration of the map
218 -
219 - function initialize_property_street_view() {
538 + }
539 + else
540 + {
541 + if ( $property->latitude != '' && $property->latitude != '0' && $property->longitude != '' && $property->longitude != '0' )
542 + {
543 + $api_key = get_option('propertyhive_google_maps_api_key');
544 + if ( isset($args['embed']) && ($args['embed'] === 'true' || $args['embed'] === TRUE) )
545 + {
546 + echo '<iframe
547 + width="100%"
548 + height="' . ( ( isset($args['height']) && !empty($args['height']) && is_numeric($args['height']) ) ? (int)$args['height'] : 400 ) . '"
549 + style="border:0"
550 + loading="lazy"
551 + allowfullscreen
552 + referrerpolicy="no-referrer-when-downgrade"
553 + src="' . esc_url( 'https://www.google.com/maps/embed/v1/streetview?key=' . $api_key . '&location=' . $property->latitude . ',' . $property->longitude ) . '">
554 + </iframe>';
555 + }
556 + else
557 + {
558 + wp_register_script('googlemaps', '//maps.googleapis.com/maps/api/js?' . ( ( $api_key != '' && $api_key !== FALSE ) ? 'key=' . $api_key : '' ), false, '3', true );
559 + wp_enqueue_script('googlemaps');
560 +
561 + echo '<div id="property_street_view_canvas" style="height:' . ( ( isset($args['height']) && !empty($args['height']) && is_numeric($args['height']) ) ? (int)$args['height'] : 400 ) . 'px"></div>';
562 + ?>
563 + <script>
564 +
565 + // We declare vars globally so developers can access them
566 + var property_street_view; // Global declaration of the map
220 567
221 - var myLatlng = new google.maps.LatLng(<?php echo $property->latitude; ?>, <?php echo $property->longitude; ?>);
222 - var map_options = {
223 - center: myLatlng
224 - }
568 + function initialize_property_street_view() {
569 +
570 + var myLatlng = new google.maps.LatLng(<?php echo (float)$property->latitude; ?>, <?php echo (float)$property->longitude; ?>);
571 + var map_options = {
572 + center: myLatlng
573 + }
225 574
226 - <?php do_action( 'propertyhive_property_street_view_map_options' ); ?>
575 + <?php do_action( 'propertyhive_property_street_view_map_options' ); ?>
227 576
228 - property_street_view = new google.maps.Map(document.getElementById("property_street_view_canvas"), map_options);
229 -
230 - var streetViewOptions = {
231 - position: myLatlng,
232 - pov: {
233 - heading: 90,
234 - pitch: 0,
235 - zoom: 0
577 + property_street_view = new google.maps.Map(document.getElementById("property_street_view_canvas"), map_options);
578 +
579 + var streetViewOptions = {
580 + position: myLatlng,
581 + pov: {
582 + heading: 90,
583 + pitch: 0,
584 + zoom: 0
585 + }
586 + };
587 +
588 + <?php do_action( 'propertyhive_property_street_view_options' ); ?>
589 +
590 + var streetView = new google.maps.StreetViewPanorama(document.getElementById("property_street_view_canvas"), streetViewOptions);
591 + streetView.setVisible(true);
592 + }
593 +
594 + <?php if ( !isset($args['init_on_load']) || ( isset($args['init_on_load']) && ($args['init_on_load'] === 'true' || $args['init_on_load'] === TRUE) ) ) { ?>
595 + if(window.addEventListener) {
596 + window.addEventListener('load', initialize_property_street_view);
597 + }else{
598 + window.attachEvent('onload', initialize_property_street_view);
599 + }
600 + <?php
236 601 }
237 - };
602 + }
603 + ?>
238 604
239 - <?php do_action( 'propertyhive_property_street_view_options' ); ?>
605 + </script>
606 + <?php
607 + }
608 + }
609 +}
240 610
241 - var streetView = new google.maps.StreetViewPanorama(document.getElementById("property_street_view_canvas"), streetViewOptions);
242 - streetView.setVisible(true);
611 +// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound -- Legacy public global helper get_electricity_types; the established callable name is part of the plugin/extension API and must remain stable.
612 +function get_electricity_types()
613 +{
614 + $types = array(
615 + 'mains_supply' => __( 'Mains Supply', 'propertyhive' ),
616 + 'wind_turbine' => __( 'Wind Turbine', 'propertyhive' ),
617 + 'solar_pv_panels' => __( 'Solar PV Panels', 'propertyhive' ),
618 + 'private_supply' => __( 'Private Supply', 'propertyhive' ),
619 + );
620 +
621 + $types = apply_filters( 'propertyhive_electricity_types', $types );
622 +
623 + asort($types);
624 +
625 + $types['other'] = __( 'Other', 'propertyhive' );
626 +
627 + return $types;
628 +}
629 +
630 +// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound -- Legacy public global helper get_electricity_type; the established callable name is part of the plugin/extension API and must remain stable.
631 +function get_electricity_type( $type )
632 +{
633 + $types = get_electricity_types();
634 +
635 + if ( isset($types[$type]) )
636 + {
637 + return $types[$type];
243 638 }
244 -
245 - if(window.addEventListener) {
246 - window.addEventListener('load', initialize_property_street_view);
247 - }else{
248 - window.attachEvent('onload', initialize_property_street_view);
639 +
640 + return '';
641 +}
642 +
643 +// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound -- Legacy public global helper get_water_types; the established callable name is part of the plugin/extension API and must remain stable.
644 +function get_water_types()
645 +{
646 + $types = array(
647 + 'mains_supply' => __( 'Mains Supply', 'propertyhive' ),
648 + 'private_supply' => __( 'Private Supply', 'propertyhive' ),
649 + );
650 +
651 + $types = apply_filters( 'propertyhive_water_types', $types );
652 +
653 + asort($types);
654 +
655 + $types['other'] = __( 'Other', 'propertyhive' );
656 +
657 + return $types;
658 +}
659 +
660 +// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound -- Legacy public global helper get_water_type; the established callable name is part of the plugin/extension API and must remain stable.
661 +function get_water_type( $type )
662 +{
663 + $types = get_water_types();
664 +
665 + if ( isset($types[$type]) )
666 + {
667 + return $types[$type];
249 668 }
250 669
251 -</script>
252 -<?php
670 + return '';
671 +}
672 +
673 +// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound -- Legacy public global helper get_broadband_types; the established callable name is part of the plugin/extension API and must remain stable.
674 +function get_broadband_types()
675 +{
676 + $types = array(
677 + 'adsl' => __( 'ADSL', 'propertyhive' ),
678 + 'cable' => __( 'Cable', 'propertyhive' ),
679 + 'fttc' => __( 'FTTC (Fibre to the Cabinet)', 'propertyhive' ),
680 + 'fttp' => __( 'FTTP (Fibre to the Premises)', 'propertyhive' ),
681 + 'none' => __( 'None', 'propertyhive' ),
682 + );
683 +
684 + $types = apply_filters( 'propertyhive_broadband_types', $types );
685 +
686 + asort($types);
687 +
688 + $types['other'] = __( 'Other', 'propertyhive' );
689 +
690 + return $types;
691 +}
692 +
693 +// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound -- Legacy public global helper get_broadband_type; the established callable name is part of the plugin/extension API and must remain stable.
694 +function get_broadband_type( $type )
695 +{
696 + $types = get_broadband_types();
697 +
698 + if ( isset($types[$type]) )
699 + {
700 + return $types[$type];
253 701 }
702 +
703 + return '';
254 704 }
255 705
706 +// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound -- Legacy public global helper get_heating_types; the established callable name is part of the plugin/extension API and must remain stable.
707 +function get_heating_types()
708 +{
709 + $types = array(
710 + 'air_conditioning' => __( 'Air Conditioning', 'propertyhive' ),
711 + 'central' => __( 'Central Heating', 'propertyhive' ),
712 + 'double_glazing' => __( 'Double Glazing', 'propertyhive' ),
713 + 'eco_friendly' => __( 'Eco-Friendly', 'propertyhive' ),
714 + 'electric' => __( 'Electric Heating', 'propertyhive' ),
715 + 'gas' => __( 'Gas Heating', 'propertyhive' ),
716 + 'gas_central' => __( 'Gas Central Heating', 'propertyhive' ),
717 + 'night_storage' => __( 'Night Storage Heating', 'propertyhive' ),
718 + 'oil' => __( 'Oil Heating', 'propertyhive' ),
719 + 'solar' => __( 'Solar Panels', 'propertyhive' ),
720 + 'solar_water' => __( 'Solar Water Heating', 'propertyhive' ),
721 + 'under_floor' => __( 'Underfloor Heating', 'propertyhive' ),
722 + 'wood_burner' => __( 'Wood Burner', 'propertyhive' ),
723 + 'open_fire' => __( 'Open Fire', 'propertyhive' ),
724 + 'biomass_boiler' => __( 'Biomass Boiler', 'propertyhive' ),
725 + 'ground_source_heat_pump' => __( 'Ground Source Heat Pump', 'propertyhive' ),
726 + 'air_source_heat_pump' => __( 'Air Source Heat Pump', 'propertyhive' ),
727 + 'solar_pv_thermal' => __( 'Solar PV Thermal', 'propertyhive' ),
728 + 'solar_thermal' => __( 'Solar Thermal Heating', 'propertyhive' ),
729 + );
730 +
731 + $types = apply_filters( 'propertyhive_heating_types', $types );
732 +
733 + asort($types);
734 +
735 + $types['other'] = __( 'Other', 'propertyhive' );
736 +
737 + return $types;
738 +}
739 +
740 +// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound -- Legacy public global helper get_heating_type; the established callable name is part of the plugin/extension API and must remain stable.
741 +function get_heating_type( $type )
742 +{
743 + $types = get_heating_types();
744 +
745 + if ( isset($types[$type]) )
746 + {
747 + return $types[$type];
748 + }
749 +
750 + return '';
751 +}
752 +
753 +// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound -- Legacy public global helper get_sewerage_types; the established callable name is part of the plugin/extension API and must remain stable.
754 +function get_sewerage_types()
755 +{
756 + $types = array(
757 + 'mains_supply' => __( 'Mains Supply', 'propertyhive' ),
758 + 'private_supply' => __( 'Private Supply', 'propertyhive' ),
759 + );
760 +
761 + $types = apply_filters( 'propertyhive_sewerage_types', $types );
762 +
763 + asort($types);
764 +
765 + $types['other'] = __( 'Other', 'propertyhive' );
766 +
767 + return $types;
768 +}
769 +
770 +// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound -- Legacy public global helper get_sewerage_type; the established callable name is part of the plugin/extension API and must remain stable.
771 +function get_sewerage_type( $type )
772 +{
773 + $types = get_sewerage_types();
774 +
775 + if ( isset($types[$type]) )
776 + {
777 + return $types[$type];
778 + }
779 +
780 + return '';
781 +}
782 +
783 +// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound -- Legacy public global helper get_flooding_source_types; the established callable name is part of the plugin/extension API and must remain stable.
784 +function get_flooding_source_types()
785 +{
786 + $types = array(
787 + 'river' => __( 'River', 'propertyhive' ),
788 + 'sea' => __( 'Sea', 'propertyhive' ),
789 + 'groundwater' => __( 'Groundwater', 'propertyhive' ),
790 + 'lake' => __( 'Lake', 'propertyhive' ),
791 + 'reservoir' => __( 'Reservoir', 'propertyhive' ),
792 + );
793 +
794 + $types = apply_filters( 'propertyhive_flooding_source_types', $types );
795 +
796 + asort($types);
797 +
798 + $types['other'] = __( 'Other', 'propertyhive' );
799 +
800 + return $types;
801 +}
802 +
803 +// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound -- Legacy public global helper get_flooding_source_type; the established callable name is part of the plugin/extension API and must remain stable.
804 +function get_flooding_source_type( $type )
805 +{
806 + $types = get_flooding_source_types();
807 +
808 + if ( isset($types[$type]) )
809 + {
810 + return $types[$type];
811 + }
812 +
813 + return '';
814 +}
815 +
816 +// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound -- Legacy public global helper get_accessibility_types; the established callable name is part of the plugin/extension API and must remain stable.
817 +function get_accessibility_types()
818 +{
819 + $types = array(
820 + 'lateral_living' => __( 'Lateral Living', 'propertyhive' ),
821 + 'level_access' => __( 'Level Access', 'propertyhive' ),
822 + 'lift_access' => __( 'Lift Access', 'propertyhive' ),
823 + 'step_free_access' => __( 'Step-Free Access', 'propertyhive' ),
824 + 'wet_room' => __( 'Wet Room', 'propertyhive' ),
825 + 'level_access_shower' => __( 'Level Access Shower', 'propertyhive' ),
826 + 'wide_doorways' => __( 'Wide Doorways', 'propertyhive' ),
827 + 'ramped_access' => __( 'Ramped Access', 'propertyhive' ),
828 + 'unsuitableForWheelchairs' => __( 'Unsuitable for Wheelchairs', 'propertyhive' ),
829 + );
830 +
831 + $types = apply_filters( 'propertyhive_accessibility_types', $types );
832 +
833 + asort($types);
834 +
835 + $types['other'] = __( 'Other', 'propertyhive' );
836 +
837 + return $types;
838 +}
839 +
840 +// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound -- Legacy public global helper get_accessibility_type; the established callable name is part of the plugin/extension API and must remain stable.
841 +function get_accessibility_type( $type )
842 +{
843 + $types = get_accessibility_types();
844 +
845 + if ( isset($types[$type]) )
846 + {
847 + return $types[$type];
848 + }
849 +
850 + return '';
851 +}
852 +
853 +// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound -- Legacy public global helper get_restrictions; the established callable name is part of the plugin/extension API and must remain stable.
854 +function get_restrictions()
855 +{
856 + $types = array(
857 + 'conservation_area' => __( 'Restrictions due to being in a conservation area', 'propertyhive' ),
858 + 'lease_restrictions' => __( 'Restrictions in the lease', 'propertyhive' ),
859 + 'listed_building' => __( 'Restrictions due to being listed', 'propertyhive' ),
860 + 'permitted_development' => __( 'Restrictions on property development', 'propertyhive' ),
861 + 'real_burdens' => __( 'A real burden applies to this property (Scotland only)', 'propertyhive' ),
862 + 'holiday_home_rental' => __( 'Holiday home rental restrictions', 'propertyhive' ),
863 + 'restrictive_covenant' => __( 'Restrictive covenants', 'propertyhive' ),
864 + 'business_from_property' => __( 'Restrictions on running a business', 'propertyhive' ),
865 + 'property_subletting' => __( 'Restrictions regarding subletting', 'propertyhive' ),
866 + 'tree_preservation_order' => __( 'Tree preservation orders', 'propertyhive' ),
867 + );
868 +
869 + $types = apply_filters( 'propertyhive_restrictions', $types );
870 +
871 + asort($types);
872 +
873 + $types['other'] = __( 'Other', 'propertyhive' );
874 +
875 + return $types;
876 +}
877 +
878 +// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound -- Legacy public global helper get_restriction; the established callable name is part of the plugin/extension API and must remain stable.
879 +function get_restriction( $type )
880 +{
881 + $types = get_restrictions();
882 +
883 + if ( isset($types[$type]) )
884 + {
885 + return $types[$type];
886 + }
887 +
888 + return '';
889 +}
890 +
891 +// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound -- Legacy public global helper get_rights; the established callable name is part of the plugin/extension API and must remain stable.
892 +function get_rights()
893 +{
894 + $types = array(
895 + 'right_of_way_public' => __( 'Public rights of way', 'propertyhive' ),
896 + 'right_of_way_private' => __( 'Private rights of way', 'propertyhive' ),
897 + 'registered_easements_hmlr' => __( 'Registered easements/rights with the HMLR (Land Registry)', 'propertyhive' ),
898 + 'servitudes' => __( 'Servitudes (Scotland only)', 'propertyhive' ),
899 + 'shared_driveway' => __( 'Shared driveway', 'propertyhive' ),
900 + 'loft_access' => __( 'Loft access', 'propertyhive' ),
901 + 'drain_access' => __( 'Drain access', 'propertyhive' ),
902 + );
903 +
904 + $types = apply_filters( 'propertyhive_rights', $types );
905 +
906 + asort($types);
907 +
908 + $types['other'] = __( 'Other', 'propertyhive' );
909 +
910 + return $types;
911 +}
912 +
913 +// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound -- Legacy public global helper get_right; the established callable name is part of the plugin/extension API and must remain stable.
914 +function get_right( $type )
915 +{
916 + $types = get_rights();
917 +
918 + if ( isset($types[$type]) )
919 + {
920 + return $types[$type];
921 + }
922 +
923 + return '';
924 +}
925 +
256 926 add_filter( 'get_post_metadata', function ( $value, $post_id, $meta_key, $single )
257 927 {
258 928 static $is_recursing = false; // Used to prevent infinite loop
259 929
@@ -265,15 +935,15 @@
265 935 $value = get_post_thumbnail_id( $post_id );
266 936
267 937 $is_recursing = false;
268 938
269 - if ( $value == '' ) // If we haven't already get a thumbnail ID (i.e. in the case where someone has added theme support)
939 + if ( empty($value) ) // If we haven't already get a thumbnail ID (i.e. in the case where someone has added theme support)
270 940 {
271 941 $photos = get_post_meta( $post_id, '_photos', TRUE );
272 942 if ( is_array($photos) && !empty($photos) )
273 943 {
274 944 $photos = array_filter( $photos );
275 - $value = $photos[0];
945 + if ( !empty($photos) ) { $value = $photos[0]; }
276 946 }
277 947 }
278 948
279 949 if ( ! $single )
@@ -281,5 +951,29 @@
281 951 $value = array( $value );
282 952 }
283 953 }
284 954 return $value;
285 -}, 10, 4);
955 +}, 10, 4);
956 +
957 +add_filter( 'wpseo_add_opengraph_images', function ( $object )
958 +{
959 + if ( get_option('propertyhive_images_stored_as', '') != 'urls' )
960 + {
961 + return $object;
962 + }
963 +
964 + global $post;
965 +
966 + if ( isset($post->post_type) && $post->post_type == 'property' )
967 + {
968 + $property = new PH_Property($post->ID);
969 + $photos = $property->_photo_urls;
970 +
971 + if (isset($photos) && is_array($photos) && !empty($photos) && isset($photos[0]) && isset($photos[0]['url']))
972 + {
973 + $secondary_image = array( 'url' => $photos[0]['url']/*, 'height' => 768, 'width' => 1024*/ );
974 + $object->add_image( $secondary_image );
975 + }
976 + }
977 +
978 + return $object;
979 +});