1: <?php
2: /**
3: * Register post type Rural.
4: *
5: * @package EPL
6: * @subpackage PostTypes/Rural
7: * @copyright Copyright (c) 2019, 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 Rural custom post type.
19: *
20: * @since 1.0
21: * @since 3.5.1 View Rural Listings added for plural.
22: *
23: * @return void
24: */
25: function epl_register_custom_post_type_rural() {
26:
27: $archives = defined( 'EPL_RURAL_DISABLE_ARCHIVE' ) && EPL_RURAL_DISABLE_ARCHIVE ? false : true;
28: $slug = defined( 'EPL_RURAL_SLUG' ) ? EPL_RURAL_SLUG : 'rural';
29: $rewrite = defined( 'EPL_RURAL_DISABLE_REWRITE' ) && EPL_RURAL_DISABLE_REWRITE ? false : array(
30: 'slug' => $slug,
31: 'with_front' => false,
32: );
33: $rest = defined( 'EPL_RURAL_DISABLE_REST' ) && EPL_RURAL_DISABLE_REST ? false : true;
34:
35: $labels = apply_filters(
36: 'epl_rural_labels',
37: array(
38: 'name' => __( 'Rural', 'easy-property-listings' ),
39: 'singular_name' => __( 'Rural', 'easy-property-listings' ),
40: 'menu_name' => __( 'Rural', 'easy-property-listings' ),
41: 'add_new' => __( 'Add New', 'easy-property-listings' ),
42: 'add_new_item' => __( 'Add New Rural Listing', 'easy-property-listings' ),
43: 'edit_item' => __( 'Edit Rural Listing', 'easy-property-listings' ),
44: 'new_item' => __( 'New Rural Listing', 'easy-property-listings' ),
45: 'update_item' => __( 'Update Rural Listing', 'easy-property-listings' ),
46: 'all_items' => __( 'All Rural Listings', 'easy-property-listings' ),
47: 'view_item' => __( 'View Rural Listing', 'easy-property-listings' ),
48: 'view_items' => __( 'View Rural Listings', 'easy-property-listings' ),
49: 'search_items' => __( 'Search Rural Listing', 'easy-property-listings' ),
50: 'not_found' => __( 'Rural Listing Not Found', 'easy-property-listings' ),
51: 'not_found_in_trash' => __( 'Rural Listing Not Found in Trash', 'easy-property-listings' ),
52: 'parent_item_colon' => __( 'Parent Rural Listing:', 'easy-property-listings' ),
53: )
54: );
55:
56: $rural_args = array(
57: 'labels' => $labels,
58: 'public' => true,
59: 'publicly_queryable' => true,
60: 'show_ui' => true,
61: 'show_in_menu' => true,
62: 'query_var' => true,
63: 'rewrite' => $rewrite,
64: 'menu_icon' => 'dashicons-location-alt',
65: 'capability_type' => 'post',
66: 'has_archive' => $archives,
67: 'hierarchical' => false,
68: 'menu_position' => '26.4',
69: 'show_in_rest' => $rest,
70: 'taxonomies' => array( 'location', 'tax_feature' ),
71: 'supports' => apply_filters( 'epl_rural_supports', array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments' ) ),
72: );
73: epl_register_post_type( 'rural', 'Rural', apply_filters( 'epl_rural_post_type_args', $rural_args ) );
74: }
75: add_action( 'init', 'epl_register_custom_post_type_rural', 0 );
76:
77: /**
78: * Manage Admin Rural Post Type Columns
79: *
80: * @since 1.0
81: * @return void
82: */
83: if ( is_admin() ) {
84: /**
85: * Manage Admin Rural Post Type Columns: Heading
86: *
87: * @param array $columns Column array.
88: *
89: * @return mixed|void $columns with epl_post_type_commercial_land_admin_columns filter.
90: * @since 1.0
91: */
92: function epl_manage_rural_columns_heading( $columns ) {
93: global $epl_settings;
94:
95: $columns = array(
96: 'cb' => '<input type="checkbox" />',
97: 'property_featured' => '<span class="dashicons dashicons-star-half"></span><span class="epl-manage-featured">' . __( 'Featured', 'easy-property-listings' ) . '</span>',
98: 'property_thumb' => __( 'Image', 'easy-property-listings' ),
99: 'property_price' => __( 'Price', 'easy-property-listings' ),
100: 'title' => __( 'Address', 'easy-property-listings' ),
101: 'listing' => __( 'Listing Details', 'easy-property-listings' ),
102: 'listing_id' => __( 'Unique ID', 'easy-property-listings' ),
103: 'geo' => __( 'Geo', 'easy-property-listings' ),
104: 'property_status' => __( 'Status', 'easy-property-listings' ),
105: 'agent' => __( 'Agent', 'easy-property-listings' ),
106: 'date' => __( 'Date', 'easy-property-listings' ),
107: ) + $columns;
108:
109: // unset author columns as duplicate of agent column.
110: unset( $columns['author'] );
111: unset( $columns['comments'] );
112:
113: // Geocode Column.
114: if ( 1 !== (int) epl_get_option( 'debug', 0 ) ) {
115: unset( $columns['geo'] );
116: }
117:
118: // Listing ID Column.
119: if ( 1 !== (int) epl_get_option( 'admin_unique_id', 0 ) ) {
120: unset( $columns['listing_id'] );
121: }
122:
123: return apply_filters( 'epl_post_type_rural_admin_columns', $columns );
124: }
125: add_filter( 'manage_edit-rural_columns', 'epl_manage_rural_columns_heading' );
126:
127: /**
128: * Manage Admin Rural Post Type Columns: Row Contents
129: *
130: * @since 1.0
131: * @param string $column column.
132: * @param int $post_id post id.
133: */
134: function epl_manage_rural_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 'real-estate' 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_rural_posts_custom_column', 'epl_manage_rural_columns_value', 10, 2 );
192: }
193: