1: <?php
2: /**
3: * Custom Post Types Functions
4: *
5: * @package EPL
6: * @subpackage PostTypes/Functions
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: * Query filter for property_address_suburb custom field sortable in posts listing.
19: *
20: * @param array $vars variables.
21: *
22: * @return array
23: * @since 1.0
24: */
25: function epl_property_address_suburb_column_orderby( $vars ) {
26: if ( isset( $vars['orderby'] ) && 'property_address_suburb' === $vars['orderby'] ) {
27: $vars = array_merge(
28: $vars,
29: array(
30: 'meta_key' => 'property_address_suburb', // phpcs:ignore WordPress.DB.SlowDBQuery
31: 'orderby' => 'meta_value',
32: )
33: );
34: }
35: return $vars;
36: }
37: add_filter( 'request', 'epl_property_address_suburb_column_orderby' );
38:
39: // Add custom filters to post type posts listings.
40: add_action( 'restrict_manage_posts', 'epl_custom_restrict_manage_posts' );
41: add_filter( 'parse_query', 'epl_admin_posts_filter' );
42:
43: /**
44: * Add custom filters to post type posts listings.
45: *
46: * @since 1.0
47: * @since 3.4.45 Added deleted status. Reordered status options.
48: * @since 3.5 Added accessibility labels to select elements. Removed: from Search For, using function to return status labels.
49: */
50: function epl_custom_restrict_manage_posts() {
51: global $post_type;
52: if ( 'property' === $post_type || 'rental' === $post_type || 'land' === $post_type || 'commercial' === $post_type || 'rural' === $post_type || 'business' === $post_type || 'holiday_rental' === $post_type || 'commercial_land' === $post_type ) {
53:
54: // Filter by property_status.
55: $fields = array();
56: $fields['current'] = epl_get_the_status_label( 'current' );
57:
58: if ( 'rental' !== $post_type && 'holiday_rental' !== $post_type ) {
59: $fields['sold'] = apply_filters( 'epl_sold_label_status_filter', epl_get_the_status_label( 'sold' ) );
60: }
61:
62: if ( 'rental' === $post_type || 'holiday_rental' === $post_type || 'commercial' === $post_type || 'business' === $post_type || 'commercial_land' === $post_type ) {
63: $fields['leased'] = apply_filters( 'epl_leased_label_status_filter', epl_get_the_status_label( 'leased' ) );
64: }
65:
66: $fields['withdrawn'] = epl_get_the_status_label( 'withdrawn' );
67: $fields['offmarket'] = epl_get_the_status_label( 'offmarket' );
68: $fields['deleted'] = epl_get_the_status_label( 'deleted' );
69:
70: if ( ! empty( $fields ) ) {
71: $_GET['property_status'] = isset( $_GET['property_status'] ) ? sanitize_text_field( wp_unslash( $_GET['property_status'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification
72: echo '<select aria-label="' . esc_attr__( 'Filter By Type', 'easy-property-listings' ) . '" name="property_status">';
73: echo '<option value="">' . esc_html__( 'Filter By Type', 'easy-property-listings' ) . '</option>';
74: foreach ( $fields as $k => $v ) {
75: $selected = ( sanitize_text_field( wp_unslash( $_GET['property_status'] ) ) === $k ? 'selected="selected"' : '' ); // phpcs:ignore WordPress.Security.NonceVerification
76: echo '<option value="' . esc_attr( $k ) . '" ' . esc_attr( $selected ) . '>' . esc_attr( $v ) . '</option>';
77: }
78: echo '</select>';
79: }
80:
81: $property_author = isset( $_GET['property_author'] ) ? intval( $_GET['property_author'] ) : ''; // phpcs:ignore WordPress.Security.NonceVerification
82: // filter by authors.
83: wp_dropdown_users(
84: array(
85: 'name' => 'property_author',
86: 'selected' => $property_author,
87: 'show_option_all' => __( 'All Users', 'easy-property-listings' ),
88: 'role__not_in' => array( 'subscriber' ),
89: )
90: );
91:
92: $custom_search_fields = array(
93: 'property_address_suburb' => epl_labels( 'label_suburb' ),
94: 'property_office_id' => __( 'Office ID', 'easy-property-listings' ),
95: 'property_agent' => __( 'Listing Agent', 'easy-property-listings' ),
96: 'property_second_agent' => __( 'Second Listing Agent', 'easy-property-listings' ),
97: 'property_unique_id' => __( 'Property ID', 'easy-property-listings' ),
98: );
99: $custom_search_fields = apply_filters( 'epl_admin_search_fields', $custom_search_fields );
100:
101: if ( ! empty( $custom_search_fields ) ) {
102: $sel = isset( $_GET['property_custom_fields'] ) ? sanitize_text_field( wp_unslash( $_GET['property_custom_fields'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification
103: echo '<select aria-label="' . esc_attr__( 'Search For', 'easy-property-listings' ) . '" name="property_custom_fields">';
104: echo '<option value="">' . esc_html__( 'Search For', 'easy-property-listings' ) . '</option>';
105: foreach ( $custom_search_fields as $k => $v ) {
106: echo '<option value="' . esc_attr( $k ) . '" ' . selected( $sel, $k, false ) . '>' . esc_attr( $v ) . '</option>';
107: }
108: echo '</select>';
109: }
110:
111: // Filter by Suburb.
112: if ( isset( $_GET['property_custom_value'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
113: $val = sanitize_text_field( wp_unslash( $_GET['property_custom_value'] ) ); // phpcs:ignore WordPress.Security.NonceVerification
114: } else {
115: $val = '';
116: }
117: echo '<input type="text" name="property_custom_value" placeholder="' . esc_html__( 'Search Value.', 'easy-property-listings' ) . '" value="' . esc_attr( $val ) . '" />';
118: }
119: }
120:
121: /**
122: * Admin Posts Filter.
123: *
124: * @param WP_Query $query WordPress query.
125: *
126: * @since 1.0.0
127: * @since 3.4.16 Filter by property author now shows results for both primary and secondary author.
128: */
129: function epl_admin_posts_filter( $query ) {
130: // phpcs:disable WordPress.Security.NonceVerification
131: global $pagenow;
132: if ( is_admin() && 'edit.php' === $pagenow && in_array( $query->get( 'post_type' ), epl_get_core_post_types(), true ) ) {
133: $meta_query = (array) $query->get( 'meta_query' );
134:
135: if ( isset( $_GET['property_status'] ) && ! empty( $_GET['property_status'] ) ) {
136: $meta_query[] = array(
137: 'key' => 'property_status',
138: 'value' => sanitize_text_field( wp_unslash( $_GET['property_status'] ) ),
139: );
140: }
141:
142: if ( isset( $_GET['property_author'] ) && ! empty( $_GET['property_author'] ) ) {
143: $author = intval( $_GET['property_author'] ); // WPCS: XSS ok.
144: $author_object = get_user_by( 'id', $author );
145: $meta_query[] = array(
146: 'relation' => 'OR',
147: array(
148: 'key' => 'property_agent',
149: 'value' => $author_object->user_login,
150: ),
151: array(
152: 'key' => 'property_second_agent',
153: 'value' => $author_object->user_login,
154: ),
155: );
156: }
157:
158: if ( ! empty( $_GET['property_custom_value'] ) && ! empty( $_GET['property_custom_fields'] ) ) {
159:
160: $meta_query[] = array(
161: 'key' => sanitize_text_field( wp_unslash( $_GET['property_custom_fields'] ) ),
162: 'value' => sanitize_text_field( wp_unslash( $_GET['property_custom_value'] ) ),
163: 'compare' => 'LIKE',
164: );
165:
166: }
167:
168: if ( ! empty( $meta_query ) ) {
169: $query->set( 'meta_query', $meta_query );
170: }
171: }
172: }
173:
174: /**
175: * Manage Property Columns Sorting.
176: *
177: * @param array $columns Columns.
178: *
179: * @return array
180: * @since 1.0
181: */
182: function epl_manage_listings_sortable_columns( $columns ) {
183: $columns['property_featured'] = 'property_featured';
184: $columns['property_rent'] = 'property_rent';
185: $columns['property_price'] = 'property_price';
186: $columns['property_status'] = 'property_status';
187: $columns['listing_id'] = 'listing_id';
188: $columns['agent'] = 'agent';
189: $columns['property_thumb'] = 'property_thumb';
190: return $columns;
191: }
192:
193: $epl_posts = array( 'property', 'land', 'commercial', 'business', 'commercial_land', 'location_profile', 'rental', 'rural' );
194:
195: foreach ( $epl_posts as $epl_post ) {
196: add_filter( 'manage_edit-' . $epl_post . '_sortable_columns', 'epl_manage_listings_sortable_columns' );
197: }
198:
199: /**
200: * Manage Listing Columns Sorting.
201: *
202: * @since 1.0
203: * @param WP_Query $query WordPress query.
204: */
205: function epl_custom_orderby( $query ) {
206: if ( ! is_admin() ) {
207: return;
208: }
209:
210: $orderby = $query->get( 'orderby' );
211:
212: if ( 'property_price' === $orderby ) {
213: $query->set( 'meta_key', 'property_price' );
214: $query->set( 'orderby', 'meta_value_num' );
215: }
216:
217: if ( 'property_rent' === $orderby ) {
218: $query->set( 'meta_key', 'property_rent' );
219: $query->set( 'orderby', 'meta_value_num' );
220: }
221:
222: if ( 'listing_id' === $orderby ) {
223: $query->set( 'meta_key', 'property_unique_id' );
224: $query->set( 'orderby', 'meta_value' );
225: }
226:
227: if ( 'property_thumb' === $orderby ) {
228: $query->set( 'meta_key', '_thumbnail_id' );
229: $query->set( 'orderby', 'meta_value' );
230: }
231:
232: if ( 'property_featured' === $orderby ) {
233: $query->set( 'meta_key', 'property_featured' );
234: $query->set( 'orderby', 'meta_value' );
235: }
236: }
237: // handle sorting of admin columns.
238: add_filter( 'pre_get_posts', 'epl_custom_orderby' );
239:
240: /**
241: * Functions for post column contents.
242: *
243: * @since 2.2.0
244: * @since 3.4.0 Now using epl_get_option function.
245: */
246: function epl_manage_listing_column_property_thumb_callback() {
247:
248: if ( function_exists( 'the_post_thumbnail' ) ) {
249: $thumb_size = epl_get_option( 'epl_admin_thumb_size', 'admin-list-thumb' );
250:
251: the_post_thumbnail( $thumb_size );
252: }
253: }
254: add_action( 'epl_manage_listing_column_property_thumb', 'epl_manage_listing_column_property_thumb_callback' );
255:
256: /**
257: * Posts Types Columns.
258: *
259: * @since 1.0.0
260: * @since 3.4.23 Altered the admin output of property_category to use the label instead of value.
261: * @since 3.4.23 Added land unit filter epl_property_land_area_unit_label to admin area when viewing listings.
262: * @since 3.4.27 Fixed html escaping issue and formatting for land size.
263: * @since 3.4.30 Using epl_get_meta_field_label for dynamic labels.
264: * @since 3.5 Escaping values.
265: * @since 3.5.10 Fix warning for trim when home_open is null.
266: */
267: function epl_manage_listing_column_listing_callback() {
268: global $post, $property;
269:
270: $property_address_suburb = get_the_term_list( $post->ID, 'location', '', ', ', '' );
271: $heading = $property->get_property_meta( 'property_heading' );
272: $home_open = $property->get_property_meta( 'property_inspection_times' );
273: $home_open = is_string( $home_open ) ? trim( $home_open ) : '';
274: $beds = $property->get_property_meta( 'property_bedrooms' );
275: $baths = $property->get_property_meta( 'property_bathrooms' );
276: $rooms = $property->get_property_meta( 'property_rooms', false );
277: $land = $property->get_property_meta( 'property_land_area', false );
278: $land_unit = $property->get_property_meta( 'property_land_area_unit' );
279: $category = $property->get_property_meta( 'property_category' );
280:
281: // Commercial Specific fields.
282: $commercial_category = $property->get_property_meta( 'property_commercial_category' );
283: $outgoings = $property->get_property_meta( 'property_com_outgoings' );
284: $return = $property->get_property_meta( 'property_com_return' );
285:
286: // Business Specific fields.
287: $taking = $property->get_property_meta( 'property_bus_takings' );
288: $franchise = $property->get_property_meta( 'property_bus_franchise' );
289: $taking = $property->get_property_meta( 'property_bus_terms' );
290:
291: if ( is_array( $commercial_category ) ) {
292: $commercial_category = implode( ', ', $commercial_category );
293: }
294:
295: // Heading.
296: if ( empty( $heading ) ) {
297: echo '<strong>' . esc_html__( 'Important! Set a Heading', 'easy-property-listings' ) . '</strong>';
298: } else {
299: echo '<div class="type_heading"><strong>', wp_kses(
300: $heading,
301: array(
302: 'strong' => array(),
303: 'b' => array(),
304: )
305: ), '</strong></div>';
306: }
307:
308: // Category for commercial listing type.
309: if ( ! empty( $commercial_category ) ) {
310: echo '<div class="epl_meta_category">', esc_html( $commercial_category ), '</div>';
311: }
312:
313: /**
314: * TODO: Factor in Business category.
315: * Need to factor in business category: <businessCategory id="1">.
316: * Need to factor in business category: <name>Food/Hospitality</name>.
317: * Need to factor in business category: <businessSubCategory>.
318: * Need to factor in business category: <name>Takeaway Food</name>.
319: * Need to factor in business category: </businessSubCategory>.
320: * Need to factor in business category: </businessCategory>.
321: * Need to factor in business category: <businessCategory id="2"/>.
322: * Need to factor in business category: <businessCategory id="3"/>.
323: * Need to factor in business fields: property_bus_takings (number).
324: * Need to factor in business fields: property_bus_franchise (yes/no).
325: */
326:
327: // Listing Location Taxonomy.
328: echo '<div class="type_suburb">', wp_kses(
329: $property_address_suburb,
330: array(
331: 'strong' => array(),
332: 'b' => array(),
333: 'a' => array(
334: 'href' => array(),
335: ),
336: )
337: ), '</div>';
338:
339: // Listing Category.
340: if ( ! empty( $category ) ) {
341: $property_category = $property->get_property_category( 'span', 'epl_meta_property_category' );
342: echo '<div class="epl_meta_category">', wp_kses_post( $property_category ), '</div>';
343: }
344:
345: // Outgoings for commercial listing type.
346: if ( ! empty( $outgoings ) ) {
347: echo '<div class="epl_meta_outgoings">' . esc_html( epl_get_meta_field_label( 'property_com_outgoings' ) ) . ': ', esc_html( epl_currency_formatted_amount( $outgoings ) ), '</div>';
348: }
349:
350: // Return for commercial listing type.
351: if ( ! empty( $return ) ) {
352: echo '<div class="epl_meta_return">' . esc_html( epl_get_meta_field_label( 'property_com_return' ) ) . ': ', esc_html( $return ), '%</div>';
353: }
354:
355: // Bedrooms and Bathrooms.
356: if ( ! empty( $beds ) || ! empty( $baths ) ) {
357: echo '<div class="epl_meta_beds_baths">';
358: echo '<span class="epl_meta_beds">', esc_attr( $beds ), ' ', esc_html__( 'Beds', 'easy-property-listings' ), ' | </span>';
359: echo '<span class="epl_meta_baths">', esc_attr( $baths ), ' ', esc_html__( 'Baths', 'easy-property-listings' ), '</span>';
360: echo '</div>';
361: }
362:
363: // Rooms.
364: if ( ! empty( $rooms ) ) {
365: if ( 1 === absint( $rooms ) ) {
366: echo '<div class="epl_meta_rooms">', esc_attr( $rooms ), ' ', esc_html__( 'Room', 'easy-property-listings' ), '</div>';
367: } else {
368: echo '<div class="epl_meta_rooms">', esc_attr( $rooms ), ' ', esc_html( epl_get_meta_field_label( 'property_rooms' ) ), '</div>';
369: }
370: }
371:
372: // Land area.
373: if ( ! empty( $land ) ) {
374:
375: $decimal_formatted = apply_filters( 'epl_land_value_decimal_format', true );
376:
377: if ( $decimal_formatted ) {
378: $land = epl_format_amount( $land, true, true );
379: }
380: echo '<div class="epl_meta_land_details">';
381: echo '<span class="epl_meta_land">', wp_kses_post( $land ), '</span>';
382:
383: if ( 'squareMeter' === $land_unit ) {
384: $land_unit = esc_html__( 'm&#178;', 'easy-property-listings' );
385: }
386: $land_unit = apply_filters( 'epl_property_land_area_unit_label', $land_unit );
387:
388: echo '<span class="epl_meta_land_unit"> ', wp_kses_post( $land_unit ), '</span>';
389: echo '</div>';
390: }
391:
392: // Home Open date and time.
393: if ( ! empty( $home_open ) ) {
394: $home_open = array_filter( explode( "\n", $home_open ) );
395: $home_open_list = '<ul class="epl_meta_home_open">';
396: foreach ( $home_open as $num => $item ) {
397: $home_open_list .= '<li>' . htmlspecialchars( $item, ENT_QUOTES, 'UTF-8' ) . '</li>';
398: }
399: $home_open_list .= '</ul>';
400: echo '<div class="epl_meta_home_open_label"><span class="home-open"><strong>' . esc_html( epl_labels( 'label_home_open' ) ) . '</strong></span>', wp_kses_post( $home_open_list ), '</div>';
401: }
402: }
403: add_action( 'epl_manage_listing_column_listing', 'epl_manage_listing_column_listing_callback' );
404:
405: /**
406: * Get Listing Labels.
407: *
408: * @param array $args Array of arguments.
409: * @param string $returntype The type of return formatting filterable with epl_manage_listing_column_labels_return_type.
410: *
411: * @return false|string
412: * @since 3.3
413: */
414: function epl_get_manage_listing_column_labels( $args = array(), $returntype = 'l' ) {
415:
416: global $property;
417:
418: $defaults = array( 'featured' );
419: $labels = apply_filters( 'epl_manage_listing_column_labels', $defaults );
420: $returntype = apply_filters( 'epl_manage_listing_column_labels_return_type', $returntype );
421:
422: ob_start();
423:
424: foreach ( $labels as $label ) {
425: if ( ! empty( $args ) && ! in_array( $label, $args, true ) ) {
426: continue;
427: }
428:
429: switch ( $label ) {
430: case 'featured':
431: echo $property->get_property_featured( $returntype ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
432: break;
433:
434: default:
435: // Action to hook additional icons.
436: do_action( 'epl_get_manage_listing_column_label_' . $label );
437: break;
438: }
439: }
440:
441: return ob_get_clean();
442: }
443:
444: /**
445: * Featured Listing Label to Listing Details column.
446: *
447: * @since 3.3
448: * @param string $returntype The type of return formatting filterable with epl_manage_listing_column_labels_return_type.
449: */
450: function epl_manage_listing_column_labels_callback( $returntype = 'l' ) {
451:
452: $returntype = empty( $returntype ) ? 'l' : $returntype;
453:
454: echo '<ul class="epl-listing-labels">' . epl_get_manage_listing_column_labels( array(), $returntype ) . '</ul>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
455: }
456: add_action( 'epl_manage_listing_column_listing', 'epl_manage_listing_column_labels_callback', 20 );
457:
458: /**
459: * Posts Types Column ID
460: *
461: * @since 1.0
462: */
463: function epl_manage_listing_column_listing_id_callback() {
464: global $post;
465:
466: $unique_id = get_post_meta( $post->ID, 'property_unique_id', true );
467: // If no duration is found, output a default message.
468: if ( ! empty( $unique_id ) ) {
469: echo esc_attr( $unique_id );
470: }
471: }
472: add_action( 'epl_manage_listing_column_listing_id', 'epl_manage_listing_column_listing_id_callback' );
473:
474: /**
475: * Posts Types Column Geocode.
476: *
477: * @since 1.0
478: */
479: function epl_manage_listing_column_geo_callback() {
480: global $post;
481:
482: $property_address_coordinates = get_post_meta( $post->ID, 'property_address_coordinates', true );
483: // If no lat long coordinates saved, display default message.
484: if ( ',' === $property_address_coordinates || empty( $property_address_coordinates ) ) {
485: esc_html_e( 'No', 'easy-property-listings' );
486: } else {
487: echo esc_html( $property_address_coordinates );
488: }
489: }
490: add_action( 'epl_manage_listing_column_geo', 'epl_manage_listing_column_geo_callback' );
491:
492: /**
493: * Posts Types Column Price.
494: *
495: * @since 1.0.0
496: * @since 3.4.0 Now using epl_get_option function.
497: * @since 3.5 Set the bar value to integer.
498: * @since 3.5.11 Removed unnecessary uppercase function for status in admin columns.
499: * @since 3.5.15 Fix: Sold price not displaying in admin.
500: */
501: function epl_manage_listing_column_price_callback() {
502: global $post, $property;
503:
504: $price = $property->get_property_meta( 'property_price' );
505: $view = $property->get_property_meta( 'property_price_view' );
506: $property_status = $property->get_property_meta( 'property_status' );
507: $property_authority = $property->get_property_meta( 'property_authority' );
508: $sold_price = $property->get_property_meta( 'property_sold_price' );
509: $property_under_offer = $property->get_property_meta( 'property_under_offer' );
510: $lease = $property->get_property_meta( 'property_com_rent' );
511: $lease_period = $property->get_property_meta( 'property_com_rent_period' );
512: $lease_date = $property->get_property_meta( 'property_com_lease_end_date' );
513: $d_bond = '';
514: $bond = '';
515: $max_price = (int) epl_get_option( 'epl_max_graph_sales_price', '2000000' );
516:
517: // Rental Listing Type Custom Values.
518: if ( 'rental' === $post->post_type ) {
519:
520: $price = $property->get_property_meta( 'property_rent' );
521: $view = $property->get_property_meta( 'property_rent_view' );
522:
523: $d_bond = epl_get_option( 'display_bond' );
524: $bond = $property->get_property_meta( 'property_bond', false );
525:
526: $max_price = (int) epl_get_option( 'epl_max_graph_rent_price', '2000' );
527: }
528:
529: // Commercial Listing Lease Type Price.
530: if ( 'commercial' === $post->post_type && 'lease' === $property->get_property_meta( 'property_com_listing_type' ) ) {
531:
532: /**
533: * TODO: Commercial features consideration.
534: * Needs consideration and configuring property_com_listing_type.
535: * Needs consideration and configuring property_com_rent.
536: * Needs consideration and configuring property_com_rent_period.
537: * Needs consideration and configuring property_com_rent_range_min.
538: * Needs consideration and configuring property_com_rent_range_max.
539: */
540:
541: $price = $property->get_property_meta( 'property_com_rent' );
542: $max_price = (int) epl_get_option( 'epl_max_graph_rent_price', '2000' );
543: }
544:
545: if ( 'sold' === $property_status ) {
546: $class = 'bar-home-sold';
547: } elseif ( 'leased' === $property_status ) {
548: $class = 'bar-home-sold';
549: } elseif ( ! empty( $property_under_offer ) && 'yes' === $property_under_offer ) {
550: $class = 'bar-under-offer';
551: } elseif ( 'current' === $property_status ) {
552: $class = 'bar-home-open';
553: } else {
554: $class = '';
555: }
556:
557: // If we have a sold price.
558: if ( ! empty( $sold_price ) ) {
559: $bar_price = $sold_price;
560: // If we have a regular price.
561: } elseif ( ! empty( $price ) ) {
562: $bar_price = $price;
563: }
564:
565: // If we have a price to display in the bar.
566: if ( ! empty( $bar_price ) ) {
567: $bar_width = 0 === $max_price ? 0 : intval( $bar_price ) / $max_price * 100;
568: echo '<div class="epl-price-bar ' . esc_attr( $class ) . '">
569: <span style="width:' . esc_attr( $bar_width ) . '%"></span>
570: </div>';
571: // Otherwise, there is no price set.
572: } else {
573: echo esc_html__( 'No price set', 'easy-property-listings' );
574: }
575:
576: // Display sold price.
577: if ( ! empty( $sold_price ) ) {
578: echo '<div class="epl_meta_search_price">' . wp_kses_post( $property->get_price_plain_value() ) . ' ';
579: echo 'sold' === $property_status ? esc_html( epl_currency_formatted_amount( $sold_price ) ) : '';
580: echo '</div>';
581: } else {
582: echo '<div class="epl_meta_price">' . wp_kses_post( $property->get_price_plain_value() ) . '</div>';
583: }
584:
585: // Bond for rental listing type.
586: if ( ! empty( $bond ) && 1 === $d_bond ) {
587: echo '<div class="epl_meta_bond">', esc_html( epl_labels( 'label_bond' ) ), ' ', esc_html( epl_currency_formatted_amount( $bond ) ), '</div>';
588: }
589:
590: // Lease period for commercial listing type.
591: if ( ! empty( $lease_date ) ) {
592: echo '<div class="epl_meta_lease_date">' . esc_html__( 'Lease End:', 'easy-property-listings' ) . ' ', esc_html( $lease_date ), '</div>';
593: }
594:
595: // Lease period for Commercial listing type.
596: if ( ! empty( $lease ) ) {
597: if ( empty( $lease_period ) ) {
598: $lease_period = esc_html( 'annual' );
599: }
600: echo '<div class="epl_meta_lease_price">Lease: ', esc_html( epl_currency_formatted_amount( $lease ) ), ' ', esc_html( epl_listing_load_meta_commercial_rent_period_value( $lease_period ) ), '</div>';
601: }
602: }
603: add_action( 'epl_manage_listing_column_price', 'epl_manage_listing_column_price_callback' );
604:
605: /**
606: * Posts Types Column Status.
607: *
608: * @since 1.0
609: * @since 3.4.45 Added deleted status. Re-ordered.
610: * @since 3.5 Corrected esc function for label.
611: * @since 3.5.0 Using the global function to get status labels.
612: */
613: function epl_manage_listing_column_property_status_callback() {
614: global $post, $property;
615:
616: $property_status = get_post_meta( $post->ID, 'property_status', true );
617: $labels_property_status = apply_filters(
618: 'epl_labels_property_status_filter',
619: array(
620: 'current' => epl_get_the_status_label( 'current' ),
621: 'sold' => $property->label_sold,
622: 'leased' => $property->label_leased,
623: 'withdrawn' => epl_get_the_status_label( 'withdrawn' ),
624: 'offmarket' => epl_get_the_status_label( 'offmarket' ),
625: 'deleted' => epl_get_the_status_label( 'deleted' ),
626: )
627: );
628: if ( ! empty( $property_status ) ) {
629: echo '<span class="type_' . esc_attr( strtolower( $property_status ) ) . '">' . esc_html( $labels_property_status[ $property_status ] ) . '</span>';
630: }
631: }
632: add_action( 'epl_manage_listing_column_property_status', 'epl_manage_listing_column_property_status_callback' );
633:
634: /**
635: * Posts Types Column Listing Type
636: *
637: * @since 1.0
638: */
639: function epl_manage_listing_column_listing_type_callback() {
640: global $post;
641:
642: // Get the post meta.
643: $listing_type = get_post_meta( $post->ID, 'property_com_listing_type', true );
644: // If no duration is found, output a default message.
645: if ( ! empty( $listing_type ) ) {
646: echo esc_html( $listing_type );
647: }
648: }
649: add_action( 'epl_manage_listing_column_listing_type', 'epl_manage_listing_column_listing_type_callback' );
650:
651: /**
652: * Show agent name in column.
653: *
654: * @since 3.5.3.
655: */
656: function epl_show_agent_name_in_column() {
657:
658: global $property, $post;
659:
660: $agent_keys = array(
661: 'property_second_agent',
662: 'property_third_agent',
663: 'property_fourth_agent',
664: );
665:
666: foreach ( $agent_keys as $agent_key ) {
667:
668: $agent = $property->get_property_meta( $agent_key );
669:
670: if ( ! empty( $agent ) ) {
671:
672: $current_author = get_user_by( 'login', $agent );
673:
674: if ( false !== $current_author ) {
675: $url = add_query_arg(
676: array(
677: 'post_type' => $post->post_type,
678: 'author' => $current_author->ID,
679: ),
680: 'edit.php'
681: );
682: ?>
683: <div class="epl-meta epl-meta--agent epl-meta--<?php echo esc_attr( $agent_key ); ?>">
684: <span class="epl-agent epl-agent--name">
685: <a href="<?php echo esc_url( $url ); ?>">
686: <?php echo esc_html( get_the_author_meta( 'display_name', $current_author->ID ) ); ?>
687: </a>
688: </span>
689: </div>
690: <?php
691: } else {
692: ?>
693: <div class="epl-meta epl-meta--agent epl-meta--<?php echo esc_attr( $agent_key ); ?>">
694: <span class="epl-agent epl-agent--name"><?php echo esc_html( $agent ); ?></span>
695: </div>
696: <?php
697: }
698: epl_reset_post_author();
699: }
700: }
701: }
702:
703: /**
704: * Posts Types Agent/Author
705: *
706: * @since 1.0
707: */
708: function epl_manage_listing_column_agent_callback() {
709: global $post, $property;
710:
711: printf(
712: '<a href="%s">%s</a>',
713: esc_url(
714: add_query_arg(
715: array(
716: 'post_type' => $post->post_type,
717: 'author' => get_the_author_meta( 'ID' ),
718: ),
719: 'edit.php'
720: )
721: ),
722: get_the_author()
723: );
724:
725: epl_show_agent_name_in_column();
726: }
727: add_action( 'epl_manage_listing_column_agent', 'epl_manage_listing_column_agent_callback' );
728:
729: /**
730: * Functions for featured listing column.
731: *
732: * @since 3.3
733: */
734: function epl_manage_listing_column_featured_callback() {
735:
736: global $property;
737:
738: if ( 'yes' === $property->get_property_meta( 'property_featured' ) ) {
739: echo '<span class="dashicons dashicons-star-filled"></span>';
740: } else {
741: echo '<span class="dashicons dashicons-star-empty"></span>';
742: }
743: }
744: add_action( 'epl_manage_listing_column_featured', 'epl_manage_listing_column_featured_callback' );
745: