1: <?php
2: /**
3: * Register post type :: Property
4: *
5: * @package EPL
6: * @subpackage PostTypes/Property
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: * Registers and sets up the Property custom post type.
19: *
20: * @return void
21: *
22: * @since 3.5.1 View Listings added for plural.
23: */
24: function epl_register_custom_post_type_property() {
25:
26: $archives = defined( 'EPL_PROPERTY_DISABLE_ARCHIVE' ) && EPL_PROPERTY_DISABLE_ARCHIVE ? false : true;
27: $slug = defined( 'EPL_PROPERTY_SLUG' ) ? EPL_PROPERTY_SLUG : 'property';
28: $rewrite = defined( 'EPL_PROPERTY_DISABLE_REWRITE' ) && EPL_PROPERTY_DISABLE_REWRITE ? false : array(
29: 'slug' => $slug,
30: 'with_front' => false,
31: );
32: $rest = defined( 'EPL_PROPERTY_DISABLE_REST' ) && EPL_PROPERTY_DISABLE_REST ? false : true;
33:
34: $labels = apply_filters(
35: 'epl_property_labels',
36: array(
37: 'name' => __( 'Properties', 'easy-property-listings' ),
38: 'singular_name' => __( 'Property', 'easy-property-listings' ),
39: 'menu_name' => __( 'Property', 'easy-property-listings' ),
40: 'add_new' => __( 'Add New', 'easy-property-listings' ),
41: 'add_new_item' => __( 'Add New Listing', 'easy-property-listings' ),
42: 'edit_item' => __( 'Edit Listing', 'easy-property-listings' ),
43: 'new_item' => __( 'New Listing', 'easy-property-listings' ),
44: 'update_item' => __( 'Update Listing', 'easy-property-listings' ),
45: 'all_items' => __( 'All Listings', 'easy-property-listings' ),
46: 'view_item' => __( 'View Listing', 'easy-property-listings' ),
47: 'view_items' => __( 'View Listings', 'easy-property-listings' ),
48: 'search_items' => __( 'Search Listing', 'easy-property-listings' ),
49: 'not_found' => __( 'Listing Not Found', 'easy-property-listings' ),
50: 'not_found_in_trash' => __( 'Listing Not Found in Trash', 'easy-property-listings' ),
51: 'parent_item_colon' => __( 'Parent Listing:', 'easy-property-listings' ),
52: )
53: );
54:
55: $property_args = array(
56: 'labels' => $labels,
57: 'public' => true,
58: 'publicly_queryable' => true,
59: 'show_ui' => true,
60: 'show_in_menu' => true,
61: 'query_var' => true,
62: 'rewrite' => $rewrite,
63: 'menu_icon' => 'dashicons-admin-home',
64: 'capability_type' => 'post',
65: 'has_archive' => $archives,
66: 'hierarchical' => false,
67: 'menu_position' => '26.2',
68: 'show_in_rest' => $rest,
69: 'taxonomies' => array( 'location', 'tax_feature' ),
70: 'supports' => apply_filters( 'epl_property_supports', array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments' ) ),
71: );
72: epl_register_post_type( 'property', 'Property (Residential)', apply_filters( 'epl_property_post_type_args', $property_args ) );
73: }
74: add_action( 'init', 'epl_register_custom_post_type_property', 0 );
75:
76: /**
77: * Manage Admin Property Post Type Columns.
78: *
79: * @since 1.0
80: * @return void
81: */
82: if ( is_admin() ) {
83: /**
84: * Manage Admin Property Post Type Columns: Heading.
85: *
86: * @param array $columns Column array.
87: *
88: * @return mixed|void $columns with epl_post_type_commercial_land_admin_columns filter.
89: * @since 1.0
90: */
91: function epl_manage_property_columns_heading( $columns ) {
92: global $epl_settings;
93:
94: $columns = array(
95: 'cb' => '<input type="checkbox" />',
96: 'property_featured' => '<span class="dashicons dashicons-star-half"></span><span class="epl-manage-featured">' . __( 'Featured', 'easy-property-listings' ) . '</span>',
97: 'property_thumb' => __( 'Image', 'easy-property-listings' ),
98: 'property_price' => __( 'Price', 'easy-property-listings' ),
99: 'title' => __( 'Address', 'easy-property-listings' ),
100: 'listing' => __( 'Listing Details', 'easy-property-listings' ),
101: 'listing_id' => __( 'Unique ID', 'easy-property-listings' ),
102: 'geo' => __( 'Geo', 'easy-property-listings' ),
103: 'property_status' => __( 'Status', 'easy-property-listings' ),
104: 'agent' => __( 'Agent', 'easy-property-listings' ),
105: 'date' => __( 'Date', 'easy-property-listings' ),
106: ) + $columns;
107:
108: // unset author columns as duplicate of agent column.
109: unset( $columns['author'] );
110: unset( $columns['comments'] );
111:
112: // Geocode Column.
113: if ( 1 !== (int) epl_get_option( 'debug', 0 ) ) {
114: unset( $columns['geo'] );
115: }
116:
117: // Listing ID Column.
118: if ( 1 !== (int) epl_get_option( 'admin_unique_id', 0 ) ) {
119: unset( $columns['listing_id'] );
120: }
121:
122: return apply_filters( 'epl_post_type_property_admin_columns', $columns );
123: }
124: add_filter( 'manage_edit-property_columns', 'epl_manage_property_columns_heading' );
125:
126: /**
127: * Manage Admin Property Post Type Columns: Row Contents.
128: *
129: * @since 1.0
130: * @revised 3.3
131: * @param string $column column.
132: * @param int $post_id post id.
133: */
134: function epl_manage_property_columns_value( $column, $post_id ) {
135:
136: switch ( $column ) {
137:
138: // If displaying the 'Featured Star' column.
139: case 'property_featured':
140: do_action( 'epl_manage_listing_column_featured' );
141:
142: break;
143:
144: // If displaying the 'Featured' image column.
145: case 'property_thumb':
146: do_action( 'epl_manage_listing_column_property_thumb' );
147:
148: break;
149:
150: // If displaying the 'Listing Details' column.
151: case 'listing':
152: do_action( 'epl_manage_listing_column_listing' );
153:
154: break;
155:
156: // If displaying the 'Listing ID' column.
157: case 'listing_id':
158: do_action( 'epl_manage_listing_column_listing_id' );
159:
160: break;
161:
162: // If displaying the 'Geocoding' column.
163: case 'geo':
164: do_action( 'epl_manage_listing_column_geo' );
165:
166: break;
167:
168: // If displaying the 'Price' column.
169: case 'property_price':
170: do_action( 'epl_manage_listing_column_price' );
171:
172: break;
173:
174: // If displaying the 'property_status' column.
175: case 'property_status':
176: do_action( 'epl_manage_listing_column_property_status' );
177:
178: break;
179:
180: // If displaying the 'agent' column.
181: case 'agent':
182: do_action( 'epl_manage_listing_column_agent' );
183:
184: break;
185:
186: // Just break out of the switch statement for everything else.
187: default:
188: break;
189: }
190: }
191: add_action( 'manage_property_posts_custom_column', 'epl_manage_property_columns_value', 10, 2 );
192: }
193: