1: <?php
2: /**
3: * Register post type :: Business
4: *
5: * @package EPL
6: * @subpackage PostTypes/Business
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 Business custom post type.
19: *
20: * @since 1.0
21: * @since 3.5.1 View Land Listings added for plural.
22: *
23: * @return void
24: */
25: function epl_register_custom_post_type_business() {
26:
27: $archives = defined( 'EPL_BUSINESS_DISABLE_ARCHIVE' ) && EPL_BUSINESS_DISABLE_ARCHIVE ? false : true;
28: $slug = defined( 'EPL_BUSINESS_SLUG' ) ? EPL_BUSINESS_SLUG : 'business';
29: $rewrite = defined( 'EPL_BUSINESS_DISABLE_REWRITE' ) && EPL_BUSINESS_DISABLE_REWRITE ? false : array(
30: 'slug' => $slug,
31: 'with_front' => false,
32: );
33: $rest = defined( 'EPL_BUSINESS_DISABLE_REST' ) && EPL_BUSINESS_DISABLE_REST ? false : true;
34:
35: $labels = apply_filters(
36: 'epl_business_labels',
37: array(
38: 'name' => __( 'Business Listings', 'easy-property-listings' ),
39: 'singular_name' => __( 'Business Listings', 'easy-property-listings' ),
40: 'menu_name' => __( 'Business', 'easy-property-listings' ),
41: 'add_new' => __( 'Add New', 'easy-property-listings' ),
42: 'add_new_item' => __( 'Add New Business Listing', 'easy-property-listings' ),
43: 'edit_item' => __( 'Edit Business Listing', 'easy-property-listings' ),
44: 'new_item' => __( 'New Business Listing', 'easy-property-listings' ),
45: 'update_item' => __( 'Update Business Listing', 'easy-property-listings' ),
46: 'all_items' => __( 'All Business Listings', 'easy-property-listings' ),
47: 'view_item' => __( 'View Business Listing', 'easy-property-listings' ),
48: 'view_items' => __( 'View Business Listings', 'easy-property-listings' ),
49: 'search_items' => __( 'Search Business Listing', 'easy-property-listings' ),
50: 'not_found' => __( 'Business Listing Not Found', 'easy-property-listings' ),
51: 'not_found_in_trash' => __( 'Business Listing Not Found in Trash', 'easy-property-listings' ),
52: 'parent_item_colon' => __( 'Parent Business Listing:', 'easy-property-listings' ),
53: )
54: );
55:
56: $business_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-cart',
65: 'capability_type' => 'post',
66: 'has_archive' => $archives,
67: 'hierarchical' => false,
68: 'menu_position' => '26.6',
69: 'show_in_rest' => $rest,
70: 'taxonomies' => array( 'location', 'tax_feature' ),
71: 'supports' => apply_filters( 'epl_business_supports', array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments' ) ),
72: );
73: epl_register_post_type( 'business', 'Business', apply_filters( 'epl_business_post_type_args', $business_args ) );
74: }
75: add_action( 'init', 'epl_register_custom_post_type_business', 0 );
76:
77:
78: /**
79: * Manage Admin Business Post Type Columns.
80: *
81: * @since 1.0
82: * @return void
83: */
84: if ( is_admin() ) {
85: /**
86: * Manage Admin Business Post Type Columns: Heading.
87: *
88: * @param array $columns Column array.
89: *
90: * @return mixed|void $columns with epl_post_type_business_admin_columns filter.
91: * @since 1.0
92: */
93: function epl_manage_business_columns_heading( $columns ) {
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_business_admin_columns', $columns );
124: }
125: add_filter( 'manage_edit-business_columns', 'epl_manage_business_columns_heading' );
126:
127: /**
128: * Manage Admin Business 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_business_columns_value( $column, $post_id ) {
135: global $post, $property;
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_business_posts_custom_column', 'epl_manage_business_columns_value', 10, 2 );
192:
193: /**
194: * Manage Business Columns Sorting
195: *
196: * @param array $columns Column array.
197: *
198: * @return array
199: * @since 1.0
200: */
201: function epl_manage_business_sortable_columns( $columns ) {
202: $columns['property_status'] = 'property_status';
203: return $columns;
204: }
205: add_filter( 'manage_edit-business_sortable_columns', 'epl_manage_business_sortable_columns' );
206: }
207: