PluginProbe
Property Hive / 2.3.1
Property Hive v2.3.1
2.3.1 2.3.0 2.2.6 2.2.5 2.2.4 2.2.3 2.2.2 1.4.46 1.4.47 1.4.48 1.4.49 1.4.5 1.4.50 1.4.51 1.4.52 1.4.53 1.4.54 1.4.55 1.4.56 1.4.57 1.4.58 1.4.59 1.4.6 1.4.60 1.4.61 All 261 releases
propertyhive / includes / admin / post-types / class-ph-admin-cpt-offer.php

class-ph-admin-cpt-offer.php in Property Hive 2.3.1, at includes/admin/post-types/class-ph-admin-cpt-offer.php

286 lines 9.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Admin functions for the offer post type
4 *
5 * @author PropertyHive
6 * @category Admin
7 * @package PropertyHive/Admin/Post Types
8 * @version 1.0.0
9 */
10
11 if ( ! defined( 'ABSPATH' ) ) {
12 exit; // Exit if accessed directly
13 }
14
15 if ( ! class_exists( 'PH_Admin_CPT' ) ) {
16 include( 'class-ph-admin-cpt.php' );
17 }
18
19 if ( ! class_exists( 'PH_Admin_CPT_Offer' ) ) :
20
21 /**
22 * PH_Admin_CPT_Offer Class
23 */
24 // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedClassFound -- Legacy public global class PH_Admin_CPT_Offer; preserving the existing PH_* class name is required for plugin and extension compatibility.
25 class PH_Admin_CPT_Offer extends PH_Admin_CPT {
26
27 /**
28 * Constructor
29 */
30 public function __construct() {
31 $this->type = 'offer';
32
33 // Before data updates
34 add_action( 'pre_post_update', array( $this, 'pre_post_update' ) );
35 add_filter( 'wp_insert_post_data', array( $this, 'wp_insert_post_data' ) );
36
37 // Admin Columns
38 add_filter( 'manage_edit-offer_columns', array( $this, 'edit_columns' ) );
39 add_action( 'manage_offer_posts_custom_column', array( $this, 'custom_columns' ), 2 );
40 add_filter( 'list_table_primary_column', array( $this, 'set_primary_column' ), 10, 2 );
41 add_filter( 'post_row_actions', array( $this, 'remove_actions' ), 10, 2 );
42 add_filter( 'manage_edit-offer_sortable_columns', array( $this, 'custom_columns_sort' ) );
43 add_filter( 'request', array( $this, 'custom_columns_orderby' ) );
44
45 // Bulk / quick edit
46 add_filter( 'bulk_actions-edit-offer', array( $this, 'remove_bulk_actions') );
47 /*add_action( 'bulk_edit_custom_box', array( $this, 'bulk_edit' ), 10, 2 );
48 add_action( 'quick_edit_custom_box', array( $this, 'quick_edit' ), 10, 2 );
49 add_action( 'save_post', array( $this, 'bulk_and_quick_edit_save_post' ), 10, 2 );*/
50
51 // Call PH_Admin_CPT constructor
52 parent::__construct();
53 }
54
55 /**
56 * Check if we're editing or adding a offer
57 * @return boolean
58 */
59 private function is_editing_offer() {
60 // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Read-only screen detection; mutations have separate save guards.
61 $post_type = isset( $_GET['post_type'] ) && is_string( $_GET['post_type'] ) ? sanitize_key( wp_unslash( $_GET['post_type'] ) ) : '';
62 // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Read-only screen detection.
63 $post_id = isset( $_GET['post'] ) && is_string( $_GET['post'] ) ? absint( $_GET['post'] ) : 0;
64 // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Read-only screen detection for AJAX requests.
65 $request_id = isset( $_REQUEST['post_id'] ) && is_string( $_REQUEST['post_id'] ) ? absint( $_REQUEST['post_id'] ) : 0;
66 return 'offer' === $post_type || ( $post_id > 0 && 'offer' === get_post_type( $post_id ) ) || ( $request_id > 0 && 'offer' === get_post_type( $request_id ) );
67 }
68
69 /**
70 * @param int $post_id
71 */
72 public function pre_post_update( $post_id ) {
73
74 }
75
76 /**
77 * @param array $data
78 * @return array
79 */
80 public function wp_insert_post_data( $data ) {
81
82
83 return $data;
84 }
85
86 /**
87 * Change the columns shown in admin.
88 */
89 public function edit_columns( $existing_columns ) {
90
91 if ( empty( $existing_columns ) && ! is_array( $existing_columns ) ) {
92 $existing_columns = array();
93 }
94
95 unset( $existing_columns['title'], $existing_columns['comments'], $existing_columns['date'] );
96
97 $columns = array();
98 $columns['cb'] = '<input type="checkbox" />';
99 $columns['offer_date_time'] = __( 'Offer Date / Time', 'propertyhive' );
100 $columns['property'] = __( 'Property', 'propertyhive' );
101 $columns['property_owner'] = __( 'Property Owner', 'propertyhive' );
102 $columns['applicant'] = __( 'Applicant(s)', 'propertyhive' );
103 $columns['amount'] = __( 'Amount', 'propertyhive' );
104 $columns['status'] = __( 'Status', 'propertyhive' );
105
106 return array_merge( $columns, $existing_columns );
107 }
108
109 /**
110 * Define our custom columns shown in admin.
111 * @param string $column
112 */
113 public function custom_columns( $column ) {
114 global $post, $propertyhive, $the_offer;
115
116 if ( empty( $the_offer ) || $the_offer->ID != $post->ID )
117 {
118 // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Retain the legacy global name for compatibility with external admin column callbacks.
119 $the_offer = new PH_Offer( $post->ID );
120 }
121
122 switch ( $column ) {
123 case 'offer_date_time' :
124
125 $edit_link = get_edit_post_link( $post->ID );
126 //$title = _draft_or_post_title();
127 $title = gmdate("H:i jS F Y", strtotime($the_offer->offer_date_time));
128
129 $post_type_object = get_post_type_object( $post->post_type );
130 $can_edit_post = current_user_can( $post_type_object->cap->edit_post, $post->ID );
131
132 echo '<strong><a class="row-title" href="' . esc_url( $edit_link ) .'">' . esc_html($title) . '</a></strong>';
133 break;
134 case 'property' :
135
136 if ( $the_offer->property_id != '' )
137 {
138 $property = new PH_Property((int)$the_offer->property_id);
139 echo esc_html($property->get_formatted_full_address());
140 }
141 else
142 {
143 echo '-';
144 }
145
146 break;
147 case 'property_owner' :
148
149 $the_property = new PH_Property((int)$the_offer->property_id);
150 $owner_contact_ids = $the_property->_owner_contact_id;
151 if (
152 ( !is_array($owner_contact_ids) && $owner_contact_ids != '' && $owner_contact_ids != 0 )
153 ||
154 ( is_array($owner_contact_ids) && !empty($owner_contact_ids) )
155 )
156 {
157 if ( !is_array($owner_contact_ids) )
158 {
159 $owner_contact_ids = array($owner_contact_ids);
160 }
161
162 foreach ( $owner_contact_ids as $owner_contact_id )
163 {
164 echo esc_html(get_the_title($owner_contact_id)) . '<br>';
165 if ( count($owner_contact_ids) == 1 )
166 {
167 echo '<div class="row-actions">';
168 echo 'T: ' . esc_html(get_post_meta($owner_contact_id, '_telephone_number', TRUE)) . '<br>';
169 echo 'E: ' . esc_html(get_post_meta($owner_contact_id, '_email_address', TRUE));
170 echo '</div>';
171 }
172 }
173 }
174 else
175 {
176 echo '-';
177 }
178
179 break;
180 case 'applicant' :
181
182 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- get_applicants escapes stored names/contact details and URLs before its trusted PHP contact-details HTML filter.
183 echo $the_offer->get_applicants( false, true, false );
184
185 break;
186 case 'amount' :
187
188 echo wp_kses_post( $the_offer->get_formatted_amount() );
189
190 break;
191 case 'status' :
192 echo esc_html(propertyhive_get_status_label( $the_offer->status ));
193 break;
194 default :
195 break;
196 }
197 }
198
199 public function set_primary_column( $default, $screen ) {
200
201 if ( 'edit-offer' === $screen )
202 {
203 $default = 'offer_date_time';
204 }
205
206 return $default;
207 }
208
209 public function remove_actions($actions, $post) {
210
211 if ( $post->post_type !== 'offer' )
212 {
213 return $actions;
214 }
215
216 // Remove 'Quick Edit' link
217 if ( isset($actions['inline hide-if-no-js']) )
218 {
219 unset($actions['inline hide-if-no-js']);
220 }
221
222 if ( isset($actions['trash']) )
223 {
224 unset($actions['trash']);
225 }
226
227 return $actions;
228 }
229
230 /**
231 * Make offer columns sortable
232 *
233 * @access public
234 * @param mixed $columns
235 * @return array
236 */
237 public function custom_columns_sort( $columns ) {
238 $custom = array(
239 'offer_date_time' => '_offer_date_time',
240 'status' => '_status',
241 );
242 return wp_parse_args( $custom, $columns );
243 }
244
245 /**
246 * Offer column orderby
247 *
248 * @access public
249 * @param mixed $vars
250 * @return array
251 */
252 public function custom_columns_orderby( $vars ) {
253 if ( isset( $vars['orderby'] ) ) {
254 if ( '_offer_date_time' == $vars['orderby'] ) {
255 $vars = array_merge( $vars, array(
256 // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_key -- All these meta_key values are literal, supported CPT date/status/price keys used by paginated WordPress admin list ordering. Core admin post queries provide pagination; no arbitrary request key is copied into these lines.
257 'meta_key' => '_offer_date_time',
258 'orderby' => 'meta_value'
259 ) );
260 }
261 elseif ( '_status' == $vars['orderby'] ) {
262 $vars = array_merge( $vars, array(
263 // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_key -- All these meta_key values are literal, supported CPT date/status/price keys used by paginated WordPress admin list ordering. Core admin post queries provide pagination; no arbitrary request key is copied into these lines.
264 'meta_key' => '_status',
265 'orderby' => 'meta_value'
266 ) );
267 }
268 }
269
270 return $vars;
271 }
272
273 /**
274 * Remove bulk edit option
275 * @param array $actions
276 */
277 public function remove_bulk_actions( $actions ) {
278 unset( $actions['edit'] );
279 return $actions;
280 }
281 }
282
283 endif;
284
285 return new PH_Admin_CPT_Offer();
286