PluginProbe
Property Hive / 2.3.0
Property Hive v2.3.0
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 1.4.62 All 260 releases
← All changes | includes/ph-core-functions.php +86 -2 2.2.62.3.0 View file →
@@ -26,8 +26,9 @@
26 26 * @param mixed $slug
27 27 * @param string $name (default: '')
28 28 * @return void
29 29 */
30 +// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound -- Legacy public global helper ph_get_template_part; the established callable name is part of the plugin/extension API and must remain stable.
30 31 function ph_get_template_part( $slug, $name = '' ) {
31 32 $template = '';
32 33
33 34 // Look in yourtheme/slug-name.php and yourtheme/propertyhive/slug-name.php
@@ -45,8 +46,9 @@
45 46 $template = locate_template( array( "{$slug}.php", PH()->template_path() . "{$slug}.php" ) );
46 47 }
47 48
48 49 // Allow 3rd party plugin filter template file from their plugin
50 + // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- Existing public Property Hive extension hook ph_get_template_part; changing the established name would detach installed callbacks.
49 51 $template = apply_filters( 'ph_get_template_part', $template, $slug, $name );
50 52
51 53 if ( $template ) {
52 54 load_template( $template, false );
@@ -62,8 +64,9 @@
62 64 * @param string $template_path (default: '')
63 65 * @param string $default_path (default: '')
64 66 * @return void
65 67 */
68 +// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound -- Legacy public global helper ph_get_template; the established callable name is part of the plugin/extension API and must remain stable.
66 69 function ph_get_template( $template_name, $args = array(), $template_path = '', $default_path = '' ) {
67 70 if ( $args && is_array( $args ) ) {
68 71 extract( $args );
69 72 }
@@ -70,9 +73,9 @@
70 73
71 74 $located = ph_locate_template( $template_name, $template_path, $default_path );
72 75
73 76 if ( ! file_exists( $located ) ) {
74 - _doing_it_wrong( __FUNCTION__, sprintf( '<code>%s</code> does not exist.', $located ), '2.1' );
77 + _doing_it_wrong( __FUNCTION__, sprintf( '<code>%s</code> does not exist.', esc_html( $located ) ), '2.1' );
75 78 return;
76 79 }
77 80
78 81 do_action( 'propertyhive_before_template_part', $template_name, $template_path, $located, $args );
@@ -96,8 +99,9 @@
96 99 * @param string $template_path (default: '')
97 100 * @param string $default_path (default: '')
98 101 * @return string
99 102 */
103 +// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound -- Legacy public global helper ph_locate_template; the established callable name is part of the plugin/extension API and must remain stable.
100 104 function ph_locate_template( $template_name, $template_path = '', $default_path = '' ) {
101 105 if ( ! $template_path ) {
102 106 $template_path = PH()->template_path();
103 107 }
@@ -130,12 +134,14 @@
130 134 * @param string $value Value of the cookie
131 135 * @param integer $expire Expiry of the cookie
132 136 * @param string $secure Whether the cookie should be served only over https
133 137 */
138 +// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound -- Legacy public global helper ph_setcookie; the established callable name is part of the plugin/extension API and must remain stable.
134 139 function ph_setcookie( $name, $value, $expire = 0, $secure = false ) {
135 140 if ( ! headers_sent() ) {
136 141 return setcookie( $name, $value, $expire, COOKIEPATH, COOKIE_DOMAIN, $secure );
137 142 } elseif ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
143 + // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_trigger_error -- Intentional developer notice, enabled only by WP_DEBUG, for a failed cookie API call; no request or private data is included.
138 144 trigger_error( "Cookie cannot be set - headers already sent", E_USER_NOTICE );
139 145 }
140 146 return false;
141 147 }
@@ -145,8 +151,9 @@
145 151 *
146 152 * @param mixed $image_size
147 153 * @return array
148 154 */
155 +// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound -- Legacy public global helper ph_get_image_size; the established callable name is part of the plugin/extension API and must remain stable.
149 156 function ph_get_image_size( $image_size ) {
150 157 if ( is_array( $image_size ) ) {
151 158 $width = isset( $image_size[0] ) ? $image_size[0] : '300';
152 159 $height = isset( $image_size[1] ) ? $image_size[1] : '300';
@@ -169,8 +176,9 @@
169 176
170 177 return $size;
171 178 }
172 179
180 +// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound -- Legacy public global helper ph_get_custom_departments; the established callable name is part of the plugin/extension API and must remain stable.
173 181 function ph_get_custom_departments( $active_only = true )
174 182 {
175 183 $return = array();
176 184
@@ -189,8 +197,9 @@
189 197
190 198 return $return;
191 199 }
192 200
201 +// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound -- Legacy public global helper ph_get_custom_department_based_on; the established callable name is part of the plugin/extension API and must remain stable.
193 202 function ph_get_custom_department_based_on( $department )
194 203 {
195 204 $custom_departments = get_option( 'propertyhive_custom_departments', array() );
196 205
@@ -201,8 +210,9 @@
201 210
202 211 return false;
203 212 }
204 213
214 +// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound -- Legacy public global helper ph_get_departments; the established callable name is part of the plugin/extension API and must remain stable.
205 215 function ph_get_departments( $raw = false )
206 216 {
207 217 $departments = array(
208 218 'residential-sales' => __( 'Residential Sales', 'propertyhive' ),
@@ -212,8 +222,9 @@
212 222
213 223 return $raw ? $departments : apply_filters( 'propertyhive_departments', $departments );
214 224 }
215 225
226 +// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound -- Legacy public global helper ph_get_viewing_statuses; the established callable name is part of the plugin/extension API and must remain stable.
216 227 function ph_get_viewing_statuses()
217 228 {
218 229 $viewing_statuses = array(
219 230 'pending' => __( 'Pending', 'propertyhive' ),
@@ -229,8 +240,9 @@
229 240
230 241 return $viewing_statuses;
231 242 }
232 243
244 +// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound -- Legacy public global helper add_viewing_status_meta_query; the established callable name is part of the plugin/extension API and must remain stable.
233 245 function add_viewing_status_meta_query( $meta_query, $selected_status )
234 246 {
235 247 switch ( $selected_status )
236 248 {
@@ -321,8 +333,9 @@
321 333 }
322 334 return $meta_query;
323 335 }
324 336
337 +// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound -- Legacy public global helper ph_get_offer_statuses; the established callable name is part of the plugin/extension API and must remain stable.
325 338 function ph_get_offer_statuses()
326 339 {
327 340 $offer_statuses = array(
328 341 'pending' => __( 'Pending', 'propertyhive' ),
@@ -332,8 +345,9 @@
332 345
333 346 return $offer_statuses;
334 347 }
335 348
349 +// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound -- Legacy public global helper ph_get_sale_statuses; the established callable name is part of the plugin/extension API and must remain stable.
336 350 function ph_get_sale_statuses()
337 351 {
338 352 $sale_statuses = array(
339 353 'current' => __( 'Current', 'propertyhive' ),
@@ -344,8 +358,9 @@
344 358
345 359 return $sale_statuses;
346 360 }
347 361
362 +// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound -- Legacy public global helper ph_get_enquiry_statuses; the established callable name is part of the plugin/extension API and must remain stable.
348 363 function ph_get_enquiry_statuses()
349 364 {
350 365 $enquiry_statuses = array(
351 366 'open' => __( 'Open', 'propertyhive' ),
@@ -354,8 +369,9 @@
354 369
355 370 return $enquiry_statuses;
356 371 }
357 372
373 +// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound -- Legacy public global helper get_area_units; the established callable name is part of the plugin/extension API and must remain stable.
358 374 function get_area_units()
359 375 {
360 376 $size_options = array(
361 377 'sqft' => __( 'Sq Ft', 'propertyhive' ),
@@ -370,8 +386,9 @@
370 386
371 387 return $size_options;
372 388 }
373 389
390 +// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound -- Legacy public global helper convert_size_to_sqft; the established callable name is part of the plugin/extension API and must remain stable.
374 391 function convert_size_to_sqft( $size, $unit = 'sqft' )
375 392 {
376 393 $size_sqft = $size;
377 394
@@ -386,8 +403,9 @@
386 403 }
387 404 return $size_sqft;
388 405 }
389 406
407 +// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound -- Legacy public global helper get_commercial_price_units; the established callable name is part of the plugin/extension API and must remain stable.
390 408 function get_commercial_price_units( )
391 409 {
392 410 $price_options = array(
393 411 'psqft' => __( 'Per Sq Ft', 'propertyhive' ),
@@ -405,8 +423,9 @@
405 423 * @param int $number
406 424 * @param bool $return_number Include $n in the string returned
407 425 * @return string $number including its ordinal suffix
408 426 */
427 +// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound -- Legacy public global helper ph_ordinal_suffix; the established callable name is part of the plugin/extension API and must remain stable.
409 428 function ph_ordinal_suffix( $number, $return_words = true, $return_number = true )
410 429 {
411 430 $n_last = $number % 100;
412 431 if ( ($n_last > 10 && $n_last << 14) || $number == 0 )
@@ -444,5 +463,70 @@
444 463 break;
445 464 }
446 465 }
447 466 return $return_words ? $number_in_words : ( $return_number ? $number . $suffix : $suffix );
448 -}
467 +}
468 +
469 +/**
470 + * Save an ordered property media list without modifying unauthorized attachments.
471 + * The caller verifies the property form nonce before invoking this helper.
472 + *
473 + * @param int $post_id Property ID.
474 + * @param string $meta_key Media list key.
475 + * @param string $submitted_ids Comma-separated attachment IDs.
476 + * @return bool Whether the list was saved.
477 + */
478 +function propertyhive_save_media_attachment_list( $post_id, $meta_key, $submitted_ids ) {
479 + if ( ! current_user_can( 'manage_propertyhive' ) || ! current_user_can( 'edit_post', $post_id ) || 'property' !== get_post_type( $post_id ) ) {
480 + return false;
481 + }
482 + if ( ! in_array( $meta_key, array( '_photos', '_floorplans', '_brochures', '_epcs' ), true ) || ! is_string( $submitted_ids ) || ! preg_match( '/^[0-9,\s]*$/D', $submitted_ids ) ) {
483 + return false;
484 + }
485 + $ids = array_values( array_unique( array_filter( array_map( 'absint', explode( ',', $submitted_ids ) ) ) ) );
486 + $previous_ids = get_post_meta( $post_id, $meta_key, true );
487 + $previous_ids = is_array( $previous_ids ) ? array_map( 'absint', $previous_ids ) : array();
488 +
489 + foreach ( $ids as $index => $attachment_id ) {
490 + if ( 'attachment' !== get_post_type( $attachment_id ) ) {
491 + unset( $ids[$index] );
492 + continue;
493 + }
494 +
495 + if ( ! current_user_can( 'edit_post', $attachment_id ) ) {
496 + return false;
497 + }
498 + }
499 +
500 + $ids = array_values( $ids );
501 +
502 + foreach ( $ids as $attachment_id ) {
503 + wp_update_post( array( 'ID' => $attachment_id, 'post_parent' => $post_id ) );
504 + clean_attachment_cache( $attachment_id );
505 + }
506 + update_post_meta( $post_id, $meta_key, $ids );
507 + foreach ( array_diff( $previous_ids, $ids ) as $attachment_id ) {
508 + if ( 'attachment' === get_post_type( $attachment_id ) && (int) get_post_field( 'post_parent', $attachment_id ) === (int) $post_id && current_user_can( 'edit_post', $attachment_id ) ) {
509 + wp_update_post( array( 'ID' => $attachment_id, 'post_parent' => 0 ) );
510 + clean_attachment_cache( $attachment_id );
511 + }
512 + }
513 + return true;
514 +}
515 +
516 +/**
517 + * Determine public visibility on all supported WordPress versions.
518 + *
519 + * @param int|WP_Post $post Post to inspect.
520 + * @return bool Whether anonymous visitors may view it.
521 + */
522 +function propertyhive_is_post_publicly_viewable( $post ) {
523 + if ( function_exists( 'is_post_publicly_viewable' ) ) {
524 + return is_post_publicly_viewable( $post );
525 + }
526 + $post = get_post( $post );
527 + if ( ! $post || ! is_post_type_viewable( get_post_type_object( $post->post_type ) ) ) {
528 + return false;
529 + }
530 + $status = get_post_status_object( $post->post_status );
531 + return $status && ! empty( $status->public );
532 +}