1: <?php
2: /**
3: * Front End Functions
4: *
5: * @package EPL
6: * @subpackage Functions/Global
7: * @copyright Copyright (c) 2020, Merv Barrett
8: * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
9: * @since 1.0
10: */
11:
12: // Exit if accessed directly.
13: if ( ! defined( 'ABSPATH' ) ) {
14: exit;
15: }
16:
17: /**
18: * Get an option
19: *
20: * Looks to see if the specified setting exists, returns default if not
21: *
22: * @param string $key Meta key.
23: * @param bool $default_val Returns default if not set.
24: *
25: * @return mixed
26: *
27: * @since 2.2
28: * @since 3.5.2 Added check to identify 0 values so that it's not ignored by empty check.
29: * @since 3.6 Fix: a decimal between -1 and 1, such as 0.5, was returned as 0. Only a real 0 is returned as 0 now.
30: */
31: function epl_get_option( $key = '', $default_val = false ) {
32:
33: global $epl_settings;
34:
35: // Check for zeros.
36: if ( isset( $epl_settings[ $key ] ) && is_numeric( $epl_settings[ $key ] ) && 0.0 === (float) $epl_settings[ $key ] ) {
37: $value = 0;
38: } else {
39: // Preserve empty check for rest of the values to preserve the behaviour: if value empty, then return default.
40: $value = ! empty( $epl_settings[ $key ] ) ? $epl_settings[ $key ] : $default_val;
41: }
42:
43: $value = apply_filters( 'epl_get_option', $value, $key, $default_val );
44: return apply_filters( 'epl_get_option_' . $key, $value, $key, $default_val );
45: }
46:
47: /**
48: * Get a saved option, keeping saved empty values
49: *
50: * Unlike epl_get_option(), a saved empty value such as '' or an empty array is returned as
51: * saved, so a cleared text field or a checkbox list with nothing ticked stays empty. The
52: * default is returned only when the setting has never been saved. Runs the same
53: * epl_get_option and epl_get_option_{$key} filters as epl_get_option().
54: *
55: * @param string $key Setting key.
56: * @param mixed $default_val Returned when the setting has never been saved.
57: *
58: * @return mixed
59: *
60: * @since 3.6
61: */
62: function epl_get_saved_option( $key = '', $default_val = false ) {
63:
64: $epl_settings = epl_get_settings();
65:
66: if ( is_array( $epl_settings ) && isset( $epl_settings[ $key ] ) ) {
67: $value = $epl_settings[ $key ];
68: } else {
69: $value = $default_val;
70: }
71:
72: $value = apply_filters( 'epl_get_option', $value, $key, $default_val );
73: return apply_filters( 'epl_get_option_' . $key, $value, $key, $default_val );
74: }
75:
76: /**
77: * Keep the global settings in step with the saved option
78: *
79: * The global $epl_settings is loaded once per request, so without this epl_get_option()
80: * and epl_get_saved_option() return the old values for the rest of the request after
81: * the epl_settings option is saved.
82: *
83: * @param mixed $old_value Previous value (unused).
84: * @param mixed $value Saved value.
85: *
86: * @since 3.6
87: */
88: function epl_refresh_settings_global( $old_value, $value ) {
89: global $epl_settings;
90: $epl_settings = $value;
91: }
92: add_action( 'update_option_epl_settings', 'epl_refresh_settings_global', 10, 2 );
93:
94: /**
95: * Keep the global settings in step when the epl_settings option is first added
96: *
97: * @param string $option Option name (unused).
98: * @param mixed $value Saved value.
99: *
100: * @since 3.6
101: */
102: function epl_refresh_settings_global_on_add( $option, $value ) {
103: epl_refresh_settings_global( null, $value );
104: }
105: add_action( 'add_option_epl_settings', 'epl_refresh_settings_global_on_add', 10, 2 );
106:
107: /**
108: * Determine if Divi framework is loaded
109: *
110: * @since 3.1
111: */
112: function epl_is_divi_framework_theme() {
113: if ( function_exists( 'et_divi_fonts_url' ) ) {
114: return true;
115: }
116: return false;
117: }
118:
119: /**
120: * Determine if iThemes Builder framework is loaded
121: *
122: * @since 1.0
123: */
124: function epl_is_builder_framework_theme() {
125: if ( function_exists( 'it_classes_load' ) ) {
126: return true;
127: }
128: return false;
129: }
130:
131: /**
132: * Determine if Genesis framework is loaded
133: *
134: * @since 1.0
135: */
136: function epl_is_genesis_framework_theme() {
137: if ( function_exists( 'genesis_constants' ) ) {
138: return true;
139: }
140: return false;
141: }
142:
143: /**
144: * Determine if TwentyTwenty is loaded
145: *
146: * @since 3.4.14
147: */
148: function epl_is_twenty_twenty_theme() {
149: if ( function_exists( 'twentytwenty_theme_support' ) ) {
150: return true;
151: }
152: return false;
153: }
154:
155: /**
156: * Determine if Avada is loaded
157: *
158: * @since 3.4.26
159: */
160: function epl_is_avada_theme() {
161: if ( function_exists( 'Avada' ) ) {
162: return true;
163: }
164: return false;
165: }
166:
167: /**
168: * Used in the widgets by appending the registered image sizes
169: *
170: * @since 1.0
171: * @since 3.4.24 Added full size in array.
172: */
173: function epl_get_thumbnail_sizes() {
174: global $_wp_additional_image_sizes;
175: $sizes = array(
176: 'full' => array(),
177: );
178: foreach ( get_intermediate_image_sizes() as $s ) {
179: $sizes[ $s ] = array( 0, 0 );
180: if ( in_array( $s, array( 'thumbnail', 'medium', 'large' ), true ) ) {
181: $sizes[ $s ][0] = get_option( $s . '_size_w' );
182: $sizes[ $s ][1] = get_option( $s . '_size_h' );
183: } elseif ( isset( $_wp_additional_image_sizes ) && isset( $_wp_additional_image_sizes[ $s ] ) ) {
184: $sizes[ $s ] = array( $_wp_additional_image_sizes[ $s ]['width'], $_wp_additional_image_sizes[ $s ]['height'] );
185: }
186: }
187: return $sizes;
188: }
189:
190: /**
191: * Remote get function
192: *
193: * @param string $url Url.
194: *
195: * @return string
196: * @since 3.3.5 Removed curl.
197: * @since 1.0
198: */
199: function epl_remote_url_get( $url ) {
200:
201: $response = wp_remote_get( $url );
202: return wp_remote_retrieve_body( $response );
203: }
204:
205: /**
206: * Generate signed token for inspection iCal links.
207: *
208: * @param int $post_id Post ID.
209: * @param string $inspection_time Inspection date/time string.
210: *
211: * @return string
212: * @since 3.5.21
213: */
214: function epl_get_ical_download_token( $post_id, $inspection_time ) {
215: $post_id = absint( $post_id );
216: $inspection_time = trim( (string) $inspection_time );
217: $payload = $post_id . '|' . $inspection_time;
218: $secret = apply_filters( 'epl_ical_token_secret', wp_salt( 'nonce' ) );
219:
220: return hash_hmac( 'sha256', $payload, $secret );
221: }
222:
223: /**
224: * Register post type to EPL and WordPress
225: *
226: * @param string $post_type Post type name.
227: * @param string $post_type_label Post type label.
228: * @param array $args Arguments.
229: *
230: * @since 1.0.0
231: * @since 3.4.20 flush permalinks after new settings are saved.
232: * @since 3.4.26 Set $post_type_label to blank by default.
233: */
234: function epl_register_post_type( $post_type = '', $post_type_label = '', $args = array() ) {
235: if ( empty( $post_type ) ) {
236: return;
237: }
238:
239: global $epl_settings;
240: if ( ! empty( $epl_settings ) && isset( $epl_settings['activate_post_types'] ) ) {
241: $epl_activate_post_types = $epl_settings['activate_post_types'];
242: if ( ! empty( $epl_activate_post_types ) ) {
243: if ( in_array( $post_type, $epl_activate_post_types, true ) ) {
244: global $epl_active_post_types;
245: if ( ! isset( $epl_active_post_types ) ) {
246: $epl_active_post_types = array();
247: }
248: $epl_active_post_types[ $post_type ] = $post_type_label;
249: register_post_type( $post_type, $args );
250: }
251: }
252: }
253:
254: if ( isset( $_REQUEST['action'] ) && 'epl_settings' === $_REQUEST['action'] ) { //phpcs:ignore
255: update_option( 'epl_rewrite_rules', false );
256: }
257: }
258:
259: /**
260: * Return all the post types that are selected as active by admin
261: *
262: * @since 1.0
263: */
264: function epl_get_active_post_types() {
265: global $epl_active_post_types;
266: if ( is_null( $epl_active_post_types ) ) {
267: $epl_active_post_types = array();
268: }
269: return $epl_active_post_types;
270: }
271:
272: /**
273: * Return all the post types doesn't matter if selected as active or not by admin
274: *
275: * @since 1.0
276: */
277: function epl_get_post_types() {
278: $epl_post_types = array(
279: 'property' => __( 'Property (Residential)', 'easy-property-listings' ),
280: 'land' => __( 'Land', 'easy-property-listings' ),
281: 'rental' => __( 'Rental', 'easy-property-listings' ),
282: 'rural' => __( 'Rural', 'easy-property-listings' ),
283: 'commercial' => __( 'Commercial', 'easy-property-listings' ),
284: 'commercial_land' => __( 'Commercial Land', 'easy-property-listings' ),
285: 'business' => __( 'Business', 'easy-property-listings' ),
286: );
287: // allow 3rd party extensions to add custom posts as a part of epl.
288: return apply_filters( 'epl_post_types', $epl_post_types );
289: }
290:
291: /**
292: * Get Currencies
293: *
294: * @since 1.0
295: * @return array $currencies A list of the available currencies
296: * @since 3.4.48 Support for Namibian dollar.
297: */
298: function epl_get_currencies() {
299: $currencies = array(
300: 'AUD' => __( 'Australian Dollars (&#36;)', 'easy-property-listings' ),
301: 'USD' => __( 'US Dollars (&#36;)', 'easy-property-listings' ),
302: 'EUR' => __( 'Euros (&euro;)', 'easy-property-listings' ),
303: 'GBP' => __( 'Pounds Sterling (&pound;)', 'easy-property-listings' ),
304: 'BRL' => __( 'Brazilian Real (R&#36;)', 'easy-property-listings' ),
305: 'CAD' => __( 'Canadian Dollars (&#36;)', 'easy-property-listings' ),
306: 'CZK' => __( 'Czech Koruna', 'easy-property-listings' ),
307: 'DKK' => __( 'Danish Krone', 'easy-property-listings' ),
308: 'HKD' => __( 'Hong Kong Dollar (&#36;)', 'easy-property-listings' ),
309: 'HUF' => __( 'Hungarian Forint', 'easy-property-listings' ),
310: 'INR' => __( 'Indian Rupee (&#8377;)', 'easy-property-listings' ),
311: 'RIAL' => __( 'Iranian Rial (&#65020;)', 'easy-property-listings' ),
312: 'ILS' => __( 'Israeli Shekel (&#8362;)', 'easy-property-listings' ),
313: 'JPY' => __( 'Japanese Yen (&yen;)', 'easy-property-listings' ),
314: 'MYR' => __( 'Malaysian Ringgits', 'easy-property-listings' ),
315: 'MXN' => __( 'Mexican Peso (&#36;)', 'easy-property-listings' ),
316: 'NAD' => __( 'Namibian Dollar (&#36;)', 'easy-property-listings' ),
317: 'NZD' => __( 'New Zealand Dollar (&#36;)', 'easy-property-listings' ),
318: 'NOK' => __( 'Norwegian Krone', 'easy-property-listings' ),
319: 'PHP' => __( 'Philippine Pesos', 'easy-property-listings' ),
320: 'PLN' => __( 'Polish Zloty', 'easy-property-listings' ),
321: 'PKR' => __( 'Pakistani Rupee', 'easy-property-listings' ),
322: 'QAR' => __( 'Qatar Riyal (QAR)', 'easy-property-listings' ),
323: 'SGD' => __( 'Singapore Dollar (&#36;)', 'easy-property-listings' ),
324: 'ZAR' => __( 'South African Rand (R)', 'easy-property-listings' ),
325: 'SEK' => __( 'Swedish Krona', 'easy-property-listings' ),
326: 'CHF' => __( 'Swiss Franc', 'easy-property-listings' ),
327: 'TWD' => __( 'Taiwan New Dollars', 'easy-property-listings' ),
328: 'THB' => __( 'Thai Baht (&#3647;)', 'easy-property-listings' ),
329: 'TRY' => __( 'Turkish Lira (&#8378;)', 'easy-property-listings' ),
330: 'RUB' => __( 'Russian Rubles', 'easy-property-listings' ),
331: 'AED' => __( 'United Arab Emirates, Dirham (AED)', 'easy-property-listings' ),
332: 'UAH' => __( 'Ukrainian Hryvnia (&#8372;)', 'easy-property-listings' ),
333: 'VND' => __( 'Vietnamese đồng (&#8363;)', 'easy-property-listings' ),
334: );
335: return apply_filters( 'epl_get_currencies', $currencies );
336: }
337:
338: /**
339: * Get the store's set currency
340: *
341: * @since 1.0
342: * @return string The currency code
343: */
344: function epl_get_currency() {
345: $epl_currency = '';
346:
347: global $epl_settings;
348: if ( ! empty( $epl_settings ) && isset( $epl_settings['currency'] ) ) {
349: $epl_currency = $epl_settings['currency'];
350: }
351: return apply_filters( 'epl_currency', $epl_currency );
352: }
353:
354: /**
355: * Get the currency position
356: *
357: * @since 1.0
358: * @return string The currency symbol position
359: */
360: function epl_get_currency_position() {
361: $epl_currency_position = '';
362:
363: global $epl_settings;
364: if ( ! empty( $epl_settings ) && isset( $epl_settings['currency_position'] ) ) {
365: $epl_currency_position = $epl_settings['currency_position'];
366: }
367: return apply_filters( 'epl_currency_position', $epl_currency_position );
368: }
369:
370: /**
371: * Get the currency thousands separator
372: *
373: * @since 1.0
374: * @return string The currency thousands separator
375: */
376: function epl_get_thousands_separator() {
377: $epl_thousands_separator = '';
378:
379: global $epl_settings;
380: if ( ! empty( $epl_settings ) && isset( $epl_settings['currency_thousands_separator'] ) ) {
381: $epl_thousands_separator = $epl_settings['currency_thousands_separator'];
382: }
383: return apply_filters( 'epl_thousands_separator', $epl_thousands_separator );
384: }
385:
386: /**
387: * Get the currency decimal separator
388: *
389: * @since 1.0
390: * @return string The currency decimal separator
391: */
392: function epl_get_decimal_separator() {
393: $epl_decimal_separator = '';
394:
395: global $epl_settings;
396: if ( ! empty( $epl_settings ) && isset( $epl_settings['currency_decimal_separator'] ) ) {
397: $epl_decimal_separator = $epl_settings['currency_decimal_separator'];
398: }
399: return apply_filters( 'epl_decimal_separator', $epl_decimal_separator );
400: }
401:
402: /**
403: * Get the currency formatted amount
404: *
405: * @param integer $price The price.
406: *
407: * @return string Currency Formatted price
408: * @since 1.0
409: */
410: function epl_currency_formatted_amount( $price ) {
411: $price_format = apply_filters( 'epl_price_number_format', 'number' );
412: $price_format_com_lease = apply_filters( 'epl_price_number_format_commercial_lease', 'number' );
413:
414: if ( 'decimal' === $price_format || 'decimal' === $price_format_com_lease ) {
415: return epl_currency_filter( epl_format_amount( $price, true ) );
416: } else {
417: return epl_currency_filter( epl_format_amount( $price, false ) );
418: }
419: }
420:
421: /**
422: * Get labels
423: *
424: * @param integer $key Settings meta key.
425: * @return string
426: *
427: * @since 2.2
428: * @since 3.5.0 New: Display hidden field option.
429: */
430: function epl_labels( $key ) {
431: global $epl_settings;
432: $field_groups = epl_get_admin_option_fields();
433: $epl_labels = array();
434: foreach ( $field_groups as $field_group ) {
435: if ( 'labels' === $field_group['id'] || 'address' === $field_group['id'] ) {
436: $epl_labels = array_merge( $epl_labels, array_filter( $field_group['fields'] ) );
437: }
438: }
439: foreach ( $epl_labels as $label_key => $label ) {
440:
441: if ( isset( $label['default'] ) && $key === $label['name'] ) {
442:
443: $label = isset( $epl_settings[ $key ] ) ? $epl_settings[ $key ] : $label['default'];
444:
445: return apply_filters( 'epl_display_' . $key, $label );
446: }
447: }
448: }
449:
450: /**
451: * Display or retrieve the current listing address based on user display selection with optional markup.
452: *
453: * @since 3.3
454: *
455: * @param string $before Optional. Markup to prepend to the title. Default empty.
456: * @param string $after Optional. Markup to append to the title. Default empty.
457: * @param bool $country Optional. Whether to echo or return country. Default false for country.
458: * @param bool $echo_output Optional. Whether to echo or return the title. Default true for echo.
459: * @return string|void Current post title if $echo_output is false.
460: */
461: function epl_the_address( $before = '', $after = '', $country = false, $echo_output = true ) {
462: $address = epl_get_the_address();
463:
464: if ( strlen( $address ) === 0 ) {
465: return;
466: }
467:
468: $address = $before . $address . $after;
469:
470: if ( $echo_output ) {
471: echo wp_kses_post( $address );
472: } else {
473: return $address;
474: }
475: }
476:
477: /**
478: * Retrieve address based on user display selection.
479: *
480: * @param array $address_args Address components.
481: * @param array $sep Override default separators for each address components here.
482: * @param bool $country Return country with true, default false.
483: * @param array $prefix Customise the prefix for each address component.
484: *
485: * @return string
486: * @since 3.3
487: * @since 3.4.27 Added support for prefix.
488: * @since 3.6 Uses the listing's show_street_address() and show_suburb() rules. Fix: the suburb of a commercial, commercial land or business listing is left out when Display Street Address and Display Suburb are both unticked, as epl_property_the_address() and the REST API already do.
489: */
490: function epl_get_the_address( $address_args = array(), $sep = array(), $country = false, $prefix = array() ) {
491:
492: $address = '';
493:
494: $address_defaults = array(
495: 'sub_number' => '/',
496: 'lot_number' => ' ',
497: 'street_number' => ' ',
498: 'street' => ', ',
499: 'suburb' => ' ',
500: 'city' => ' ',
501: 'state' => ' ',
502: 'postal_code' => ' ',
503: 'country' => ' ',
504: );
505:
506: $prefix_defaults = array(
507: 'sub_number' => '',
508: 'lot_number' => '',
509: 'street_number' => '',
510: 'street' => '',
511: 'suburb' => '',
512: 'city' => '',
513: 'state' => '',
514: 'postal_code' => '',
515: 'country' => '',
516: );
517:
518: // Override default separators for address components.
519: $seps = array_merge( $address_defaults, $sep );
520:
521: $prefix = array_merge( $prefix_defaults, $prefix );
522:
523: // Output the full address based on user selection.
524: if ( empty( $address_args ) ) {
525: $address_args = array_keys( $address_defaults );
526: }
527:
528: global $property;
529:
530: foreach ( $address_args as $arg ) {
531:
532: if ( isset( $address_defaults[ $arg ] ) ) {
533:
534: if ( ! $property->show_street_address() && in_array( $arg, array( 'sub_number', 'lot_number', 'street_number', 'street' ), true ) ) {
535: continue;
536: }
537:
538: if ( 'suburb' === $arg && ! $property->show_suburb() ) {
539: continue;
540: }
541:
542: // Country hidden by default.
543: if ( true !== $country && in_array( $arg, array( 'country' ), true ) ) {
544: continue;
545: }
546:
547: $value = get_property_meta( 'property_address_' . $arg );
548:
549: if ( ! empty( $value ) ) {
550: $address .= $prefix[ $arg ] . get_property_meta( 'property_address_' . $arg ) . $seps[ $arg ];
551: }
552: }
553: }
554:
555: /**
556: * Filters the post title.
557: *
558: * @since 3.3
559: *
560: * @param string $title The listing address.
561: * @param int $id The post ID.
562: */
563: return apply_filters( 'epl_the_address', $address );
564: }
565:
566: /**
567: * Display or retrieve the listing status label with optional markup.
568: *
569: * @since 3.3
570: *
571: * @param string $before Output string before.
572: * @param string $after Output string after.
573: * @param bool $echo_output Echo the result.
574: * @return string/list for values
575: */
576: function epl_the_status( $before = '', $after = '', $echo_output = true ) {
577: $status = epl_get_the_status();
578:
579: $status_opts = epl_get_property_status_opts();
580:
581: if ( strlen( $status ) === 0 ) {
582: return;
583: }
584:
585: $status = $before . $status_opts[ $status ] . $after;
586:
587: if ( $echo_output ) {
588: echo wp_kses_post( $status );
589: } else {
590: return $status;
591: }
592: }
593:
594: /**
595: * Retrieve listing status.
596: *
597: * @since 3.3
598: *
599: * @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global $post.
600: * @return string
601: */
602: function epl_get_the_status( $post = 0 ) {
603:
604: $post = get_post( $post );
605:
606: $status = get_property_meta( 'property_status' );
607: $status = isset( $status ) ? $status : '';
608: $id = isset( $post->ID ) ? $post->ID : 0;
609:
610: /**
611: * Filters the status.
612: *
613: * @since 3.3
614: *
615: * @param string $title The listing status.
616: * @param int $id The post ID.
617: */
618: return apply_filters( 'epl_get_the_status', $status, $id );
619: }
620:
621: /**
622: * Get EPL property meta data based on post id
623: *
624: * @since 1.0
625: * @param string $post_ID The post ID.
626: * @param string $meta_key Meta key name.
627: * @return string Value.
628: */
629: function epl_get_property_meta( $post_ID = '', $meta_key = '' ) {
630:
631: if ( empty( $post_ID ) ) {
632: $post_ID = get_the_ID();
633: }
634:
635: if ( ! empty( $meta_key ) ) {
636: $meta_value = trim( get_post_meta( $post_ID, $meta_key, true ) );
637: } else {
638: $meta_value = get_post_meta( $post_ID, $meta_key, false );
639: }
640: return apply_filters( 'epl_get_property_meta_filter', $meta_value );
641: }
642:
643: /**
644: * Print EPL property meta data
645: *
646: * @param string $post_ID The post ID.
647: * @param string $meta_key Meta key name.
648: *
649: * @since 1.0.0
650: * @since 3.4.26 Set $meta_key variable as blank.
651: */
652: function epl_the_property_meta( $post_ID = '', $meta_key = '' ) {
653: $meta_value = epl_get_property_meta( $post_ID, $meta_key );
654: echo wp_kses_post( apply_filters( 'epl_the_property_meta_filter', $meta_value ) );
655: }
656:
657: /**
658: * Taxonomy Location Label
659: *
660: * @since 1.0
661: * @return string Location label.
662: */
663: function epl_tax_location_label() {
664: $label_location = '';
665: global $epl_settings;
666: if ( ! empty( $epl_settings ) && isset( $epl_settings['label_location'] ) ) {
667: $label_location = trim( $epl_settings['label_location'] );
668: }
669: if ( empty( $label_location ) ) {
670: $label_location = __( 'City', 'easy-property-listings' );
671: }
672: return $label_location;
673: }
674:
675: /**
676: * Location Label
677: *
678: * @since 1.0
679: * @return string Location label.
680: */
681: function epl_meta_location_label() {
682: $label_location = '';
683: global $epl_settings;
684: if ( ! empty( $epl_settings ) && isset( $epl_settings['label_suburb'] ) ) {
685: $label_location = trim( $epl_settings['label_suburb'] );
686: }
687: if ( empty( $label_location ) ) {
688: $label_location = __( 'City', 'easy-property-listings' );
689: }
690: return $label_location;
691: }
692:
693: /**
694: * Display or retrieve the under offer label with optional markup.
695: *
696: * @since 3.3
697: *
698: * @param string $before Optional. Markup to prepend to the formatted Under Offer label. Default empty.
699: * @param string $after Optional. Markup to append to the formatted Under Offer label. Default empty.
700: * @param bool $echo_output Optional. Whether to echo or return the formatted Under Offer label. Default true for echo.
701: * @return string|void Current post title if $echo_output is false.
702: */
703: function epl_the_under_offer( $before = '', $after = '', $echo_output = true ) {
704: $under_offer = epl_get_the_under_offer();
705:
706: $under_offer_label = epl_meta_under_offer_label();
707:
708: if ( strlen( $under_offer ) === 0 ) {
709: return;
710: }
711:
712: if ( 'yes' !== strtolower( $under_offer ) && 'sold' !== epl_get_the_status() ) {
713: return;
714: }
715:
716: $under_offer = $before . $under_offer_label . $after;
717:
718: if ( $echo_output ) {
719: echo wp_kses_post( $under_offer );
720: } else {
721: return $under_offer;
722: }
723: }
724:
725: /**
726: * Retrieve listing under offer value.
727: *
728: * @since 3.3
729: *
730: * @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global $post.
731: * @return string
732: */
733: function epl_get_the_under_offer( $post = 0 ) {
734:
735: $post = get_post( $post );
736:
737: $under_offer = get_property_meta( 'property_under_offer' );
738: $under_offer = 'yes' === get_property_meta( 'property_under_offer' ) && 'sold' !== epl_get_the_status() ? $under_offer : '';
739: $id = isset( $post->ID ) ? $post->ID : 0;
740:
741: /**
742: * Filters the status.
743: *
744: * @since 3.3
745: *
746: * @param string $under_offer The Under Offer status.
747: * @param int $id The post ID.
748: */
749: return apply_filters( 'epl_get_the_under_offer', $under_offer, $id );
750: }
751:
752: /**
753: * Under Offer Label
754: *
755: * @since 2.1
756: * @return string
757: */
758: function epl_meta_under_offer_label() {
759: $under_offer = '';
760: global $epl_settings;
761: if ( ! empty( $epl_settings ) && isset( $epl_settings['label_under_offer'] ) ) {
762: $under_offer = trim( $epl_settings['label_under_offer'] );
763: }
764: if ( empty( $under_offer ) ) {
765: $under_offer = __( 'Under Offer', 'easy-property-listings' );
766: }
767: return $under_offer;
768: }
769:
770: /**
771: * House Categories Options
772: *
773: * @since 1.1
774: * @return array Categories in array.
775: */
776: function epl_listing_load_meta_property_category() {
777: $defaults = array(
778: 'House' => __( 'House', 'easy-property-listings' ),
779: 'Unit' => __( 'Unit', 'easy-property-listings' ),
780: 'Townhouse' => __( 'Townhouse', 'easy-property-listings' ),
781: 'Villa' => __( 'Villa', 'easy-property-listings' ),
782: 'Apartment' => __( 'Apartment', 'easy-property-listings' ),
783: 'Flat' => __( 'Flat', 'easy-property-listings' ),
784: 'Studio' => __( 'Studio', 'easy-property-listings' ),
785: 'Warehouse' => __( 'Warehouse', 'easy-property-listings' ),
786: 'DuplexSemi-detached' => __( 'Duplex Semi-detached', 'easy-property-listings' ),
787: 'Alpine' => __( 'Alpine', 'easy-property-listings' ),
788: 'AcreageSemi-rural' => __( 'Acreage Semi-rural', 'easy-property-listings' ),
789: 'Retirement' => __( 'Retirement', 'easy-property-listings' ),
790: 'BlockOfUnits' => __( 'Block Of Units', 'easy-property-listings' ),
791: 'Terrace' => __( 'Terrace', 'easy-property-listings' ),
792: 'ServicedApartment' => __( 'Serviced Apartment', 'easy-property-listings' ),
793: 'Other' => __( 'Other', 'easy-property-listings' ),
794: );
795: return apply_filters( 'epl_listing_meta_property_category', $defaults );
796: }
797:
798: /**
799: * Custom Meta: Return Value of House Category
800: *
801: * @since 1.1
802: * @param string $key Meta key.
803: * @return string the categories in array
804: */
805: function epl_listing_meta_property_category_value( $key ) {
806: $array = epl_listing_load_meta_property_category();
807: $key = (array) $key;
808: $values = array();
809: foreach ( $key as $single ) {
810: $values[] = array_key_exists( $single, $array ) && ! empty( $array[ $single ] ) ? $array[ $single ] : $single;
811: }
812:
813: $value = implode( ', ', $values );
814:
815: return apply_filters( 'epl_property_category_value', $value );
816: }
817:
818: /**
819: * Custom Meta: Land Categories
820: *
821: * @since 1.1
822: * @return array the categories in array
823: */
824: function epl_listing_load_meta_land_category() {
825: $defaults = array(
826: 'Commercial' => __( 'Commercial', 'easy-property-listings' ),
827: 'Residential' => __( 'Residential', 'easy-property-listings' ),
828: );
829: return apply_filters( 'epl_listing_meta_land_category', $defaults );
830: }
831:
832: /**
833: * Custom Meta: Return Value of Land Category
834: *
835: * @param string $key Meta key.
836: * @return array the categories in array
837: *
838: * @since 1.1.0
839: */
840: function epl_listing_meta_land_category_value( $key ) {
841: $array = epl_listing_load_meta_land_category();
842: $value = array_key_exists( $key, $array ) && ! empty( $array[ $key ] ) ? $array[ $key ] : '';
843:
844: return $value;
845: }
846:
847: /**
848: * Custom Meta: Commercial Categories
849: *
850: * @since 1.1
851: * @return array the categories in array
852: */
853: function epl_listing_load_meta_commercial_category() {
854: $defaults = array(
855: 'Commercial Farming' => __( 'Commercial Farming', 'easy-property-listings' ),
856: 'Land/Development' => __( 'Land/Development', 'easy-property-listings' ),
857: 'Hotel/Leisure' => __( 'Hotel/Leisure', 'easy-property-listings' ),
858: 'Industrial/Warehouse' => __( 'Industrial/Warehouse', 'easy-property-listings' ),
859: 'Medical/Consulting' => __( 'Medical/Consulting', 'easy-property-listings' ),
860: 'Offices' => __( 'Offices', 'easy-property-listings' ),
861: 'Retail' => __( 'Retail', 'easy-property-listings' ),
862: 'Showrooms/Bulky Goods' => __( 'Showrooms/Bulky Goods', 'easy-property-listings' ),
863: 'Other' => __( 'Other', 'easy-property-listings' ),
864: );
865: return apply_filters( 'epl_listing_meta_commercial_category', $defaults );
866: }
867:
868: /**
869: * Custom Meta: Return Value of Commercial Category
870: *
871: * @since 1.1
872: * @param string $key Meta key.
873: * @return array the categories in array
874: */
875: function epl_listing_load_meta_commercial_category_value( $key ) {
876: $array = epl_listing_load_meta_commercial_category();
877:
878: if ( is_array( $key ) ) {
879: $values = array();
880: foreach ( $key as $k ) {
881: $values[] = array_key_exists( $k, $array ) && ! empty( $array[ $k ] ) ? $array[ $k ] : ucfirst( $k );
882: }
883: $value = implode( ', ', $values );
884: } else {
885: $value = array_key_exists( $key, $array ) && ! empty( $array[ $key ] ) ? $array[ $key ] : ucfirst( $key );
886: }
887:
888: return apply_filters( 'epl_meta_commercial_category_value', $value, $key, $array );
889: }
890:
891: /**
892: * Custom Meta: Commercial Rental Period
893: *
894: * @since 2.1
895: * @return array the categories in array
896: */
897: function epl_listing_load_meta_commercial_rent_period() {
898: $defaults = array(
899: 'annual' => __( 'P.A.', 'easy-property-listings' ),
900: 'nnn' => __( 'NNN', 'easy-property-listings' ),
901: 'full-service' => __( 'Full Service', 'easy-property-listings' ),
902: 'gross-lease-rates' => __( 'Gross Lease Rates', 'easy-property-listings' ),
903: );
904: return apply_filters( 'epl_listing_meta_commercial_rent_period', $defaults );
905: }
906:
907: /**
908: * Custom Meta: Return Value of Commercial Rental Period
909: *
910: * @since 2.1
911: * @param string $key Meta key.
912: * @return array the categories in array
913: */
914: function epl_listing_load_meta_commercial_rent_period_value( $key ) {
915: $array = epl_listing_load_meta_commercial_rent_period();
916: $value = array_key_exists( $key, $array ) && ! empty( $array[ $key ] ) ? $array[ $key ] : '';
917:
918: return $value;
919: }
920:
921: /**
922: * Custom Meta: Rural Categories
923: *
924: * @since 1.1
925: * @return all the categories in array
926: */
927: function epl_listing_load_meta_rural_category() {
928: $defaults = array(
929: 'Cropping' => __( 'Cropping', 'easy-property-listings' ),
930: 'Dairy' => __( 'Dairy', 'easy-property-listings' ),
931: 'Farmlet' => __( 'Farmlet', 'easy-property-listings' ),
932: 'Horticulture' => __( 'Horticulture', 'easy-property-listings' ),
933: 'Livestock' => __( 'Livestock', 'easy-property-listings' ),
934: 'Viticulture' => __( 'Viticulture', 'easy-property-listings' ),
935: 'MixedFarming' => __( 'Mixed Farming', 'easy-property-listings' ),
936: 'Lifestyle' => __( 'Lifestyle', 'easy-property-listings' ),
937: 'Other' => __( 'Other', 'easy-property-listings' ),
938: );
939: return apply_filters( 'epl_listing_meta_rural_category', $defaults );
940: }
941:
942: /**
943: * Custom Meta: Return Value of Rural Category
944: *
945: * @since 1.1
946: * @param string $key Meta key.
947: * @return all the categories in array
948: */
949: function epl_listing_load_meta_rural_category_value( $key ) {
950: $array = epl_listing_load_meta_rural_category();
951: $value = array_key_exists( $key, $array ) && ! empty( $array[ $key ] ) ? $array[ $key ] : '';
952:
953: return $value;
954: }
955:
956: /**
957: * REAXML Date Processing Function for WP All Import and FeedSync
958: *
959: * Some imports set the current date instead of the date from the REAXML file.
960: * Usage in WP All Import Post Date field is:
961: * [epl_feedsync_format_date({./@modTime})]
962: *
963: * @since 1.2
964: * @param string $date Date.
965: * @return string formatted date
966: * @revised 3.3
967: */
968: function epl_feedsync_format_date( $date ) {
969: $date_example = '2014-07-22-16:45:56';
970:
971: $tempdate = explode( '-', $date );
972: $date = $tempdate[0];
973: if ( isset( $tempdate[1] ) ) {
974: $date .= '-' . $tempdate[1];
975: }
976: if ( isset( $tempdate[2] ) ) {
977: $date .= '-' . $tempdate[2];
978: }
979: if ( isset( $tempdate[3] ) ) {
980: $date .= ' ' . $tempdate[3];
981: }
982:
983: return gmdate( 'Y-m-d H:i:s', strtotime( $date ) );
984: }
985:
986: /**
987: * REAXML Auction Date Processing Function for WP All Import and FeedSync
988: *
989: * Some imports set the current date instead of the date from the REAXML file.
990: * Usage in WP All Import Post Date field is:
991: * [epl_feedsync_format_date_auction({AUCDATE[1]},{AUC_TIME[1]})]
992: *
993: * @since 3.1.7
994: * @param string $date Date.
995: * @param string $time Time.
996: * @return string formatted date
997: */
998: function epl_feedsync_format_date_auction( $date, $time ) {
999:
1000: $date = str_replace( '/', '-', $date ); // Convert to european date format for strtotime function.
1001: return gmdate( 'Y-M-d H:i:s', strtotime( $date . ' ' . $time ) );
1002: }
1003:
1004: /**
1005: * REAXML Address Sub Number field for title import
1006: * processing Function for WP All Import and FeedSync
1007: *
1008: * This function adds a / after the $value else returns false.
1009: * Usage in WP All Import Post Date field is:
1010: * [epl_feedsync_filter_sub_number({address[1]/subNumber[1]})]
1011: *
1012: * @since 1.3
1013: * @param string $sub_value Address sub value.
1014: * @return string formatted sub number/
1015: */
1016: function epl_feedsync_format_sub_number( $sub_value ) {
1017: if ( $sub_value ) {
1018: $sub_value = $sub_value . '/';
1019: return $sub_value;
1020: }
1021: }
1022:
1023: /**
1024: * REAXML convert currency to integer
1025: *
1026: * Processing Function for WP All Import and FeedSync
1027: *
1028: * @param string $value Value.
1029: * @return float|void Currently as number.
1030: * @since 3.0
1031: */
1032: function epl_feedsync_format_strip_currency( $value ) {
1033: if ( $value ) {
1034: $value = preg_replace( apply_filters( 'epl_feedsync_format_strip_currency_symbol', '/[\$,]/' ), '', $value );
1035: $value = floatval( $value );
1036: return $value;
1037: }
1038: }
1039:
1040: /**
1041: * REAXML convert date/time to adjust for timezone
1042: *
1043: * Processing Function for WP All Import and FeedSync
1044: * [epl_feedsync_switch_date_time({firstDate[1]},"Australia/Perth","Australia/Sydney")]
1045: *
1046: * @param bool $date_time Switch date time.
1047: * @param string $old_time_zone Old Timezone.
1048: * @param string $new_timezone New timezone.
1049: * @param string $format Date format.
1050: *
1051: * @return string
1052: * @throws exception Exception.
1053: * @since 3.0
1054: * @since 3.5.3 Update to return local timestamp.
1055: */
1056: function epl_feedsync_switch_date_time( $date_time = false, $old_time_zone = 'Australia/Perth', $new_timezone = 'Australia/Sydney', $format = 'Y-m-d H:i:s' ) {
1057:
1058: if ( ! $date_time ) {
1059: $date_time = gmdate( 'Y-m-d H:i:s', epl_get_local_timestamp() );
1060: }
1061: if ( ! $old_time_zone ) {
1062: $old_time_zone = 'Australia/Perth';
1063: }
1064: if ( ! $new_timezone ) {
1065: $new_timezone = 'Australia/Sydney';
1066: }
1067:
1068: $schedule_date = new DateTime( $date_time, new DateTimeZone( $new_timezone ) );
1069: $schedule_date->setTimeZone( new DateTimeZone( $old_time_zone ) );
1070: return $schedule_date->format( $format );
1071: }
1072:
1073: /**
1074: * Renders field array to html
1075: *
1076: * @since 2.1
1077: * @param array $field Field array.
1078: * @param string $val Value.
1079: * @revised 3.3
1080: */
1081: function epl_render_html_fields( $field = array(), $val = '' ) {
1082: EPL()->render_fields->render( $field, $val );
1083: }
1084:
1085: /**
1086: * Admin options settings
1087: *
1088: * @since 2.1
1089: * @since 3.5.3 Updated to return local timestamp.
1090: * @since 3.6 Added the Under Offer Price Display setting (display_price_under_offer).
1091: * @since 3.6.1 Under Offer Price Display defaults to Hide the price, as before 3.6.
1092: */
1093: function epl_get_admin_option_fields() {
1094: global $epl_settings;
1095: $opts_epl_gallery_n = array();
1096: for ( $i = 1; $i <= 10; $i++ ) {
1097: $opts_epl_gallery_n[ $i ] = $i;
1098: }
1099:
1100: $opts_epl_property_card_excerpt_length = array();
1101: for ( $i = 10; $i <= 55; $i++ ) {
1102: $opts_epl_property_card_excerpt_length[ $i ] = $i;
1103: }
1104:
1105: $opts_epl_features = array();
1106: for ( $i = 1; $i <= 5; $i++ ) {
1107: $opts_epl_features[ $i ] = $i;
1108: }
1109:
1110: $opts_pages = array( '' => __( 'Select Page', 'easy-property-listings' ) );
1111: $pages = get_pages();
1112:
1113: if ( ! empty( $pages ) ) {
1114: foreach ( $pages as $page ) {
1115: $opts_pages[ $page->ID ] = $page->post_title;
1116: }
1117: }
1118:
1119: $get_google_maps_api_key_uri = '<a target="_blank" href="https://developers.google.com/maps/documentation/javascript/get-api-key">' . __( 'Google Maps API Key', 'easy-property-listings' ) . '</a>';
1120:
1121: $epl_currency_positions = array(
1122: 'before' => __( 'Before - $10', 'easy-property-listings' ),
1123: 'after' => __( 'After - 10$', 'easy-property-listings' ),
1124: );
1125: $epl_currency_types = epl_get_currencies();
1126: $epl_post_types = epl_get_post_types();
1127: if ( ! function_exists( 'get_editable_roles' ) ) {
1128: require_once ABSPATH . '/wp-admin/includes/user.php';
1129: }
1130: $roles = array(
1131: 'level_10' => __( 'Administrator', 'easy-property-listings' ),
1132: 'level_7' => __( 'Editor', 'easy-property-listings' ),
1133: 'level_2' => __( 'Author', 'easy-property-listings' ),
1134: 'level_1' => __( 'Contributor', 'easy-property-listings' ),
1135: 'level_0' => __( 'Subscriber', 'easy-property-listings' ),
1136: );
1137: $fields = array(
1138: array(
1139: 'label' => __( 'Listing Types and Location Taxonomy', 'easy-property-listings' ),
1140: 'class' => 'core',
1141: 'id' => 'general',
1142: 'help' => __( 'Select the listing types you want to enable and press Save Changes. Refresh the page to see your new activated listing types.', 'easy-property-listings' ) . '<hr/>',
1143: 'fields' => array(
1144: array(
1145: 'name' => 'activate_post_types',
1146: 'label' => __( 'Listing Types to Enable', 'easy-property-listings' ),
1147: 'type' => 'checkbox',
1148: 'opts' => $epl_post_types,
1149: 'help' => __( 'Note: If they are not visible on the front end visit Dashboard > Settings > Permalinks and press Save Changes.', 'easy-property-listings' ),
1150: ),
1151:
1152: array(
1153: 'name' => 'label_location',
1154: 'label' => __( 'Location Taxonomy', 'easy-property-listings' ),
1155: 'type' => 'text',
1156: 'help' => __( 'After changing this setting visit Dashboard > Settings > Permalinks to save the settings.', 'easy-property-listings' ),
1157: 'default' => __( 'Location', 'easy-property-listings' ),
1158: ),
1159: ),
1160: ),
1161:
1162: array(
1163: 'label' => __( 'Address', 'easy-property-listings' ),
1164: 'class' => 'core',
1165: 'id' => 'address',
1166: 'help' => __( 'Use these settings to adjust the address labels to suite your location and address format for your listings.', 'easy-property-listings' ) . '<hr/>',
1167: 'fields' => array(
1168:
1169: array(
1170: 'name' => 'label_suburb',
1171: 'label' => __( 'Suburb/Town/City Label', 'easy-property-listings' ),
1172: 'type' => 'text',
1173: 'default' => __( 'Suburb', 'easy-property-listings' ),
1174: ),
1175:
1176: array(
1177: 'name' => 'epl_enable_city_field',
1178: 'label' => __( 'Additional Address Field', 'easy-property-listings' ),
1179: 'type' => 'radio',
1180: 'opts' => array(
1181: 'yes' => __( 'Enable', 'easy-property-listings' ),
1182: 'no' => __( 'Disable', 'easy-property-listings' ),
1183: ),
1184: 'default' => 'no',
1185: 'help' => __( 'Use when you need an additional Municipality/Town/City/Region.', 'easy-property-listings' ),
1186: ),
1187:
1188: array(
1189: 'name' => 'label_city',
1190: 'label' => __( 'Additional Address Field Label', 'easy-property-listings' ),
1191: 'type' => 'text',
1192: 'default' => __( 'City', 'easy-property-listings' ),
1193: ),
1194:
1195: array(
1196: 'name' => 'label_state',
1197: 'label' => __( 'State/Province/Region Label', 'easy-property-listings' ),
1198: 'type' => 'text',
1199: 'default' => __( 'State', 'easy-property-listings' ),
1200: ),
1201:
1202: array(
1203: 'name' => 'label_postcode',
1204: 'label' => __( 'Postcode/ZIP Label', 'easy-property-listings' ),
1205: 'type' => 'text',
1206: 'default' => __( 'Postcode', 'easy-property-listings' ),
1207: ),
1208:
1209: array(
1210: 'name' => 'epl_enable_country_field',
1211: 'label' => __( 'Display Country', 'easy-property-listings' ),
1212: 'type' => 'radio',
1213: 'opts' => array(
1214: 'yes' => __( 'Enable', 'easy-property-listings' ),
1215: 'no' => __( 'Disable', 'easy-property-listings' ),
1216: ),
1217: 'default' => 'no',
1218: 'help' => __( 'Display country with listing address.', 'easy-property-listings' ),
1219: ),
1220:
1221: array(
1222: 'name' => 'epl_default_country',
1223: 'label' => __( 'Default Country', 'easy-property-listings' ),
1224: 'type' => 'select',
1225: 'opts' => epl_get_countries_list(),
1226: 'default' => 'Australia',
1227: 'help' => __( 'This is used for map when listing has no address details', 'easy-property-listings' ),
1228: ),
1229:
1230: ),
1231: ),
1232:
1233: array(
1234: 'label' => __( 'Labels', 'easy-property-listings' ),
1235: 'class' => 'core',
1236: 'id' => 'labels',
1237: 'help' => __( 'Customise the labels that are used to show the status and information on the archive and individual listing pages.', 'easy-property-listings' ) . '<hr/>',
1238: 'fields' => array(
1239:
1240: array(
1241: 'name' => 'label_new',
1242: 'label' => __( 'New/Just Listed Label', 'easy-property-listings' ),
1243: 'type' => 'text',
1244: 'default' => __( 'New', 'easy-property-listings' ),
1245: ),
1246:
1247: array(
1248: 'name' => 'sticker_new_range',
1249: 'label' => __( 'Keep Listings flagged "New" for', 'easy-property-listings' ),
1250: 'type' => 'number',
1251: 'default' => '7',
1252: 'help' => __( 'Listings will have a "NEW" Sticker for the defined number of days.', 'easy-property-listings' ),
1253: ),
1254:
1255: array(
1256: 'name' => 'label_home_open',
1257: 'label' => __( 'Home Open Label', 'easy-property-listings' ),
1258: 'type' => 'text',
1259: 'default' => __( 'Home Open', 'easy-property-listings' ),
1260: ),
1261:
1262: array(
1263: 'name' => 'label_poa',
1264: 'label' => __( 'No Price Label', 'easy-property-listings' ),
1265: 'type' => 'text',
1266: 'default' => __( 'POA', 'easy-property-listings' ),
1267: ),
1268:
1269: array(
1270: 'name' => 'label_under_offer',
1271: 'label' => __( 'Under Offer Label', 'easy-property-listings' ),
1272: 'type' => 'text',
1273: 'default' => __( 'Under Offer', 'easy-property-listings' ),
1274: ),
1275:
1276: array(
1277: 'name' => 'display_price_under_offer',
1278: 'label' => __( 'Under Offer Price Display', 'easy-property-listings' ),
1279: 'type' => 'radio',
1280: 'opts' => array(
1281: 'yes' => __( 'Show the price', 'easy-property-listings' ),
1282: 'no' => __( 'Hide the price', 'easy-property-listings' ),
1283: ),
1284: 'default' => 'no',
1285: 'help' => __( 'Example: Under Offer | $500,000', 'easy-property-listings' ) . ' <a href="' . esc_url( 'https://codex.easypropertylistings.com.au/article/626-under-offer-price-display' ) . '" target="_blank">' . __( 'Read More', 'easy-property-listings' ) . '</a>',
1286: ),
1287:
1288: array(
1289: 'name' => 'label_sold',
1290: 'label' => __( 'Sold Label', 'easy-property-listings' ),
1291: 'type' => 'text',
1292: 'default' => __( 'Sold', 'easy-property-listings' ),
1293: ),
1294:
1295: array(
1296: 'name' => 'label_leased',
1297: 'label' => __( 'Leased Label', 'easy-property-listings' ),
1298: 'type' => 'text',
1299: 'default' => __( 'Leased', 'easy-property-listings' ),
1300: ),
1301:
1302: array(
1303: 'name' => 'label_bond',
1304: 'label' => __( 'Rental Bond/Deposit Label', 'easy-property-listings' ),
1305: 'type' => 'text',
1306: 'default' => __( 'Bond', 'easy-property-listings' ),
1307: ),
1308:
1309: array(
1310: 'name' => 'display_bond',
1311: 'label' => __( 'Rental Bond/Deposit Display', 'easy-property-listings' ),
1312: 'type' => 'radio',
1313: 'opts' => array(
1314: 1 => __( 'Enable', 'easy-property-listings' ),
1315: 0 => __( 'Disable', 'easy-property-listings' ),
1316: ),
1317: 'help' => __( 'Display the Bond/Deposit on rental listings.', 'easy-property-listings' ),
1318: ),
1319: ),
1320: ),
1321:
1322: array(
1323: 'label' => __( 'Listing Single View', 'easy-property-listings' ),
1324: 'class' => 'core',
1325: 'id' => 'general',
1326: 'help' => __( 'Configure the default options when viewing a single listing.', 'easy-property-listings' ) . '<hr/>',
1327: 'fields' => array(
1328: array(
1329: 'name' => 'display_single_gallery',
1330: 'label' => __( 'Automatically display image gallery?', 'easy-property-listings' ),
1331: 'type' => 'radio',
1332: 'opts' => array(
1333: 1 => __( 'Enable', 'easy-property-listings' ),
1334: 0 => __( 'Disable', 'easy-property-listings' ),
1335: ),
1336: 'default' => 1,
1337: 'help' => __( 'Images uploaded and attached to a listing will automatically display on the single listing page.', 'easy-property-listings' ),
1338: ),
1339:
1340: array(
1341: 'name' => 'display_gallery_n',
1342: 'label' => __( 'Gallery columns?', 'easy-property-listings' ),
1343: 'type' => 'select',
1344: 'opts' => $opts_epl_gallery_n,
1345: 'default' => 4,
1346: ),
1347:
1348: array(
1349: 'name' => 'display_feature_columns',
1350: 'label' => __( 'Feature list columns?', 'easy-property-listings' ),
1351: 'type' => 'select',
1352: 'opts' => $opts_epl_features,
1353: 'default' => 2,
1354: ),
1355:
1356: array(
1357: 'name' => 'epl_video_width',
1358: 'label' => __( 'Video width on single listings', 'easy-property-listings' ),
1359: 'type' => 'number',
1360: 'help' => __( 'Width should be in pixels', 'easy-property-listings' ),
1361: ),
1362: ),
1363: ),
1364:
1365: array(
1366: 'label' => __( 'Listing Archive View', 'easy-property-listings' ),
1367: 'class' => 'core',
1368: 'id' => 'general',
1369: 'help' => __( 'Configure the default options for when viewing the archive listing pages.', 'easy-property-listings' ) . '<hr/>',
1370: 'fields' => array(
1371: array(
1372: 'name' => 'display_excerpt_length',
1373: 'label' => __( 'Excerpt words', 'easy-property-listings' ),
1374: 'type' => 'select',
1375: 'opts' => $opts_epl_property_card_excerpt_length,
1376: 'default' => 10,
1377: 'help' => __( 'This is ignored when using manual excerpts.', 'easy-property-listings' ),
1378: ),
1379: array(
1380: 'name' => 'display_archive_view_type',
1381: 'label' => __( 'Listing view type', 'easy-property-listings' ),
1382: 'type' => 'radio',
1383: 'opts' => array(
1384: 'list' => __( 'List', 'easy-property-listings' ),
1385: 'grid' => __( 'Grid', 'easy-property-listings' ),
1386: ),
1387: 'default' => 'list',
1388: ),
1389:
1390: array(
1391: 'name' => 'use_fancy_navigation',
1392: 'label' => __( 'Fancy pagination', 'easy-property-listings' ),
1393: 'type' => 'select',
1394: 'opts' => array(
1395: 0 => __( 'No, use WordPress default pagination', 'easy-property-listings' ),
1396: 1 => __( 'Yes, use fancy navigation', 'easy-property-listings' ),
1397: ),
1398: 'default' => 0,
1399: ),
1400: ),
1401: ),
1402:
1403: array(
1404: 'label' => __( 'Search Widget: Tab Labels', 'easy-property-listings' ),
1405: 'class' => 'core',
1406: 'id' => 'labels',
1407: 'help' => __( 'Customise the tab labels of the EPL - Search Widget or [listing_search] shortcode.', 'easy-property-listings' ) . '<hr/>',
1408: 'fields' => array(
1409: array(
1410: 'name' => 'widget_label_all',
1411: 'label' => __( 'All', 'easy-property-listings' ),
1412: 'type' => 'text',
1413: 'default' => __( 'All', 'easy-property-listings' ),
1414: ),
1415: array(
1416: 'name' => 'widget_label_property',
1417: 'label' => __( 'Property', 'easy-property-listings' ),
1418: 'type' => 'text',
1419: 'default' => __( 'Property', 'easy-property-listings' ),
1420: ),
1421: array(
1422: 'name' => 'widget_label_land',
1423: 'label' => __( 'Land', 'easy-property-listings' ),
1424: 'type' => 'text',
1425: 'default' => __( 'Land', 'easy-property-listings' ),
1426: ),
1427: array(
1428: 'name' => 'widget_label_rental',
1429: 'label' => __( 'Rental', 'easy-property-listings' ),
1430: 'type' => 'text',
1431: 'default' => __( 'Rental', 'easy-property-listings' ),
1432: ),
1433: array(
1434: 'name' => 'widget_label_rural',
1435: 'label' => __( 'Rural', 'easy-property-listings' ),
1436: 'type' => 'text',
1437: 'default' => __( 'Rural', 'easy-property-listings' ),
1438: ),
1439: array(
1440: 'name' => 'widget_label_commercial',
1441: 'label' => __( 'Commercial', 'easy-property-listings' ),
1442: 'type' => 'text',
1443: 'default' => __( 'Commercial', 'easy-property-listings' ),
1444: ),
1445: array(
1446: 'name' => 'widget_label_commercial_land',
1447: 'label' => __( 'Commercial Land', 'easy-property-listings' ),
1448: 'type' => 'text',
1449: 'default' => __( 'Commercial Land', 'easy-property-listings' ),
1450: ),
1451: array(
1452: 'name' => 'widget_label_business',
1453: 'label' => __( 'Business', 'easy-property-listings' ),
1454: 'type' => 'text',
1455: 'default' => __( 'Business', 'easy-property-listings' ),
1456: ),
1457: ),
1458: ),
1459:
1460: array(
1461: 'label' => __( 'Listings', 'easy-property-listings' ),
1462: 'class' => 'core',
1463: 'id' => 'admin_general',
1464: 'help' => __( 'Use the following settings to change how the Dashboard > Property or any listing of the types you have enabled display.', 'easy-property-listings' ) . '<hr/>',
1465: 'fields' => array(
1466:
1467: array(
1468: 'name' => 'epl_max_graph_sales_price',
1469: 'label' => __( 'Graph Max', 'easy-property-listings' ),
1470: 'type' => 'number',
1471: 'default' => '2000000',
1472: 'help' => __( 'Used for bar chart display on listings for sale.', 'easy-property-listings' ),
1473: ),
1474:
1475: array(
1476: 'name' => 'epl_max_graph_rent_price',
1477: 'label' => __( 'Graph Rental Max', 'easy-property-listings' ),
1478: 'type' => 'number',
1479: 'default' => '2000',
1480: 'help' => __( 'Rental range.', 'easy-property-listings' ),
1481: ),
1482:
1483: array(
1484: 'name' => 'epl_admin_thumb_size',
1485: 'label' => __( 'Image size', 'easy-property-listings' ),
1486: 'type' => 'radio',
1487: 'opts' => array(
1488: 'admin-list-thumb' => __( '100 X 100', 'easy-property-listings' ),
1489: 'epl-image-medium-crop' => __( '300 X 200', 'easy-property-listings' ),
1490: ),
1491: 'default' => 'admin-list-thumb',
1492: 'help' => __( 'Size of the image shown in listing columns in admin area', 'easy-property-listings' ),
1493: ),
1494:
1495: array(
1496: 'name' => 'admin_unique_id',
1497: 'label' => __( 'Unique Listing ID column', 'easy-property-listings' ),
1498: 'type' => 'radio',
1499: 'opts' => array(
1500: 1 => __( 'Enable', 'easy-property-listings' ),
1501: 0 => __( 'Disable', 'easy-property-listings' ),
1502: ),
1503: 'default' => 0,
1504: ),
1505:
1506: array(
1507: 'name' => 'debug',
1508: 'label' => __( 'Geocode Lat/Long results column', 'easy-property-listings' ),
1509: 'type' => 'radio',
1510: 'opts' => array(
1511: 1 => __( 'Enable', 'easy-property-listings' ),
1512: 0 => __( 'Disable', 'easy-property-listings' ),
1513: ),
1514: 'default' => 0,
1515: ),
1516:
1517: array(
1518: 'name' => 'display_hidden_fields',
1519: 'label' => __( 'Display Hidden Fields', 'easy-property-listings' ),
1520: 'type' => 'radio',
1521: 'opts' => array(
1522: 1 => __( 'Enable', 'easy-property-listings' ),
1523: 0 => __( 'Disable', 'easy-property-listings' ),
1524: ),
1525: 'help' => __( 'Display hidden fields on the edit listing screen.', 'easy-property-listings' ),
1526: 'default' => 0,
1527: ),
1528: ),
1529: ),
1530:
1531: array(
1532: 'label' => __( 'Theme Setup', 'easy-property-listings' ),
1533: 'class' => 'core',
1534: 'id' => 'theme_setup',
1535: 'help' => __( 'The following settings will use your theme templates to generate your listing pages. If your listings appear too wide or your sidebar is in the wrong place enable theme compatibility. When this is enabled you can use the included shortcodes like [listing post_type="property" tools_top="on"] to display your listings with sorting and grid options.', 'easy-property-listings' ) . '<hr/>',
1536: 'fields' => array(
1537:
1538: array(
1539: 'name' => 'epl_feeling_lucky',
1540: 'label' => __( 'Theme Compatibility', 'easy-property-listings' ),
1541: 'type' => 'radio',
1542: 'opts' => array(
1543: 'on' => __( 'Enable', 'easy-property-listings' ),
1544: 'off' => __( 'Disable', 'easy-property-listings' ),
1545: ),
1546: 'default' => 'off',
1547: 'help' => __( 'When using iThemes, Genesis frameworks or your listings look good, leave this disabled.', 'easy-property-listings' ),
1548: ),
1549: ),
1550: ),
1551:
1552: array(
1553: 'label' => __( 'Theme Setup: Featured Images', 'easy-property-listings' ),
1554: 'class' => 'core',
1555: 'id' => 'theme_setup_featured_images',
1556: 'help' => __( 'Some WordPress themes automatically display featured images on posts and pages which may cause you to see double on your listings. Use the following settings to adjust the featured image behaviour.', 'easy-property-listings' ) . '<hr/>',
1557: 'fields' => array(
1558:
1559: array(
1560: 'name' => 'help_lucky_theme_featured_image',
1561: 'type' => 'help',
1562: 'content' => __( 'Theme Featured Image Settings', 'easy-property-listings' ),
1563: ),
1564:
1565: array(
1566: 'name' => 'epl_lucky_disable_theme_single_thumb',
1567: 'label' => __( 'Single Listing', 'easy-property-listings' ),
1568: 'type' => 'checkbox_option',
1569: 'opts' => array(
1570: 'on' => __( 'Disable', 'easy-property-listings' ),
1571: ),
1572: 'default' => 'off',
1573: ),
1574:
1575: array(
1576: 'name' => 'epl_lucky_disable_archive_thumb',
1577: 'label' => __( 'Archive Listing', 'easy-property-listings' ),
1578: 'type' => 'checkbox_option',
1579: 'opts' => array(
1580: 'on' => __( 'Disable', 'easy-property-listings' ),
1581: ),
1582: 'default' => 'off',
1583: ),
1584:
1585: array(
1586: 'name' => 'help_lucky_epl_featured_image',
1587: 'type' => 'help',
1588: 'content' => '<hr/>' . __( 'Easy Property Listings Featured Image Settings', 'easy-property-listings' ),
1589: ),
1590:
1591: array(
1592: 'name' => 'epl_lucky_disable_single_thumb',
1593: 'label' => __( 'Single Listing', 'easy-property-listings' ),
1594: 'type' => 'checkbox_option',
1595: 'opts' => array(
1596: 'on' => __( 'Disable', 'easy-property-listings' ),
1597: ),
1598: 'default' => 'off',
1599: ),
1600:
1601: array(
1602: 'name' => 'epl_lucky_disable_epl_archive_thumb',
1603: 'label' => __( 'Archive Listing', 'easy-property-listings' ),
1604: 'type' => 'checkbox_option',
1605: 'opts' => array(
1606: 'on' => __( 'Disable', 'easy-property-listings' ),
1607: ),
1608: 'default' => 'off',
1609: ),
1610: ),
1611: ),
1612:
1613: array(
1614: 'label' => __( 'Currency', 'easy-property-listings' ),
1615: 'class' => 'core',
1616: 'id' => 'currency',
1617: // Translators: Currency article link.
1618: 'help' => sprintf( __( 'Select your default currency. If you can not find the currency you are looking for, you can add additional currencies with a filter, <a href="%s" target="_blank">visit the codex to see how</a>.', 'easy-property-listings' ), esc_url( 'https://codex.easypropertylistings.com.au/article/153-eplgetcurrencies' ) ) . '<hr/>',
1619: 'fields' => array(
1620: array(
1621: 'name' => 'currency',
1622: 'label' => __( 'Currency Type', 'easy-property-listings' ),
1623: 'type' => 'select',
1624: 'opts' => $epl_currency_types,
1625: ),
1626:
1627: array(
1628: 'name' => 'currency_position',
1629: 'label' => __( 'Symbol Position', 'easy-property-listings' ),
1630: 'type' => 'select',
1631: 'opts' => $epl_currency_positions,
1632: ),
1633:
1634: array(
1635: 'name' => 'currency_thousands_separator',
1636: 'label' => __( 'Thousands Separator', 'easy-property-listings' ),
1637: 'type' => 'text',
1638: ),
1639:
1640: array(
1641: 'name' => 'currency_decimal_separator',
1642: 'label' => __( 'Decimal Separator', 'easy-property-listings' ),
1643: 'type' => 'text',
1644: ),
1645: ),
1646: ),
1647:
1648: array(
1649: 'label' => __( 'Inspection Date & Time Format', 'easy-property-listings' ),
1650: 'class' => 'core',
1651: 'id' => 'inspection_date_time',
1652: 'help' => __( 'These settings allow you to control how your inspection times display by default.', 'easy-property-listings' ) . '<hr/>',
1653: 'fields' => array(
1654: array(
1655: 'name' => 'inspection_date_format',
1656: 'label' => __( 'Date Format', 'easy-property-listings' ),
1657: 'type' => 'radio',
1658: 'opts' => array(
1659:
1660: 'd-M-Y' => gmdate( 'd-M-Y', epl_get_local_timestamp() ),
1661: 'l, dS F' => gmdate( 'l, dS F', epl_get_local_timestamp() ),
1662: 'D d M' => gmdate( 'D d M', epl_get_local_timestamp() ),
1663: 'custom_inspection_date_format' => __( 'Custom', 'easy-property-listings' ),
1664:
1665: ),
1666: ),
1667: array(
1668: 'name' => 'custom_inspection_date_format',
1669: 'label' => __( 'Custom Date Format', 'easy-property-listings' ),
1670: 'type' => 'text',
1671: ),
1672: array(
1673: 'name' => 'inspection_time_format',
1674: 'label' => __( 'Time Format', 'easy-property-listings' ),
1675: 'type' => 'radio',
1676: 'opts' => array(
1677:
1678: 'h:i A' => gmdate( 'h:i A', epl_get_local_timestamp() ),
1679: 'h:i a' => gmdate( 'h:i a', epl_get_local_timestamp() ),
1680: 'H:i' => gmdate( 'h:i', epl_get_local_timestamp() ) . __( ' ( 24 Hours Format ) ', 'easy-property-listings' ),
1681: 'custom_inspection_time_format' => __( 'Custom', 'easy-property-listings' ),
1682:
1683: ),
1684: ),
1685: array(
1686: 'name' => 'custom_inspection_time_format',
1687: 'label' => __( 'Custom Time Format', 'easy-property-listings' ),
1688: 'type' => 'text',
1689: ),
1690: ),
1691: ),
1692:
1693: array(
1694: 'label' => __( 'Contact Settings', 'easy-property-listings' ),
1695: 'class' => 'core',
1696: 'id' => 'contact',
1697: 'help' => __( 'You can allow access to the Contacts system for logged in users.', 'easy-property-listings' ) . '<hr/>',
1698: 'fields' => array(
1699: array(
1700: 'name' => 'min_contact_access',
1701: 'label' => __( 'Contact Access Level', 'easy-property-listings' ),
1702: 'type' => 'radio',
1703: 'opts' => $roles,
1704: ),
1705:
1706: ),
1707: 'default' => 'administrator',
1708: ),
1709:
1710: array(
1711: 'label' => __( 'Reports Settings', 'easy-property-listings' ),
1712: 'class' => 'core',
1713: 'id' => 'reports',
1714: 'help' => __( 'You can allow access to the Reports system for logged in users.', 'easy-property-listings' ) . '<hr/>',
1715:
1716: 'fields' => array(
1717: array(
1718: 'name' => 'min_reports_access',
1719: 'label' => __( 'Reports Access Level', 'easy-property-listings' ),
1720: 'type' => 'radio',
1721: 'opts' => $roles,
1722: ),
1723:
1724: ),
1725: 'default' => 'administrator',
1726: ),
1727:
1728: array(
1729: 'label' => __( 'Advanced Settings', 'easy-property-listings' ),
1730: 'class' => 'core',
1731: 'id' => 'advanced',
1732: // translators: EPL site link.
1733: 'help' => sprintf( __( 'Additional settings to control how Easy Property Listings works. For even more advanced filters and hooks, <a href="%s" target="_blank">visit the codex</a>.', 'easy-property-listings' ), esc_url( 'https://codex.easypropertylistings.com.au/' ) ) . '<hr/>',
1734: 'fields' => array(
1735: array(
1736: 'name' => 'epl_use_core_css',
1737: 'label' => __( 'Disable Styles', 'easy-property-listings' ),
1738: 'type' => 'checkbox_option',
1739: 'opts' => array(
1740: 'on' => __( 'Yes', 'easy-property-listings' ),
1741: ),
1742: 'default' => 'off',
1743: 'help' => __( 'Check this to disable all elements.', 'easy-property-listings' ),
1744: ),
1745:
1746: array(
1747: 'name' => 'epl_css_legacy',
1748: 'label' => __( 'Legacy Styles', 'easy-property-listings' ),
1749: 'type' => 'checkbox_option',
1750: 'opts' => array(
1751: 'on' => __( 'Enable', 'easy-property-listings' ),
1752: ),
1753: 'default' => 'off',
1754: 'help' => __( 'Check this to enable legacy css styles.', 'easy-property-listings' ),
1755: ),
1756:
1757: array(
1758: 'name' => 'epl_css_enhanced',
1759: 'label' => __( 'Enhanced Styles', 'easy-property-listings' ),
1760: 'type' => 'checkbox_option',
1761: 'opts' => array(
1762: 'on' => __( 'Enable', 'easy-property-listings' ),
1763: ),
1764: 'default' => 'off',
1765: 'help' => __( 'Check this to enable enhanced structural css styles. This implements inline-block mode for a better grid format on your listings.', 'easy-property-listings' ),
1766: ),
1767:
1768: array(
1769: 'name' => 'epl_icons_svg_listings',
1770: 'label' => __( 'SVG Icons for Listings', 'easy-property-listings' ),
1771: 'type' => 'checkbox_option',
1772: 'opts' => array(
1773: 'on' => __( 'Enable', 'easy-property-listings' ),
1774: ),
1775: 'default' => 'off',
1776: 'help' => __( 'Check this to enable SVG icons on listings.', 'easy-property-listings' ),
1777: ),
1778:
1779: array(
1780: 'name' => 'epl_icons_svg_author',
1781: 'label' => __( 'SVG Icons for Author Social Links', 'easy-property-listings' ),
1782: 'type' => 'checkbox_option',
1783: 'opts' => array(
1784: 'on' => __( 'Enable', 'easy-property-listings' ),
1785: ),
1786: 'default' => 'off',
1787: 'help' => __( 'Check this to enable SVG icons on author social links.', 'easy-property-listings' ),
1788: ),
1789:
1790: array(
1791: 'name' => 'epl_disable_google_api',
1792: 'label' => __( 'Google Maps API', 'easy-property-listings' ),
1793: 'type' => 'radio',
1794: 'opts' => array(
1795: '' => __( 'Enable', 'easy-property-listings' ),
1796: 'on' => __( 'Disable', 'easy-property-listings' ),
1797: ),
1798: 'default' => '',
1799: 'help' => __( 'Set to disabled if Google Maps API has already been loaded in your theme or other plugin.', 'easy-property-listings' ),
1800:
1801: ),
1802:
1803: array(
1804: 'name' => 'epl_google_api_key',
1805: 'label' => __( 'Google Maps API Key', 'easy-property-listings' ),
1806: 'type' => 'text',
1807: // translators: google map register key link.
1808: 'help' => sprintf( __( 'Register for a %s here.', 'easy-property-listings' ), $get_google_maps_api_key_uri ),
1809: ),
1810:
1811: array(
1812: 'name' => 'epl_plugin_mode',
1813: 'label' => __( 'Mode', 'easy-property-listings' ),
1814: 'type' => 'radio',
1815: 'opts' => array(
1816: 'development' => __( 'Development', 'easy-property-listings' ),
1817: 'production' => __( 'Production', 'easy-property-listings' ),
1818: ),
1819: 'help' => __( 'Production mode enqueue minified js & css for faster page loads.', 'easy-property-listings' ),
1820: 'default' => 'production',
1821: ),
1822:
1823: array(
1824: 'name' => 'uninstall_on_delete',
1825: 'label' => __( 'Remove Data on Uninstall?', 'easy-property-listings' ),
1826: 'type' => 'radio',
1827: 'opts' => array(
1828: 1 => __( 'Enable', 'easy-property-listings' ),
1829: 0 => __( 'Disable', 'easy-property-listings' ),
1830: ),
1831: 'help' => __( 'Select Enable if you would like EPL to completely remove all of its data when the plugin is deleted.', 'easy-property-listings' ),
1832: 'default' => 0,
1833: ),
1834: ),
1835: ),
1836:
1837: );
1838:
1839: if ( did_action( 'elementor/loaded' ) ) {
1840: // One "archive page" dropdown per active listing type, so each type can
1841: // use its own Elementor archive design. Blank = fall back to the single
1842: // site-wide "Listings Archive Page" chosen above.
1843: $epl_archive_type_fields = array();
1844: $epl_archive_type_opts = array( '' => __( 'Use Default', 'easy-property-listings' ) ) + $opts_pages;
1845:
1846: foreach ( epl_get_active_post_types() as $epl_archive_type => $epl_archive_type_label ) {
1847: $epl_archive_type_fields[] = array(
1848: 'name' => 'epl_archive_page_id_' . $epl_archive_type,
1849: /* translators: %s: listing type label, e.g. Residential. */
1850: 'label' => sprintf( __( '%s Archive Page', 'easy-property-listings' ), $epl_archive_type_label ),
1851: 'type' => 'select',
1852: 'opts' => $epl_archive_type_opts,
1853: 'default' => '',
1854: );
1855: }
1856:
1857: $fields[] = array(
1858: 'label' => __( 'Elementor Templates', 'easy-property-listings' ),
1859: 'class' => 'core',
1860: 'id' => 'elementor-templates',
1861: 'help' => __( 'Design listing pages in Elementor (beta).', 'easy-property-listings' ) . ' <a href="' . esc_url( 'https://codex.easypropertylistings.com.au/article/676-elementor-templates-settings' ) . '" target="_blank">' . __( 'Read More', 'easy-property-listings' ) . '</a><hr/>',
1862: 'fields' => array_merge( array(
1863: array(
1864: 'type' => 'help',
1865: 'name' => 'epl_elementor_templates_help',
1866: 'content' => sprintf(
1867: '<p><a class="button" href="%1$s" target="_blank">%2$s</a> &nbsp; <a class="button" href="%3$s" target="_blank">%4$s</a></p>',
1868: esc_url( admin_url( 'edit.php?post_type=elementor_library&elementor_library_type=epl-single' ) ),
1869: esc_html__( 'View Single Listing Templates', 'easy-property-listings' ),
1870: esc_url( admin_url( 'edit.php?post_type=elementor_library&elementor_library_type=epl-loop-card' ) ),
1871: esc_html__( 'View Listing Card Templates', 'easy-property-listings' )
1872: ),
1873: ),
1874:
1875: array(
1876: 'name' => 'epl_archive_page_enabled',
1877: 'label' => __( 'Use An Elementor Page As The Archive', 'easy-property-listings' ),
1878: 'type' => 'radio',
1879: 'opts' => array(
1880: 'yes' => __( 'Enable', 'easy-property-listings' ),
1881: 'no' => __( 'Disable', 'easy-property-listings' ),
1882: ),
1883: 'default' => 'no',
1884: 'help' => __( 'Show your Elementor page instead of the listings archive.', 'easy-property-listings' ),
1885: ),
1886:
1887: array(
1888: 'name' => 'epl_archive_page_id',
1889: 'label' => __( 'Listings Archive Page', 'easy-property-listings' ),
1890: 'type' => 'select',
1891: 'opts' => $opts_pages,
1892: 'default' => '',
1893: 'help' => __( 'The page needs the Listings Results widget.', 'easy-property-listings' ),
1894: ),
1895:
1896: array(
1897: 'type' => 'help',
1898: 'name' => 'epl_archive_page_per_type_help',
1899: 'content' => '<hr/><p><strong>' . esc_html__( 'Per Listing Type Archive Pages', 'easy-property-listings' ) . '</strong><br/>'
1900: . esc_html__( 'Optional.', 'easy-property-listings' ) . '</p>',
1901: ),
1902: ),
1903: $epl_archive_type_fields,
1904: array(
1905: array(
1906: 'name' => 'epl_archive_page_apply_search',
1907: 'label' => __( 'Apply To Search Results', 'easy-property-listings' ),
1908: 'type' => 'radio',
1909: 'opts' => array(
1910: 'yes' => __( 'Enable', 'easy-property-listings' ),
1911: 'no' => __( 'Disable', 'easy-property-listings' ),
1912: ),
1913: 'default' => 'yes',
1914: ),
1915:
1916: array(
1917: 'name' => 'epl_archive_page_apply_taxonomy',
1918: 'label' => __( 'Apply To Location/Feature Archives', 'easy-property-listings' ),
1919: 'type' => 'radio',
1920: 'opts' => array(
1921: 'yes' => __( 'Enable', 'easy-property-listings' ),
1922: 'no' => __( 'Disable', 'easy-property-listings' ),
1923: ),
1924: 'default' => 'yes',
1925: ),
1926: ) ),
1927: );
1928: }
1929:
1930: if ( defined( 'EPL_BETA_VERSIONS' ) && true === EPL_BETA_VERSIONS ) {
1931: $fields[] = array(
1932: 'label' => __( 'Beta Versions', 'easy-property-listings' ),
1933: 'class' => 'core',
1934: 'id' => 'beta-versions',
1935: 'fields' => array(
1936: array(
1937: 'name' => 'enabled_betas',
1938: 'label' => __( 'Enable Beta Versions', 'easy-property-listings' ),
1939: 'type' => 'checkbox',
1940: 'opts' => epl_get_beta_enabled_extensions(),
1941: 'help' => __( 'Checking any of the checkboxes will opt you in to receive pre-release update notifications. You can opt-out at any time. Pre-release updates do not install automatically, you will still have the opportunity to ignore update notifications.', 'easy-property-listings' ),
1942: ),
1943:
1944: ),
1945: );
1946: }
1947:
1948: $fields = apply_filters( 'epl_display_options_filter', $fields );
1949: return $fields;
1950: }
1951:
1952: /**
1953: * Sold status filter
1954: *
1955: * @since 2.1.11
1956: */
1957: function epl_sold_label_status_filter_callback() {
1958: global $epl_settings;
1959: $epl_settings['label_sold'] = ! isset( $epl_settings['label_sold'] ) ? '' : $epl_settings['label_sold'];
1960: $sold_label = 'Sold' !== $epl_settings['label_sold'] || ! empty( $epl_settings['label_sold'] ) ? $epl_settings['label_sold'] : __( 'Sold', 'easy-property-listings' );
1961: return $sold_label;
1962: }
1963: add_filter( 'epl_sold_label_status_filter', 'epl_sold_label_status_filter_callback' );
1964:
1965: /**
1966: * Under Offer status filter
1967: *
1968: * @since 2.1.11
1969: */
1970: function epl_under_offer_label_status_filter_callback() {
1971: global $epl_settings;
1972: $epl_settings['label_under_offer'] = ! isset( $epl_settings['label_under_offer'] ) ? '' : $epl_settings['label_under_offer'];
1973: $under_offer_label = 'Under Offer' !== $epl_settings['label_under_offer'] || ! empty( $epl_settings['label_under_offer'] ) ? $epl_settings['label_under_offer'] : __( 'Under Offer', 'easy-property-listings' );
1974: return $under_offer_label;
1975: }
1976: add_filter( 'epl_under_offer_label_status_filter', 'epl_under_offer_label_status_filter_callback' );
1977:
1978: /**
1979: * Leased status filter
1980: *
1981: * @since 2.1.11
1982: */
1983: function epl_leased_label_status_filter_callback() {
1984: global $epl_settings;
1985: $epl_settings['label_leased'] = ! isset( $epl_settings['label_leased'] ) ? '' : $epl_settings['label_leased'];
1986: $leased_label = 'Leased' !== $epl_settings['label_leased'] || ! empty( $epl_settings['label_leased'] ) ? $epl_settings['label_leased'] : __( 'Leased', 'easy-property-listings' );
1987: return $leased_label;
1988: }
1989: add_filter( 'epl_leased_label_status_filter', 'epl_leased_label_status_filter_callback' );
1990:
1991: /**
1992: * Run a listing query, with its result cached across page loads
1993: *
1994: * For queries whose results only change when listings change, such as the values in the
1995: * search dropdowns. The result is remembered for the rest of the page load and saved as a
1996: * transient for 12 hours (filter epl_listing_query_cache_expiration).
1997: *
1998: * When listings change, visitors keep getting the cached results while a background job
1999: * (WP-Cron) rebuilds every query visitors have used, then the site switches to the new
2000: * results, so no visitor waits for the rebuild. If the rebuild hasn't run within 10 minutes
2001: * (filter epl_listing_query_cache_stale_limit), the next page load rebuilds as it goes.
2002: *
2003: * @param string $sql A prepared SQL query.
2004: * @param string $return_type col for $wpdb->get_col(), results for $wpdb->get_results().
2005: *
2006: * @return array
2007: *
2008: * @since 3.6
2009: */
2010: function epl_listing_query_cache( $sql, $return_type = 'col' ) {
2011: static $memory = array();
2012: static $checked = false;
2013:
2014: $key = md5( $return_type . '|' . $sql );
2015:
2016: if ( isset( $memory[ $key ] ) ) {
2017: return $memory[ $key ];
2018: }
2019:
2020: /**
2021: * Filters whether listing query results are cached across page loads.
2022: *
2023: * @since 3.6
2024: *
2025: * @param bool $enabled Default true.
2026: */
2027: $enabled = (bool) apply_filters( 'epl_listing_query_cache_enabled', true );
2028:
2029: if ( ! $enabled ) {
2030: $memory[ $key ] = epl_listing_query_run( $sql, $return_type );
2031: return $memory[ $key ];
2032: }
2033:
2034: // Listings changed and the background rebuild hasn't run in time: stop serving old results.
2035: if ( ! $checked ) {
2036: $checked = true;
2037: $stale = (int) get_option( 'epl_listing_query_cache_stale', 0 );
2038:
2039: /**
2040: * Filters how long old results may be served after listings change, in seconds,
2041: * while waiting for the background rebuild.
2042: *
2043: * @since 3.6
2044: *
2045: * @param int $limit Default 10 minutes.
2046: */
2047: if ( $stale && time() - $stale > (int) apply_filters( 'epl_listing_query_cache_stale_limit', 10 * MINUTE_IN_SECONDS ) ) {
2048: epl_flush_listing_query_cache( true );
2049: }
2050: }
2051:
2052: $transient = epl_listing_query_cache_transient( $key );
2053: $result = get_transient( $transient );
2054:
2055: if ( ! is_array( $result ) ) {
2056: $result = epl_listing_query_run( $sql, $return_type );
2057: set_transient( $transient, $result, epl_listing_query_cache_expiration() );
2058: epl_listing_query_cache_remember( $key, $sql, $return_type );
2059: }
2060:
2061: $memory[ $key ] = $result;
2062:
2063: return $result;
2064: }
2065:
2066: /**
2067: * Run a listing query without the cache
2068: *
2069: * @param string $sql A prepared SQL query.
2070: * @param string $return_type col or results.
2071: *
2072: * @return array
2073: *
2074: * @since 3.6
2075: */
2076: function epl_listing_query_run( $sql, $return_type = 'col' ) {
2077: global $wpdb;
2078:
2079: $result = 'results' === $return_type ? $wpdb->get_results( $sql ) : $wpdb->get_col( $sql ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.DirectDatabaseQuery, PluginCheck.Security.DirectDB.UnescapedDBParameter -- $sql is prepared by the caller.
2080:
2081: return is_array( $result ) ? $result : array();
2082: }
2083:
2084: /**
2085: * Transient name for a cached listing query
2086: *
2087: * @param string $key Query key (md5 of the return type and SQL).
2088: * @param int|null $version Cache version, the current one by default.
2089: *
2090: * @return string
2091: *
2092: * @since 3.6
2093: */
2094: function epl_listing_query_cache_transient( $key, $version = null ) {
2095: if ( null === $version ) {
2096: $version = (int) get_option( 'epl_listing_query_cache_version', 1 );
2097: }
2098: return 'epl_lqc_' . md5( $version . '|' . $key );
2099: }
2100:
2101: /**
2102: * How long listing query results are cached, in seconds
2103: *
2104: * @return int
2105: *
2106: * @since 3.6
2107: */
2108: function epl_listing_query_cache_expiration() {
2109: /**
2110: * Filters how long listing query results are cached, in seconds.
2111: *
2112: * @since 3.6
2113: *
2114: * @param int $expiration Default 12 hours.
2115: */
2116: return (int) apply_filters( 'epl_listing_query_cache_expiration', 12 * HOUR_IN_SECONDS );
2117: }
2118:
2119: /**
2120: * Remember a query visitors use, so the background rebuild can refresh it
2121: *
2122: * Keeps up to 300 queries; ones unused for 14 days are dropped by the rebuild.
2123: *
2124: * @param string $key Query key.
2125: * @param string $sql A prepared SQL query.
2126: * @param string $return_type col or results.
2127: *
2128: * @return void
2129: *
2130: * @since 3.6
2131: */
2132: function epl_listing_query_cache_remember( $key, $sql, $return_type ) {
2133: $queries = get_option( 'epl_listing_query_cache_queries', array() );
2134: $queries = is_array( $queries ) ? $queries : array();
2135:
2136: // Write at most once a day per query.
2137: if ( isset( $queries[ $key ] ) && $queries[ $key ]['used'] > time() - DAY_IN_SECONDS ) {
2138: return;
2139: }
2140:
2141: $queries[ $key ] = array(
2142: 'sql' => $sql,
2143: 'return' => $return_type,
2144: 'used' => time(),
2145: );
2146:
2147: if ( count( $queries ) > 300 ) {
2148: uasort(
2149: $queries,
2150: function ( $a, $b ) {
2151: return $b['used'] - $a['used'];
2152: }
2153: );
2154: $queries = array_slice( $queries, 0, 300, true );
2155: }
2156:
2157: update_option( 'epl_listing_query_cache_queries', $queries, false );
2158: }
2159:
2160: /**
2161: * Refresh the cached listing query results
2162: *
2163: * By default this marks the cache as out of date and starts the background rebuild:
2164: * visitors keep getting the current results until it finishes. With $now true, the
2165: * cache is cleared straight away and the next page load rebuilds as it goes. Call it
2166: * after changing listings directly in the database.
2167: *
2168: * @param bool $now Clear now instead of rebuilding in the background.
2169: *
2170: * @return void
2171: *
2172: * @since 3.6
2173: */
2174: function epl_flush_listing_query_cache( $now = false ) {
2175: if ( $now ) {
2176: $old_version = (int) get_option( 'epl_listing_query_cache_version', 1 );
2177: update_option( 'epl_listing_query_cache_version', $old_version + 1, true );
2178: delete_option( 'epl_listing_query_cache_stale' );
2179: epl_delete_listing_query_cache_version( $old_version );
2180: return;
2181: }
2182:
2183: if ( ! get_option( 'epl_listing_query_cache_stale' ) ) {
2184: update_option( 'epl_listing_query_cache_stale', time(), true );
2185: }
2186:
2187: if ( ! wp_next_scheduled( 'epl_listing_query_cache_rebuild' ) ) {
2188: wp_schedule_single_event( time(), 'epl_listing_query_cache_rebuild' );
2189: }
2190:
2191: // Start the rebuild now, without waiting for the next visitor (a background request).
2192: if ( ! wp_doing_cron() && function_exists( 'spawn_cron' ) ) {
2193: spawn_cron();
2194: }
2195: }
2196:
2197: /**
2198: * Background rebuild of the listing query cache (WP-Cron)
2199: *
2200: * Runs every query visitors have used into a new cache version, then switches the site
2201: * to it. If listings changed again while it ran, it schedules another rebuild.
2202: *
2203: * @return void
2204: *
2205: * @since 3.6
2206: */
2207: function epl_rebuild_listing_query_cache() {
2208: $started = time();
2209: $version = (int) get_option( 'epl_listing_query_cache_version', 1 ) + 1;
2210: $queries = get_option( 'epl_listing_query_cache_queries', array() );
2211: $queries = is_array( $queries ) ? $queries : array();
2212:
2213: if ( function_exists( 'set_time_limit' ) ) {
2214: set_time_limit( 600 ); // phpcs:ignore Squiz.PHP.DiscouragedFunctions.Discouraged
2215: }
2216:
2217: foreach ( $queries as $key => $query ) {
2218: if ( $query['used'] < $started - 14 * DAY_IN_SECONDS ) {
2219: unset( $queries[ $key ] );
2220: continue;
2221: }
2222: set_transient( epl_listing_query_cache_transient( $key, $version ), epl_listing_query_run( $query['sql'], $query['return'] ), epl_listing_query_cache_expiration() );
2223: }
2224:
2225: update_option( 'epl_listing_query_cache_queries', $queries, false );
2226: update_option( 'epl_listing_query_cache_version', $version, true );
2227: epl_delete_listing_query_cache_version( $version - 1, $queries );
2228:
2229: // Listings changed again while rebuilding: go again.
2230: if ( (int) get_option( 'epl_listing_query_cache_stale', 0 ) >= $started ) {
2231: wp_schedule_single_event( time(), 'epl_listing_query_cache_rebuild' );
2232: } else {
2233: delete_option( 'epl_listing_query_cache_stale' );
2234: }
2235: }
2236: add_action( 'epl_listing_query_cache_rebuild', 'epl_rebuild_listing_query_cache' );
2237:
2238: /**
2239: * Delete the cached results of an old cache version
2240: *
2241: * Without this, every refresh left a full copy of the old results in the database until
2242: * they expired (12 hours), which adds up on sites without an object cache.
2243: *
2244: * @param int $version Cache version to delete.
2245: * @param array|null $queries Remembered queries, read from the option when null.
2246: *
2247: * @return void
2248: *
2249: * @since 3.6 Added: old copies are deleted as soon as a refresh finishes.
2250: */
2251: function epl_delete_listing_query_cache_version( $version, $queries = null ) {
2252: if ( null === $queries ) {
2253: $queries = get_option( 'epl_listing_query_cache_queries', array() );
2254: }
2255:
2256: foreach ( array_keys( (array) $queries ) as $key ) {
2257: delete_transient( epl_listing_query_cache_transient( $key, (int) $version ) );
2258: }
2259: }
2260:
2261: /**
2262: * Does a change to this meta key leave the listing query cache as it is?
2263: *
2264: * Hidden meta keys (starting with an underscore, like the _edit_lock WordPress saves
2265: * every minute while a listing is open in the editor) are never used by the cached
2266: * search queries, so changing them doesn't refresh the cache.
2267: *
2268: * @param string $meta_key Meta key.
2269: *
2270: * @return bool
2271: *
2272: * @since 3.6 Added: editing a listing refreshed the cache every minute.
2273: */
2274: function epl_listing_query_cache_ignores_meta_key( $meta_key ) {
2275: $ignore = is_string( $meta_key ) && 0 === strpos( $meta_key, '_' );
2276:
2277: /**
2278: * Filters whether a meta key change leaves the listing query cache as it is.
2279: *
2280: * @since 3.6
2281: *
2282: * @param bool $ignore True for hidden keys (starting with an underscore).
2283: * @param string $meta_key Meta key.
2284: */
2285: return (bool) apply_filters( 'epl_listing_query_cache_ignores_meta_key', $ignore, $meta_key );
2286: }
2287:
2288: /**
2289: * Mark the listing query cache to be refreshed when this request ends
2290: *
2291: * Hooked to listing saves, deletes, status, meta and term changes. An import can change
2292: * hundreds of meta values per listing, so the refresh starts once, at the end of the
2293: * request.
2294: *
2295: * @param mixed $arg1 Hook argument: a post ID, post object, meta ID or new status, by hook.
2296: * @param mixed $arg2 Hook argument: the object ID or old status, by hook.
2297: * @param mixed $arg3 Hook argument: the post, by hook.
2298: *
2299: * @return void
2300: *
2301: * @since 3.6
2302: */
2303: function epl_listing_query_cache_changed( $arg1 = null, $arg2 = null, $arg3 = null ) {
2304: static $scheduled = false;
2305:
2306: if ( $scheduled ) {
2307: return;
2308: }
2309:
2310: $post_id = 0;
2311: switch ( current_filter() ) {
2312: case 'transition_post_status':
2313: $post_id = $arg3 instanceof WP_Post ? $arg3->ID : 0;
2314: break;
2315: case 'added_post_meta':
2316: case 'updated_post_meta':
2317: case 'deleted_post_meta':
2318: if ( epl_listing_query_cache_ignores_meta_key( $arg3 ) ) {
2319: return;
2320: }
2321: $post_id = (int) $arg2;
2322: break;
2323: default:
2324: $post_id = (int) $arg1;
2325: }
2326:
2327: $types = array_unique( array_merge( epl_get_core_post_types(), (array) epl_all_post_types() ) );
2328:
2329: if ( ! $post_id || ! in_array( get_post_type( $post_id ), $types, true ) ) {
2330: return;
2331: }
2332:
2333: $scheduled = true;
2334: add_action( 'shutdown', 'epl_flush_listing_query_cache' );
2335: }
2336: add_action( 'save_post', 'epl_listing_query_cache_changed', 10, 1 );
2337: add_action( 'before_delete_post', 'epl_listing_query_cache_changed', 10, 1 );
2338: add_action( 'transition_post_status', 'epl_listing_query_cache_changed', 10, 3 );
2339: add_action( 'added_post_meta', 'epl_listing_query_cache_changed', 10, 3 );
2340: add_action( 'updated_post_meta', 'epl_listing_query_cache_changed', 10, 3 );
2341: add_action( 'deleted_post_meta', 'epl_listing_query_cache_changed', 10, 3 );
2342: add_action( 'set_object_terms', 'epl_listing_query_cache_changed', 10, 1 );
2343:
2344: /**
2345: * Variable names the listing search templates keep for themselves
2346: *
2347: * The search templates copy URL values into variables so the form shows the current search.
2348: * These names are never taken from the URL, or ?atts=x would break the page.
2349: *
2350: * @return string[]
2351: *
2352: * @since 3.6 Added.
2353: */
2354: function epl_search_template_reserved_vars() {
2355: return array( 'atts', 'user_atts', 'atts_key', 'atts_val', 'config', 'epl_frontend_field', 'epl_frontend_fields', 'epl_settings', 'get_data', 'get_key', 'get_val', 'global_counters', 'global_tab_counter', 'is_sb_current', 'post_type_label', 'queried_post_type', 'selected_post_types', 'show_title', 'tabcounter', 'value', 'GLOBALS', 'this', '_GET', '_POST', '_REQUEST', '_SERVER', '_COOKIE', '_FILES', '_ENV', '_SESSION' );
2356: }
2357:
2358: /**
2359: * Keep only real listing statuses from a requested status list
2360: *
2361: * The search form's dropdowns are cached per status, so a made-up status in the URL
2362: * (?property_status=<anything>) must not reach them, or every request adds cache entries.
2363: *
2364: * @param string|array $requested Comma separated statuses, or an array.
2365: *
2366: * @return string Comma separated known statuses, or '' when none are known.
2367: *
2368: * @since 3.6 Added: the search form templates passed the URL status to the dropdown queries unchecked.
2369: */
2370: function epl_search_known_statuses( $requested ) {
2371: $requested = is_array( $requested ) ? $requested : explode( ',', (string) $requested );
2372: $known = array_keys( epl_get_property_status_opts() );
2373: $statuses = array();
2374:
2375: foreach ( $requested as $status ) {
2376: $status = trim( (string) $status );
2377: if ( in_array( $status, $known, true ) ) {
2378: $statuses[] = $status;
2379: }
2380: }
2381:
2382: return implode( ',', $statuses );
2383: }
2384:
2385: /**
2386: * Description: Getting all the values associated with a specific custom post meta key, across all posts
2387: * Author: Chinmoy Paul
2388: * Author URL: http://pwdtechnology.com
2389: *
2390: * @param string $key Post Meta Key.
2391: * @param string $type Post Type. Default is post. You can pass custom post type here.
2392: * @param string $status Post Status like Publish, draft, future etc. default is publish.
2393: * @param string $property_status Listing status.
2394: *
2395: * @return void
2396: *
2397: * @since 2.1.11
2398: * @since 3.4.40 Tweak: Search selection results will be sorted in a-z order.
2399: * @since 3.4.40 Fix: Search address options fixed for the all search tab.
2400: * @since 3.5.3 Fix: Prepared statement for SQL.
2401: * @since 3.5.5 Fix: DB error due to double escaping.
2402: * @since 3.5.6 Fix: Status variable overwritten when status option was passed to the shortcode.
2403: * @since 3.5.29 Fix: SQL injection. Post types are limited to registered ones and passed as prepared placeholders.
2404: * @since 3.6 Fix: Slow query. The listing status table is only joined when filtering by status, on its own meta key, instead of every meta row of every listing (33x faster on 735 rentals). Results are cached until a listing changes (epl_listing_query_cache()).
2405: * @since 3.6 Security: only real listing statuses are used (epl_search_known_statuses()), so a made-up status can't add cache entries.
2406: */
2407: function epl_get_unique_post_meta_values( $key = '', $type = '', $status = 'publish', $property_status = '' ) {
2408:
2409: // Only real listing statuses: results are cached per status (epl_search_known_statuses()).
2410: $property_status = epl_search_known_statuses( $property_status );
2411:
2412: global $wpdb;
2413:
2414: if ( empty( $key ) ) {
2415: return;
2416: }
2417:
2418: if ( empty( $type ) || 'all' === $type ) {
2419: $type = epl_get_core_post_types();
2420: }
2421:
2422: $type = (array) $type;
2423: $type = array_map( 'sanitize_text_field', $type );
2424:
2425: // Keep only registered post types and bind each as a prepared placeholder, so
2426: // the post_type value can never break out of the IN() list (SQL injection).
2427: $type = array_values( array_filter( $type, 'post_type_exists' ) );
2428:
2429: if ( empty( $type ) ) {
2430: $type = epl_get_core_post_types();
2431: }
2432:
2433: $type_placeholders = implode( ', ', array_fill( 0, count( $type ), '%s' ) );
2434:
2435: // The listing status is only joined when filtering by it. Joining the whole postmeta
2436: // table without a key matched every meta row of every listing (100+ each) and made
2437: // this query slow on bigger sites.
2438: $status_join = '';
2439: $status_where = '';
2440:
2441: if ( ! empty( $property_status ) ) {
2442:
2443: $property_status = array_map( 'trim', explode( ',', $property_status ) );
2444:
2445: if ( count( $property_status ) ) {
2446: $prepared_status_values = array();
2447: foreach ( $property_status as $status_value ) {
2448: $prepared_status_values[] = $wpdb->prepare( '%s', $status_value );
2449: }
2450:
2451: $status_join = "INNER JOIN {$wpdb->postmeta} pm2 ON ( pm2.post_id = pm.post_id AND pm2.meta_key = 'property_status' )";
2452: $status_where = ' AND pm2.meta_value IN (' . implode( ',', $prepared_status_values ) . ') ';
2453: }
2454: }
2455:
2456: $query = "
2457: SELECT DISTINCT pm.meta_value FROM {$wpdb->postmeta} pm
2458: INNER JOIN {$wpdb->posts} p ON p.ID = pm.post_id
2459: {$status_join}
2460: WHERE pm.meta_key = '%s'
2461: AND p.post_status = '%s'
2462: AND p.post_type IN ( {$type_placeholders} )
2463: {$status_where}
2464: ";
2465:
2466: $prepare_args = array_merge( array( $key, $status ), $type );
2467: $sql = $wpdb->prepare( $query, $prepare_args ); // phpcs:ignore
2468:
2469: $res = array_filter( epl_listing_query_cache( $sql ) );
2470:
2471: foreach ( $res as $key => &$elem ) {
2472: $elem = maybe_unserialize( $elem );
2473: if ( ! empty( $elem ) && is_array( $elem ) ) {
2474: foreach ( $elem as $el ) {
2475: $res[] = $el;
2476: }
2477: unset( $res[ $key ] );
2478: }
2479: }
2480:
2481: $res = array_filter( $res );
2482: $results = array();
2483:
2484: foreach ( $res as $s_res ) {
2485: $results[ $s_res ] = ucwords( $s_res );
2486: }
2487:
2488: asort( $results );
2489:
2490: return apply_filters( 'epl_get_unique_post_meta_values', $results, $key, $type );
2491: }
2492:
2493: /**
2494: * Get Sales Count By Date
2495: *
2496: * @param int $day Day number.
2497: * @param int $month_num Month number.
2498: * @param int $year Year.
2499: * @param int $hour Hour.
2500: * @param int $status Listing status.
2501: * @param bool $day_by_day Sales by day.
2502: * @return int $count Sales
2503: * @since 3.0
2504: */
2505: function epl_get_sales_by_date( $day = null, $month_num = null, $year = null, $hour = null, $status = null, $day_by_day = true ) {
2506: // phpcs:disable WordPress.Security.NonceVerification
2507: $post_type = isset( $_GET['view'] ) ? sanitize_text_field( wp_unslash( $_GET['view'] ) ) : 'property';
2508: $args = array(
2509: 'post_type' => $post_type,
2510: 'nopaging' => true,
2511: 'year' => $year,
2512: 'fields' => 'ids',
2513: 'post_status' => array( 'publish' ),
2514: 'update_post_meta_cache' => false,
2515: 'update_post_term_cache' => false,
2516: );
2517:
2518: if ( in_array( $status, array( 'sold', 'leased' ), true ) ) {
2519:
2520: $month_num = is_null( $month_num ) ? 00 : $month_num;
2521: $day = is_null( $day ) ? 00 : $day;
2522: $year = is_null( $year ) ? 0000 : $year;
2523: $range = isset( $_GET['range'] ) ? sanitize_text_field( wp_unslash( $_GET['range'] ) ) : 'other';
2524:
2525: $args['meta_query'] = array( //phpcs:ignore
2526: array(
2527: 'key' => 'property_status',
2528: 'value' => (array) $status,
2529: 'compare' => 'IN',
2530: ),
2531: );
2532:
2533: if ( in_array( $range, array( 'other', 'last_year', 'this_year', 'last_quarter', 'this_quarter' ), true ) ) {
2534:
2535: $sold_key = 'leased' === $status ? 'property_date_available' : 'property_sold_date';
2536:
2537: $sold_date_end = gmdate( 'Y-m-d', strtotime( $year . '-' . $month_num . '-' . $day ) );
2538: $sold_date_start = true === $day_by_day ? $sold_date_end : gmdate( 'Y-m-01', strtotime( $year . '-' . $month_num . '-' . $day ) );
2539:
2540: $args['meta_query'][] = array(
2541: 'key' => $sold_key,
2542: 'value' => array( $sold_date_start, $sold_date_end ),
2543: 'type' => 'DATE',
2544: 'compare' => 'BETWEEN',
2545: );
2546:
2547: } else {
2548:
2549: $sold_key = 'leased' === $status ? 'property_date_available' : 'property_sold_date';
2550: $sold_date = gmdate( 'Y-m-d', strtotime( $year . '-' . $month_num . '-' . $day ) );
2551:
2552: $args['meta_query'][] = array(
2553: 'key' => $sold_key,
2554: 'value' => $sold_date,
2555: 'type' => 'DATE',
2556: );
2557: }
2558: } else {
2559:
2560: if ( ! empty( $month_num ) ) {
2561: $args['monthnum'] = $month_num;
2562: }
2563:
2564: if ( ! empty( $day ) ) {
2565: $args['day'] = $day;
2566: }
2567:
2568: if ( ! empty( $hour ) ) {
2569: $args['hour'] = $hour;
2570: }
2571: }
2572:
2573: $args = apply_filters( 'epl_get_sales_by_date_args', $args );
2574:
2575: $key = 'epl_stats_' . substr( md5( serialize( $args ) ), 0, 15 ); //phpcs:ignore
2576: $count = get_transient( $key );
2577: if ( false === $count ) {
2578: $sales = new WP_Query( $args );
2579: $count = (int) $sales->post_count;
2580: // Cache the results for one hour.
2581: set_transient( $key, $count, HOUR_IN_SECONDS );
2582: }
2583:
2584: return $count;
2585: }
2586:
2587: /**
2588: * Month Num To Name
2589: *
2590: * Takes a month number and returns the name three letter name of it.
2591: *
2592: * @since 3.0
2593: *
2594: * @param integer $n Month number.
2595: * @return string Short month name
2596: */
2597: function epl_month_num_to_name( $n ) {
2598: $timestamp = mktime( 0, 0, 0, $n, 1, 2005 );
2599:
2600: return date_i18n( 'M', $timestamp );
2601: }
2602:
2603: /**
2604: * Retrieve contacts from the database
2605: *
2606: * @access public
2607: *
2608: * @param array $args Arguments.
2609: *
2610: * @return bool|int[]|mixed|WP_Post[]
2611: * @since 3.0
2612: */
2613: function epl_get_contacts( $args = array() ) {
2614:
2615: global $wpdb;
2616:
2617: $defaults = array(
2618: 'post_type' => 'epl_contact',
2619: 'posts_per_page' => 20,
2620: 'offset' => 0,
2621: 'orderby' => 'ID',
2622: 'order' => 'DESC',
2623: );
2624:
2625: $args = wp_parse_args( $args, $defaults );
2626:
2627: if ( $args['posts_per_page'] < 1 ) {
2628: $args['number'] = -1;
2629: }
2630:
2631: $where = ' WHERE 1=1 ';
2632:
2633: // specific contacts.
2634: if ( ! empty( $args['ID'] ) ) {
2635: $args['post__in'] = $args['ID'];
2636:
2637: }
2638:
2639: // specific contacts by email.
2640: if ( ! empty( $args['email'] ) ) {
2641:
2642: $email_query = array(
2643: 'key' => 'contact_email',
2644: 'value' => $args['email'],
2645: );
2646:
2647: if ( is_array( $args['email'] ) ) {
2648: $email_query['comparison'] = 'IN';
2649:
2650: }
2651: $args['meta_query'][] = $email_query;
2652: }
2653:
2654: // specific contacts by name.
2655: if ( ! empty( $args['name'] ) ) {
2656: $args['post_title'] = $args['name'];
2657: }
2658:
2659: $cache_key = md5( 'epl_contacts_' . serialize( $args ) ); //phpcs:ignore
2660:
2661: $contacts = wp_cache_get( $cache_key, 'contacts' );
2662:
2663: $args['orderby'] = esc_sql( $args['orderby'] );
2664: $args['order'] = esc_sql( $args['order'] );
2665:
2666: if ( false === $contacts ) {
2667: $contacts = get_posts( $args );
2668: wp_cache_set( $cache_key, $contacts, 'contacts', 3600 );
2669: }
2670: return $contacts;
2671: }
2672:
2673: /**
2674: * Search Listing Ajax
2675: *
2676: * @access public
2677: * @since 3.0
2678: */
2679: function epl_search_listing() {
2680: $search_array = array(
2681: 's' => isset( $_POST['s'] ) ? sanitize_text_field( wp_unslash( $_POST['s'] ) ) : '',
2682: 'showposts' => 6,
2683: 'post_type' => epl_get_core_post_types(),
2684: 'post_status' => 'publish',
2685: );
2686: $query = http_build_query( $search_array );
2687: $listings = get_posts( $query );
2688: if ( ! empty( $listings ) ) {
2689: echo '<ul class="epl-popup-box epl-property-suggestion epl-striped">';
2690: foreach ( $listings as $listing ) {
2691: $status = get_post_meta( $listing->ID, 'property_status', true );
2692: echo '<li data-id="' . esc_attr( $listing->ID ) . '"><span class="epl-listing-type">' . esc_attr( $listing->post_type ) . '</span>' . esc_attr( $listing->post_title ) . '<span class="epl-listing-status type_' . esc_attr( $status ) . '">' . esc_attr( $status ) . '</span></li>';
2693: }
2694: echo '</ul>';
2695: }
2696: wp_die();
2697: }
2698: add_action( 'wp_ajax_nopriv_epl_search_listing', 'epl_search_listing' );
2699: add_action( 'wp_ajax_epl_search_listing', 'epl_search_listing' );
2700:
2701: /**
2702: * Get Contact Categories
2703: *
2704: * @access public
2705: * @since 3.0
2706: */
2707: function epl_get_contact_categories() {
2708: return apply_filters(
2709: 'epl_contact_categories',
2710: array(
2711: 'appraisal' => __( 'Appraisal', 'easy-property-listings' ),
2712: 'buyer' => __( 'Buyer', 'easy-property-listings' ),
2713: 'contact' => __( 'Contact', 'easy-property-listings' ),
2714: 'lead' => __( 'Lead', 'easy-property-listings' ),
2715: 'landlord' => __( 'Landlord', 'easy-property-listings' ),
2716: 'new' => __( 'New', 'easy-property-listings' ),
2717: 'past_customer' => __( 'Past Customer', 'easy-property-listings' ),
2718: 'seller' => __( 'Seller', 'easy-property-listings' ),
2719: 'tenant' => __( 'Tenant', 'easy-property-listings' ),
2720: 'widget' => __( 'Widget Lead', 'easy-property-listings' ),
2721: 'contract' => __( 'Under Contract', 'easy-property-listings' ),
2722: )
2723: );
2724: }
2725:
2726: /**
2727: * Get Contact Labels
2728: *
2729: * @param string $category Category label.
2730: *
2731: * @access public
2732: * @return string
2733: * @since 3.0
2734: */
2735: function get_category_label( $category ) {
2736: foreach ( epl_get_contact_categories() as $key => $cat ) {
2737: if ( $key === $category ) {
2738: return $cat;
2739: }
2740: }
2741: return $category;
2742: }
2743:
2744: /**
2745: * Helper function starts with
2746: *
2747: * @param string $haystack String.
2748: * @param string $needle String.
2749: *
2750: * @return bool
2751: * @since 3.3
2752: */
2753: function epl_starts_with( $haystack, $needle ) {
2754: // search backwards starting from haystack length characters from the end.
2755: return empty( $needle ) || strrpos( $haystack, $needle, -strlen( $haystack ) ) !== false;
2756: }
2757:
2758: /**
2759: * Helper function ends with
2760: *
2761: * @param string $haystack String.
2762: * @param string $needle String.
2763: *
2764: * @return bool
2765: * @since 3.3
2766: */
2767: function epl_ends_with( $haystack, $needle ) {
2768: // search forward starting from end minus needle length characters.
2769: $temp = strlen( $haystack ) - strlen( $needle );
2770: return empty( $needle ) || ( $temp >= 0 && strpos( $haystack, $needle, $temp ) !== false );
2771: }
2772:
2773: /**
2774: * Parse EPL shortcodes for meta queries
2775: *
2776: * @param array $atts Attributes.
2777: * @return array
2778: *
2779: * @since 3.5 Fix: PHP 8.2. Automatic conversion of false to array is deprecated fix.
2780: * @since 3.5.4 Fix: Min & Max not working.
2781: */
2782: function epl_parse_atts( $atts ) {
2783:
2784: $query = array();
2785:
2786: if ( empty( $atts ) ) {
2787: return $atts;
2788: }
2789:
2790: $compare_operators = array(
2791: '_min' => '>=',
2792: '_max' => '<=',
2793: '_not_equal' => '!=',
2794: '_like' => 'LIKE',
2795: '_not_like' => 'NOT LIKE',
2796: '_exists' => 'EXISTS',
2797: '_not_exists' => 'NOT EXISTS',
2798: '_in' => 'IN',
2799: '_not_in' => 'NOT IN',
2800: '_between' => 'BETWEEN',
2801: '_not_between' => 'NOT BETWEEN',
2802: );
2803:
2804: foreach ( $atts as $key => &$value ) {
2805:
2806: $this_query = array(
2807: 'compare' => '=',
2808: 'value' => $value,
2809: );
2810:
2811: // check for meta.
2812: if ( epl_starts_with( $key, '_' ) ) {
2813:
2814: $key = preg_replace( '/^_/', '', $key );
2815:
2816: foreach ( $compare_operators as $look_for => $compare_operator ) {
2817:
2818: if ( epl_ends_with( $key, $look_for ) ) {
2819:
2820: $key = preg_replace( '/' . $look_for . '$/', '', $key );
2821: $this_query['compare'] = $compare_operator;
2822:
2823: if ( in_array( $look_for, array( '_in', '_not_in', '_between', '_not_between' ), true ) ) {
2824:
2825: $this_query['value'] =
2826: array_map( 'trim', explode( ',', $this_query['value'] ) );
2827:
2828: if ( in_array( $look_for, array( '_between', '_not_between' ), true ) ) {
2829:
2830: if ( is_numeric( $this_query['value'][0] ) ) {
2831: $this_query['type'] = 'numeric';
2832: }
2833: }
2834: }
2835:
2836: if ( in_array( $look_for, array( '_min', '_max' ), true ) ) {
2837: if ( is_numeric( $this_query['value'] ) ) {
2838: $this_query['type'] = 'numeric';
2839: }
2840: }
2841:
2842: if ( in_array( $look_for, array( '_exists', '_not_exists' ), true ) ) {
2843: unset( $this_query['value'] );
2844: }
2845: }
2846: }
2847: $this_query['key'] = $key;
2848: $query['meta_query'][ $key . '_clause' ] = $this_query;
2849: }
2850: }
2851: return isset( $query['meta_query'] ) ? $query['meta_query'] : array();
2852: }
2853:
2854: /**
2855: * Return an array of all extensions with beta support
2856: *
2857: * Extensions should be added as 'extension-slug' => 'Extension Name'
2858: *
2859: * @return array $extensions The array of extensions
2860: */
2861: function epl_get_beta_enabled_extensions() {
2862: return apply_filters( 'epl_beta_enabled_extensions', array() );
2863: }
2864:
2865: /**
2866: * Returns List of countries
2867: *
2868: * @since 3.2
2869: */
2870: function epl_get_countries_list() {
2871:
2872: $countries = array( 'Australia', 'Afghanistan', 'Albania', 'Algeria', 'American Samoa', 'Andorra', 'Angola', 'Anguilla', 'Antarctica', 'Antigua and Barbuda', 'Argentina', 'Armenia', 'Aruba', 'Austria', 'Azerbaijan', 'Bahamas', 'Bahrain', 'Bangladesh', 'Barbados', 'Belarus', 'Belgium', 'Belize', 'Benin', 'Bermuda', 'Bhutan', 'Bolivia', 'Bosnia and Herzegowina', 'Botswana', 'Bouvet Island', 'Brazil', 'British Indian Ocean Territory', 'Brunei Darussalam', 'Bulgaria', 'Burkina Faso', 'Burundi', 'Cambodia', 'Cameroon', 'Canada', 'Cape Verde', 'Cayman Islands', 'Central African Republic', 'Chad', 'Chile', 'China', 'Christmas Island', 'Cocos (Keeling) Islands', 'Colombia', 'Comoros', 'Congo', 'Congo, the Democratic Republic of the', 'Cook Islands', 'Costa Rica', "Cote d'Ivoire", 'Croatia (Hrvatska)', 'Cuba', 'Cyprus', 'Czech Republic', 'Denmark', 'Djibouti', 'Dominica', 'Dominican Republic', 'East Timor', 'Ecuador', 'Egypt', 'El Salvador', 'Equatorial Guinea', 'Eritrea', 'Estonia', 'Ethiopia', 'Falkland Islands (Malvinas)', 'Faroe Islands', 'Fiji', 'Finland', 'France', 'France Metropolitan', 'French Guiana', 'French Polynesia', 'French Southern Territories', 'Gabon', 'Gambia', 'Georgia', 'Germany', 'Ghana', 'Gibraltar', 'Greece', 'Greenland', 'Grenada', 'Guadeloupe', 'Guam', 'Guatemala', 'Guinea', 'Guinea-Bissau', 'Guyana', 'Haiti', 'Heard and Mc Donald Islands', 'Holy See (Vatican City State)', 'Honduras', 'Hong Kong', 'Hungary', 'Iceland', 'India', 'Indonesia', 'Iran (Islamic Republic of)', 'Iraq', 'Ireland', 'Israel', 'Italy', 'Jamaica', 'Japan', 'Jordan', 'Kazakhstan', 'Kenya', 'Kiribati', "Korea, Democratic People's Republic of", 'Korea, Republic of', 'Kuwait', 'Kyrgyzstan', "Lao, People's Democratic Republic", 'Latvia', 'Lebanon', 'Lesotho', 'Liberia', 'Libyan Arab Jamahiriya', 'Liechtenstein', 'Lithuania', 'Luxembourg', 'Macau', 'Macedonia, The Former Yugoslav Republic of', 'Madagascar', 'Malawi', 'Malaysia', 'Maldives', 'Mali', 'Malta', 'Marshall Islands', 'Martinique', 'Mauritania', 'Mauritius', 'Mayotte', 'Mexico', 'Micronesia, Federated States of', 'Moldova, Republic of', 'Monaco', 'Mongolia', 'Montserrat', 'Morocco', 'Mozambique', 'Myanmar', 'Namibia', 'Nauru', 'Nepal', 'Netherlands', 'Netherlands Antilles', 'New Caledonia', 'New Zealand', 'Nicaragua', 'Niger', 'Nigeria', 'Niue', 'Norfolk Island', 'Northern Mariana Islands', 'Norway', 'Oman', 'Pakistan', 'Palau', 'Panama', 'Papua New Guinea', 'Paraguay', 'Peru', 'Philippines', 'Pitcairn', 'Poland', 'Portugal', 'Puerto Rico', 'Qatar', 'Reunion', 'Romania', 'Russian Federation', 'Rwanda', 'Saint Kitts and Nevis', 'Saint Lucia', 'Saint Vincent and the Grenadines', 'Samoa', 'San Marino', 'Sao Tome and Principe', 'Saudi Arabia', 'Senegal', 'Seychelles', 'Sierra Leone', 'Singapore', 'Slovakia (Slovak Republic)', 'Slovenia', 'Solomon Islands', 'Somalia', 'South Africa', 'South Georgia and the South Sandwich Islands', 'Spain', 'Sri Lanka', 'St. Helena', 'St. Pierre and Miquelon', 'Sudan', 'Suriname', 'Svalbard and Jan Mayen Islands', 'Swaziland', 'Sweden', 'Switzerland', 'Syrian Arab Republic', 'Taiwan, Province of China', 'Tajikistan', 'Tanzania, United Republic of', 'Thailand', 'Togo', 'Tokelau', 'Tonga', 'Trinidad and Tobago', 'Tunisia', 'Turkey', 'Turkmenistan', 'Turks and Caicos Islands', 'Tuvalu', 'Uganda', 'Ukraine', 'United Arab Emirates', 'United Kingdom', 'United States', 'United States Minor Outlying Islands', 'Uruguay', 'Uzbekistan', 'Vanuatu', 'Venezuela', 'Vietnam', 'Virgin Islands (British)', 'Virgin Islands (U.S.)', 'Wallis and Futuna Islands', 'Western Sahara', 'Yemen', 'Yugoslavia', 'Zambia', 'Zimbabwe' );
2873:
2874: return apply_filters( 'epl_get_countries_list', array_combine( $countries, $countries ) );
2875: }
2876:
2877: /**
2878: * Returns array containing Property Status
2879: *
2880: * @since 3.2
2881: * @since 3.4.45 Added deleted status. Re-orderd status options.
2882: */
2883: function epl_get_property_status_opts() {
2884:
2885: return apply_filters(
2886: 'epl_opts_property_status_filter',
2887: array(
2888: 'current' => __( 'Current', 'easy-property-listings' ),
2889: 'sold' => array(
2890: 'label' => apply_filters( 'epl_sold_label_status_filter', __( 'Sold', 'easy-property-listings' ) ),
2891: 'exclude' => array( 'rental' ),
2892: ),
2893: 'leased' => array(
2894: 'label' => apply_filters( 'epl_leased_label_status_filter', __( 'Leased', 'easy-property-listings' ) ),
2895: 'include' => array( 'rental', 'commercial', 'commercial_land', 'business' ),
2896: ),
2897: 'withdrawn' => __( 'Withdrawn', 'easy-property-listings' ),
2898: 'offmarket' => __( 'Off Market', 'easy-property-listings' ),
2899: 'deleted' => __( 'Deleted', 'easy-property-listings' ),
2900: )
2901: );
2902: }
2903:
2904: /**
2905: * Returns the status label for given status value.
2906: *
2907: * @since 3.5.0
2908: *
2909: * @param bool $status Status status value.
2910: * @return string $label Status label.
2911: */
2912: function epl_get_the_status_label( $status = '' ) {
2913:
2914: $status_opts = epl_get_property_status_opts();
2915:
2916: if ( 0 === strlen( $status ) ) {
2917: return null;
2918: }
2919:
2920: $status_data = $status_opts[ $status ];
2921:
2922: $label = is_array( $status_data ) && isset( $status_data['label'] ) ? $status_data['label'] : $status_data;
2923:
2924: return $label;
2925: }
2926:
2927: /**
2928: * Returns the array of status available in the site as key, label pair.
2929: *
2930: * @since 3.5.0
2931: *
2932: * @param string $key Post Meta Key.
2933: * @param string $type Post Type. Default is post. You can pass custom post type here.
2934: *
2935: * @return string|array $label Status label.
2936: */
2937: function epl_get_available_status_list( $key, $type ) {
2938:
2939: $status_list = epl_get_unique_post_meta_values( $key, $type );
2940: $available = array();
2941:
2942: if ( empty( $status_list ) ) {
2943: return array();
2944: }
2945:
2946: foreach ( $status_list as $key => $key_label ) {
2947: $available[ $key ] = epl_get_the_status_label( $key );
2948: }
2949:
2950: return apply_filters( 'epl_get_available_status_list', $available, $key, $type );
2951: }
2952:
2953: /**
2954: * Returns array containing Property authority
2955: *
2956: * @since 3.2
2957: */
2958: function epl_get_property_authority_opts() {
2959:
2960: return apply_filters(
2961: 'epl_property_authority_filter',
2962: array(
2963: 'exclusive' => __( 'Exclusive', 'easy-property-listings' ),
2964: 'auction' => __( 'Auction', 'easy-property-listings' ),
2965: 'multilist' => __( 'Multilist', 'easy-property-listings' ),
2966: 'conjunctional' => __( 'Conjunctional', 'easy-property-listings' ),
2967: 'open' => __( 'Open', 'easy-property-listings' ),
2968: 'sale' => __( 'Sale', 'easy-property-listings' ),
2969: 'setsale' => __( 'Set Sale', 'easy-property-listings' ),
2970: )
2971: );
2972: }
2973:
2974: /**
2975: * Returns array containing Property exclusivity
2976: *
2977: * @since 3.2
2978: */
2979: function epl_get_property_exclusivity_opts() {
2980:
2981: return apply_filters(
2982: 'epl_opts_property_exclusivity_filter',
2983: array(
2984: 'exclusive' => __( 'Exclusive', 'easy-property-listings' ),
2985: 'open' => __( 'Open', 'easy-property-listings' ),
2986: )
2987: );
2988: }
2989:
2990: /**
2991: * Returns array containing Commercial Authority
2992: *
2993: * @since 3.2
2994: * @since 3.4.26 Re-ordered options.
2995: */
2996: function epl_get_property_com_authority_opts() {
2997:
2998: return apply_filters(
2999: 'epl_opts_property_com_authority_filter',
3000: array(
3001: 'Forsale' => __( 'For Sale', 'easy-property-listings' ),
3002: 'auction' => __( 'Auction', 'easy-property-listings' ),
3003: 'eoi' => __( 'EOI', 'easy-property-listings' ),
3004: 'offers' => __( 'Offers', 'easy-property-listings' ),
3005: 'Sale' => __( 'Sale', 'easy-property-listings' ),
3006: 'tender' => __( 'Tender', 'easy-property-listings' ),
3007: )
3008: );
3009: }
3010:
3011: /**
3012: * Commercial Authority label for a saved value
3013: *
3014: * @param string $key Saved property_com_authority value, for example eoi.
3015: *
3016: * @return string Label, for example EOI, or '' when the value isn't an option.
3017: *
3018: * @since 3.6
3019: */
3020: function epl_get_property_com_authority_label( $key ) {
3021: $opts = epl_get_property_com_authority_opts();
3022:
3023: return ( is_scalar( $key ) && isset( $opts[ $key ] ) ) ? (string) $opts[ $key ] : '';
3024: }
3025:
3026: /**
3027: * Status of the current listing
3028: *
3029: * @return string Saved property_status value (current, sold, leased, withdrawn, offmarket), or '' outside a listing.
3030: *
3031: * @since 3.6
3032: */
3033: function epl_get_listing_status() {
3034: global $property;
3035:
3036: $status = $property instanceof EPL_Property_Meta ? (string) $property->get_property_meta( 'property_status' ) : '';
3037:
3038: return apply_filters( 'epl_get_listing_status', $status );
3039: }
3040:
3041: /**
3042: * Status label of the current listing, for cards and headings
3043: *
3044: * Sales listings: For Sale, Auction (current with auction authority) or Sold. Rentals: For Rent
3045: * or Leased. Commercial: Buy, Lease or Buy or Lease from the listing type, then Sold or Leased.
3046: * Sold and Leased use the Sold and Leased label settings. Other statuses return ''.
3047: *
3048: * @param array $labels Labels to override, keyed label_for_sale, label_auction, label_sold,
3049: * label_for_lease, label_leased, label_commercial_sale, label_commercial_lease,
3050: * label_commercial_both, label_commercial_sold, label_commercial_leased.
3051: *
3052: * @return string
3053: *
3054: * @since 3.6
3055: */
3056: function epl_get_listing_status_label( $labels = array() ) {
3057: global $property;
3058:
3059: if ( ! $property instanceof EPL_Property_Meta ) {
3060: return '';
3061: }
3062:
3063: $label_sold = epl_get_option( 'label_sold', __( 'Sold', 'easy-property-listings' ) );
3064: $label_leased = epl_get_option( 'label_leased', __( 'Leased', 'easy-property-listings' ) );
3065:
3066: $labels = array_merge(
3067: array(
3068: 'label_for_sale' => __( 'For Sale', 'easy-property-listings' ),
3069: 'label_auction' => __( 'Auction', 'easy-property-listings' ),
3070: 'label_sold' => $label_sold,
3071: 'label_for_lease' => __( 'For Rent', 'easy-property-listings' ),
3072: 'label_leased' => $label_leased,
3073: 'label_commercial_sale' => __( 'Buy', 'easy-property-listings' ),
3074: 'label_commercial_lease' => __( 'Lease', 'easy-property-listings' ),
3075: 'label_commercial_both' => __( 'Buy or Lease', 'easy-property-listings' ),
3076: 'label_commercial_sold' => $label_sold,
3077: 'label_commercial_leased' => $label_leased,
3078: ),
3079: (array) $labels
3080: );
3081:
3082: $post_type = $property->post_type;
3083: $status = epl_get_listing_status();
3084: $label = '';
3085:
3086: if ( 'rental' === $post_type ) {
3087: if ( 'current' === $status ) {
3088: $label = $labels['label_for_lease'];
3089: } elseif ( 'leased' === $status ) {
3090: $label = $labels['label_leased'];
3091: }
3092: } elseif ( 'commercial' === $post_type ) {
3093: if ( 'sold' === $status ) {
3094: $label = $labels['label_commercial_sold'];
3095: } elseif ( 'leased' === $status ) {
3096: $label = $labels['label_commercial_leased'];
3097: } elseif ( 'current' === $status ) {
3098: $type = $property->get_property_meta( 'property_com_listing_type' );
3099: if ( 'sale' === $type ) {
3100: $label = $labels['label_commercial_sale'];
3101: } elseif ( 'lease' === $type ) {
3102: $label = $labels['label_commercial_lease'];
3103: } else {
3104: $label = $labels['label_commercial_both'];
3105: }
3106: }
3107: } elseif ( 'current' === $status ) {
3108: $label = 'auction' === $property->get_property_meta( 'property_authority' ) ? $labels['label_auction'] : $labels['label_for_sale'];
3109: } elseif ( 'sold' === $status ) {
3110: $label = $labels['label_sold'];
3111: }
3112:
3113: return apply_filters( 'epl_get_listing_status_label', $label, $status, $post_type, $labels );
3114: }
3115:
3116: /**
3117: * Returns array containing area unit options
3118: *
3119: * @since 3.2
3120: */
3121: function epl_get_property_area_unit_opts() {
3122:
3123: return apply_filters(
3124: 'epl_opts_area_unit_filter',
3125: array(
3126: 'square' => __( 'Square', 'easy-property-listings' ),
3127: 'squareMeter' => __( 'Square Meter', 'easy-property-listings' ),
3128: 'acre' => __( 'Acre', 'easy-property-listings' ),
3129: 'hectare' => __( 'Hectare', 'easy-property-listings' ),
3130: 'sqft' => __( 'Square Feet', 'easy-property-listings' ),
3131: )
3132: );
3133: }
3134:
3135: /**
3136: * Returns array containing Rental period
3137: *
3138: * @since 3.2
3139: */
3140: function epl_get_property_rent_period_opts() {
3141:
3142: return apply_filters(
3143: 'epl_opts_rent_period_filter',
3144: array(
3145: 'day' => __( 'Day', 'easy-property-listings' ),
3146: 'daily' => __( 'Daily', 'easy-property-listings' ),
3147: 'week' => __( 'Week', 'easy-property-listings' ),
3148: 'weekly' => __( 'Weekly', 'easy-property-listings' ),
3149: 'month' => __( 'Month', 'easy-property-listings' ),
3150: 'monthly' => __( 'Monthly', 'easy-property-listings' ),
3151: )
3152: );
3153: }
3154:
3155: /**
3156: * Returns array containing Commercial Leasing Types
3157: *
3158: * @since 3.2
3159: */
3160: function epl_get_property_com_listing_type_opts() {
3161:
3162: return apply_filters(
3163: 'epl_opts_property_com_listing_type_filter',
3164: array(
3165: 'sale' => __( 'Sale', 'easy-property-listings' ),
3166: 'lease' => __( 'Lease', 'easy-property-listings' ),
3167: 'both' => __( 'Both', 'easy-property-listings' ),
3168: )
3169: );
3170: }
3171:
3172: /**
3173: * Returns array containing Commercial Tenancy
3174: *
3175: * @since 3.2
3176: */
3177: function epl_get_property_com_tenancy_opts() {
3178:
3179: return apply_filters(
3180: 'epl_opts_property_com_tenancy_filter',
3181: array(
3182: 'unknown' => __( 'Unknown', 'easy-property-listings' ),
3183: 'vacant' => __( 'Vacant', 'easy-property-listings' ),
3184: 'tenanted' => __( 'Tenanted', 'easy-property-listings' ),
3185: )
3186: );
3187: }
3188:
3189: /**
3190: * Returns array containing Commercial Land Extent
3191: *
3192: * @since 3.2
3193: */
3194: function epl_get_property_com_property_extent_opts() {
3195:
3196: return apply_filters(
3197: 'epl_opts_property_com_property_extent_filter',
3198: array(
3199: 'whole' => __( 'Whole', 'easy-property-listings' ),
3200: 'part' => __( 'Part', 'easy-property-listings' ),
3201: )
3202: );
3203: }
3204:
3205: /**
3206: * Get author id from name
3207: *
3208: * @param string $author Author name.
3209: *
3210: * @return int
3211: * @since 3.1.1
3212: */
3213: function epl_get_author_id_from_name( $author ) {
3214: if ( is_numeric( $author ) ) {
3215: return absint( $author );
3216: } else {
3217: $user = get_user_by( 'login', $author );
3218: return $user->ID;
3219: }
3220: }
3221:
3222: /**
3223: * WP All Import Pro filter that processes property_price_global after updating or saving a post
3224: *
3225: * @param string $id Post ID.
3226: * @since 3.3
3227: */
3228: function epl_pmxi_import_post_saved( $id ) {
3229:
3230: $post = get_post( $id );
3231:
3232: if ( is_null( $post ) ) {
3233: return;
3234: }
3235:
3236: if ( is_epl_post( $post->post_type ) ) {
3237:
3238: if ( 'rental' === $post->post_type ) {
3239: $price = get_post_meta( $id, 'property_rent', true );
3240: update_post_meta( $id, 'property_price_global', $price );
3241: } elseif ( 'commercial' === $post->post_type ) {
3242: $price = get_post_meta( $id, 'property_price', true );
3243: if ( empty( $price ) ) {
3244: $price = get_post_meta( $id, 'property_com_rent', true );
3245: }
3246: update_post_meta( $id, 'property_price_global', $price );
3247: } else {
3248: $price = get_post_meta( $id, 'property_price', true );
3249: update_post_meta( $id, 'property_price_global', $price );
3250: }
3251: }
3252: }
3253: add_action( 'pmxi_saved_post', 'epl_pmxi_import_post_saved', 10, 1 );
3254:
3255: /**
3256: * Load functions from child theme folder if present
3257: *
3258: * @since 3.3
3259: */
3260: function epl_single_and_archive_functions() {
3261:
3262: if ( is_epl_post_single() && file_exists( get_stylesheet_directory() . '/easypropertylistings/functions-single.php' ) ) {
3263: include_once get_stylesheet_directory() . '/easypropertylistings/functions-single.php';
3264: }
3265:
3266: if ( is_epl_post_archive() && file_exists( get_stylesheet_directory() . '/easypropertylistings/functions-archive.php' ) ) {
3267: include_once get_stylesheet_directory() . '/easypropertylistings/functions-archive.php';
3268: }
3269: }
3270: add_action( 'wp', 'epl_single_and_archive_functions', 99 );
3271:
3272: /**
3273: * Recursive array map for multi dimensional array
3274: *
3275: * @param string $callback Callback.
3276: * @param array $input_array Array.
3277: *
3278: * @return array
3279: * @since 3.3.5
3280: */
3281: function epl_array_map_recursive( $callback, $input_array ) {
3282: $func = function ( $item ) use ( &$func, &$callback ) { //phpcs:ignore
3283: return is_array( $item ) ? array_map( $func, $item ) : call_user_func( $callback, $item );
3284: };
3285: return array_map( $func, $input_array );
3286: }
3287:
3288: /**
3289: * Sanitize function to allow certain safe html tags.
3290: *
3291: * @param array $content sanitized html content.
3292: *
3293: * @return string
3294: * @since 3.4.48
3295: */
3296: function epl_sanitize_html_tags( $content ) {
3297:
3298: $allowed_tags = wp_kses_allowed_html( 'post' );
3299:
3300: return wp_kses( $content, $allowed_tags );
3301: }
3302:
3303: /**
3304: * Function to generate a unique tab counter for search forms.
3305: *
3306: * @return int
3307: * @since 3.5
3308: */
3309: function epl_generate_unique_tab_counter() {
3310:
3311: global $epl_search_shortcode_counter;
3312:
3313: if ( empty( $epl_search_shortcode_counter ) ) {
3314: $epl_search_shortcode_counter = 0;
3315: }
3316:
3317: ++$epl_search_shortcode_counter;
3318: return $epl_search_shortcode_counter;
3319: }
3320:
3321: /**
3322: * Function to generate a unique instance counter for search forms.
3323: *
3324: * @return int
3325: * @since 3.5
3326: */
3327: function epl_generate_search_instance_counter() {
3328:
3329: global $epl_search_instance_counter;
3330:
3331: if ( empty( $epl_search_instance_counter ) ) {
3332: $epl_search_instance_counter = 0;
3333: }
3334:
3335: ++$epl_search_instance_counter;
3336: return $epl_search_instance_counter;
3337: }
3338:
3339: /**
3340: * Get the meta value as label helper function.
3341: *
3342: * @param string $meta_key The meta key to get the label for.
3343: *
3344: * @return mixed
3345: * @since 3.5
3346: */
3347: function epl_get_property_meta_label( $meta_key ) {
3348:
3349: $value = get_property_meta( $meta_key );
3350: $return = $value;
3351:
3352: if ( function_exists( 'epl_get_' . $meta_key . '_opts' ) ) {
3353:
3354: $labels = call_user_func( 'epl_get_' . $meta_key . '_opts' );
3355:
3356: if ( is_string( $value ) && isset( $labels[ $value ] ) ) {
3357: $return = $labels[ $value ];
3358: }
3359: }
3360:
3361: return $return;
3362: }
3363:
3364: /**
3365: * Returns the localised timestamp
3366: *
3367: * @since 3.5.3
3368: */
3369: function epl_get_local_timestamp() {
3370: $local_time = current_datetime();
3371: return $local_time->getTimestamp() + $local_time->getOffset();
3372: }
3373: