PluginProbe
Property Hive / 1.4.6
Property Hive v1.4.6
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-contact.php

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

565 lines 16.7 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 contact 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_Contact' ) ) :
20
21 /**
22 * PH_Admin_CPT_Contact Class
23 */
24 class PH_Admin_CPT_Contact extends PH_Admin_CPT {
25
26 /**
27 * Constructor
28 */
29 public function __construct() {
30 $this->type = 'contact';
31
32 // Post title fields
33 add_filter( 'enter_title_here', array( $this, 'enter_title_here' ), 1, 2 );
34
35 // Featured image text
36 //add_filter( 'gettext', array( $this, 'featured_image_gettext' ) );
37 //add_filter( 'media_view_strings', array( $this, 'media_view_strings' ), 10, 2 );
38
39 // Visibility option
40 //add_action( 'post_submitbox_misc_actions', array( $this, 'property_data_visibility' ) );
41
42 // Before data updates
43 add_action( 'pre_post_update', array( $this, 'pre_post_update' ) );
44 add_filter( 'wp_insert_post_data', array( $this, 'wp_insert_post_data' ) );
45
46 // Admin Columns
47 add_filter( 'manage_edit-contact_columns', array( $this, 'edit_columns' ) );
48 add_action( 'manage_contact_posts_custom_column', array( $this, 'custom_columns' ), 2 );
49 /*add_filter( 'manage_edit-property_sortable_columns', array( $this, 'custom_columns_sort' ) );
50 add_filter( 'request', array( $this, 'custom_columns_orderby' ) );
51
52 // Sort link
53 add_filter( 'views_edit-property', array( $this, 'default_sorting_link' ) );
54
55 // Prouct filtering
56 add_action( 'restrict_manage_posts', array( $this, 'product_filters' ) );
57 add_filter( 'parse_query', array( $this, 'property_filters_query' ) );
58
59 // Enhanced search
60 add_filter( 'posts_search', array( $this, 'product_search' ) );
61
62 // Maintain hierarchy of terms
63 add_filter( 'wp_terms_checklist_args', array( $this, 'disable_checked_ontop' ) );*/
64
65 // Bulk / quick edit
66 add_filter( 'bulk_actions-edit-contact', array( $this, 'remove_bulk_actions') );
67 /*add_action( 'bulk_edit_custom_box', array( $this, 'bulk_edit' ), 10, 2 );
68 add_action( 'quick_edit_custom_box', array( $this, 'quick_edit' ), 10, 2 );
69 add_action( 'save_post', array( $this, 'bulk_and_quick_edit_save_post' ), 10, 2 );
70
71 // Uploads
72 add_filter( 'upload_dir', array( $this, 'upload_dir' ) );
73 add_action( 'media_upload_downloadable_product', array( $this, 'media_upload_downloadable_product' ) );
74 add_filter( 'mod_rewrite_rules', array( $this, 'ms_protect_download_rewite_rules' ) );
75
76 // Download permissions
77 //add_action( 'propertyhive_process_product_file_download_paths', array( $this, 'process_product_file_download_paths' ), 10, 3 );*/
78
79 add_action( 'admin_notices', array( $this, 'ph_message_admin_notice') );
80
81 // Call PH_Admin_CPT constructor
82 parent::__construct();
83 }
84
85 public function ph_message_admin_notice()
86 {
87 $message = '';
88
89 if ( isset($_GET['ph_message']) )
90 {
91 switch ( $_GET['ph_message'] )
92 {
93 case "1": {
94 $message = __( 'All done! The selected properties will be emailed to the applicant shortly.', 'propertyhive' );
95 break;
96 }
97 case "2": {
98 $message = __( 'Selected properties successfully removed from applicant matches', 'propertyhive' );
99 break;
100 }
101 }
102 }
103
104 if ( $message != '' )
105 {
106 echo "<div class=\"notice notice-success\">
107 <p>" . $message . "</p>
108 </div>";
109 }
110 }
111
112 /**
113 * Check if we're editing or adding a contact
114 * @return boolean
115 */
116 private function is_editing_contact() {
117 if ( ! empty( $_GET['post_type'] ) && 'contact' == $_GET['post_type'] ) {
118 return true;
119 }
120 if ( ! empty( $_GET['post'] ) && 'contact' == get_post_type( $_GET['post'] ) ) {
121 return true;
122 }
123 if ( ! empty( $_REQUEST['post_id'] ) && 'contact' == get_post_type( $_REQUEST['post_id'] ) ) {
124 return true;
125 }
126 return false;
127 }
128
129 /**
130 * Change title boxes in admin.
131 * @param string $text
132 * @param object $post
133 * @return string
134 */
135 public function enter_title_here( $text, $post ) {
136 if ( is_admin() && $post->post_type == 'contact' ) {
137 return __( 'Enter Contact Name(s)', 'propertyhive' );
138 }
139
140 return $text;
141 }
142
143 /**
144 * Some functions, like the term recount, require the visibility to be set prior. Lets save that here.
145 *
146 * @param int $post_id
147 */
148 public function pre_post_update( $post_id ) {
149
150 }
151
152 /**
153 * Forces certain product data based on the product's type, e.g. grouped products cannot have a parent.
154 *
155 * @param array $data
156 * @return array
157 */
158 public function wp_insert_post_data( $data ) {
159
160
161 return $data;
162 }
163
164 /**
165 * Change the columns shown in admin.
166 */
167 public function edit_columns( $existing_columns ) {
168
169 if ( empty( $existing_columns ) && ! is_array( $existing_columns ) ) {
170 $existing_columns = array();
171 }
172
173 unset( $existing_columns['title'], $existing_columns['comments'], $existing_columns['date'] );
174
175 $columns = array();
176 $columns['cb'] = '<input type="checkbox" />';
177 $columns['name'] = __( 'Name', 'propertyhive' );
178 $columns['address'] = __( 'Address', 'propertyhive' );
179 $columns['contact_details'] = __( 'Contact Details', 'propertyhive' );
180
181 return array_merge( $columns, $existing_columns );
182 }
183
184 /**
185 * Define our custom columns shown in admin.
186 * @param string $column
187 */
188 public function custom_columns( $column ) {
189 global $post, $propertyhive, $the_contact;
190
191 if ( empty( $the_contact ) || $the_contact->ID != $post->ID )
192 {
193 $the_contact = new PH_Contact( $post->ID );
194 }
195
196 switch ( $column ) {
197 case 'name' :
198
199 $edit_link = get_edit_post_link( $post->ID );
200 //$title = _draft_or_post_title();
201 $title = $the_contact->post_title;
202
203 $post_type_object = get_post_type_object( $post->post_type );
204 $can_edit_post = current_user_can( $post_type_object->cap->edit_post, $post->ID );
205
206 echo '<strong><a class="row-title" href="' . esc_url( $edit_link ) .'">' . $title.'</a></strong>';
207
208 /*if ( $post->post_parent > 0 ) {
209 echo '&nbsp;&nbsp;&larr; <a href="'. get_edit_post_link( $post->post_parent ) .'">'. get_the_title( $post->post_parent ) .'</a>';
210 }
211
212 // Excerpt view
213 if ( isset( $_GET['mode'] ) && 'excerpt' == $_GET['mode'] ) {
214 echo apply_filters( 'the_excerpt', $post->post_excerpt );
215 }*/
216
217 // Get actions
218 $actions = array();
219
220 if ( $can_edit_post && 'trash' != $post->post_status ) {
221 $actions['edit'] = '<a href="' . get_edit_post_link( $post->ID, true ) . '" title="' . esc_attr( __( 'Edit this item', 'propertyhive' ) ) . '">' . __( 'Edit', 'propertyhive' ) . '</a>';
222 }
223 if ( current_user_can( $post_type_object->cap->delete_post, $post->ID ) ) {
224 if ( 'trash' == $post->post_status ) {
225 $actions['untrash'] = '<a title="' . esc_attr( __( 'Restore this item from the Trash', 'propertyhive' ) ) . '" href="' . wp_nonce_url( admin_url( sprintf( $post_type_object->_edit_link . '&amp;action=untrash', $post->ID ) ), 'untrash-post_' . $post->ID ) . '">' . __( 'Restore', 'propertyhive' ) . '</a>';
226 } elseif ( EMPTY_TRASH_DAYS ) {
227 //$actions['trash'] = '<a class="submitdelete" title="' . esc_attr( __( 'Move this item to the Trash', 'propertyhive' ) ) . '" href="' . get_delete_post_link( $post->ID ) . '">' . __( 'Trash', 'propertyhive' ) . '</a>';
228 }
229
230 if ( 'trash' == $post->post_status || ! EMPTY_TRASH_DAYS ) {
231 $actions['delete'] = '<a class="submitdelete" title="' . esc_attr( __( 'Delete this item permanently', 'propertyhive' ) ) . '" href="' . get_delete_post_link( $post->ID, '', true ) . '">' . __( 'Delete Permanently', 'propertyhive' ) . '</a>';
232 }
233 }
234 if ( $post_type_object->public ) {
235 if ( in_array( $post->post_status, array( 'pending', 'draft', 'future' ) ) ) {
236 if ( $can_edit_post )
237 $actions['view'] = '<a href="' . esc_url( add_query_arg( 'preview', 'true', get_permalink( $post->ID ) ) ) . '" title="' . esc_attr( sprintf( __( 'Preview &#8220;%s&#8221;', 'propertyhive' ), $title ) ) . '" rel="permalink">' . __( 'Preview', 'propertyhive' ) . '</a>';
238 } elseif ( 'trash' != $post->post_status ) {
239 $actions['view'] = '<a href="' . get_permalink( $post->ID ) . '" title="' . esc_attr( sprintf( __( 'View &#8220;%s&#8221;', 'propertyhive' ), $title ) ) . '" rel="permalink">' . __( 'View', 'propertyhive' ) . '</a>';
240 }
241 }
242
243 $actions = apply_filters( 'post_row_actions', $actions, $post );
244
245 echo '<div class="row-actions">';
246
247 $i = 0;
248 $action_count = sizeof($actions);
249
250 foreach ( $actions as $action => $link ) {
251 ++$i;
252 ( $i == $action_count ) ? $sep = '' : $sep = ' | ';
253 echo '<span class="' . $action . '">' . $link . $sep . '</span>';
254 }
255 echo '</div>';
256
257 /*get_inline_data( $post );*/
258
259 /* Custom inline data for propertyhive */
260 /*echo '
261 <div class="hidden" id="propertyhive_inline_' . $post->ID . '">
262 <div class="menu_order">' . $post->menu_order . '</div>
263 </div>
264 ';*/
265
266 break;
267 case 'address' :
268
269 echo $the_contact->_address_name_number . ' ';
270 echo $the_contact->_address_street . ', ';
271 echo $the_contact->_address_two . ', ';
272 echo $the_contact->_address_three . ', ';
273 echo $the_contact->_address_four . ', ';
274 echo $the_contact->_address_postcode;
275
276 break;
277 case 'contact_details' :
278
279 echo 'T: ' . $the_contact->_telephone_number . '<br>';
280 echo 'E: ' . $the_contact->_email_address;
281
282 break;
283 default :
284 break;
285 }
286 }
287
288 /**
289 * Remove bulk edit option
290 * @param array $actions
291 */
292 public function remove_bulk_actions( $actions ) {
293 unset( $actions['edit'] );
294 return $actions;
295 }
296
297 /**
298 * Make contact columns sortable
299 *
300 * https://gist.github.com/906872
301 *
302 * @access public
303 * @param mixed $columns
304 * @return array
305 */
306 public function custom_columns_sort( $columns ) {
307 $custom = array(
308 'name' => 'title'
309 );
310 return wp_parse_args( $custom, $columns );
311 }
312
313 /**
314 * Product column orderby
315 *
316 * http://scribu.net/wordpress/custom-sortable-columns.html#comment-4732
317 *
318 * @access public
319 * @param mixed $vars
320 * @return array
321 */
322 public function custom_columns_orderby( $vars ) {
323 /*if ( isset( $vars['orderby'] ) ) {
324 if ( 'price' == $vars['orderby'] ) {
325 $vars = array_merge( $vars, array(
326 'meta_key' => 'price',
327 'orderby' => 'meta_value_num'
328 ) );
329 }
330 }*/
331
332 return $vars;
333 }
334
335 /**
336 * Product sorting link
337 *
338 * Based on Simple Page Ordering by 10up (http://wordpress.org/extend/plugins/simple-page-ordering/)
339 *
340 * @param array $views
341 * @return array
342 */
343 public function default_sorting_link( $views ) {
344 global $post_type, $wp_query;
345
346 if ( ! current_user_can('edit_others_pages') ) {
347 return $views;
348 }
349
350 $class = ( isset( $wp_query->query['orderby'] ) && $wp_query->query['orderby'] == 'menu_order title' ) ? 'current' : '';
351 $query_string = remove_query_arg(array( 'orderby', 'order' ));
352 $query_string = add_query_arg( 'orderby', urlencode('menu_order title'), $query_string );
353 $query_string = add_query_arg( 'order', urlencode('ASC'), $query_string );
354 $views['byorder'] = '<a href="'. $query_string . '" class="' . esc_attr( $class ) . '">' . __( 'Sort Contacts', 'propertyhive' ) . '</a>';
355
356 return $views;
357 }
358
359 /**
360 * Show a category filter box
361 */
362 public function propertyhive_filters() {
363 global $typenow, $wp_query;
364
365 if ( 'contact' != $typenow ) {
366 return;
367 }
368
369
370 echo apply_filters( 'propertyhive_contact_filters', $output );
371 }
372
373 /**
374 * Filter the contacts in admin based on options
375 *
376 * @param mixed $query
377 */
378 public function contact_filters_query( $query ) {
379 global $typenow, $wp_query;
380
381 if ( 'contact' == $typenow ) {
382
383 /*if ( isset( $query->query_vars['product_type'] ) ) {
384 // Subtypes
385 if ( 'downloadable' == $query->query_vars['product_type'] ) {
386 $query->query_vars['product_type'] = '';
387 $query->query_vars['meta_value'] = 'yes';
388 $query->query_vars['meta_key'] = '_downloadable';
389 } elseif ( 'virtual' == $query->query_vars['product_type'] ) {
390 $query->query_vars['product_type'] = '';
391 $query->query_vars['meta_value'] = 'yes';
392 $query->query_vars['meta_key'] = '_virtual';
393 }
394 }
395
396 // Categories
397 if ( isset( $_GET['product_cat'] ) && '0' == $_GET['product_cat'] ) {
398 $query->query_vars['tax_query'][] = array(
399 'taxonomy' => 'product_cat',
400 'field' => 'id',
401 'terms' => get_terms( 'product_cat', array( 'fields' => 'ids' ) ),
402 'operator' => 'NOT IN'
403 );
404 }*/
405 }
406 }
407
408 /**
409 * Maintain term hierarchy when editing a property.
410 * @param array $args
411 * @return array
412 */
413 public function disable_checked_ontop( $args ) {
414 if ( 'product_cat' == $args['taxonomy'] ) {
415 $args['checked_ontop'] = false;
416 }
417
418 return $args;
419 }
420
421 /**
422 * Custom bulk edit - form
423 *
424 * @access public
425 * @param mixed $column_name
426 * @param mixed $post_type
427 */
428 public function bulk_edit( $column_name, $post_type ) {
429 if ( 'price' != $column_name || 'property' != $post_type ) {
430 return;
431 }
432
433 include( HP()->plugin_path() . '/includes/admin/views/html-bulk-edit-product.php' );
434 }
435
436 /**
437 * Custom quick edit - form
438 *
439 * @access public
440 * @param mixed $column_name
441 * @param mixed $post_type
442 */
443 public function quick_edit( $column_name, $post_type ) {
444 if ( 'price' != $column_name || 'property' != $post_type ) {
445 return;
446 }
447
448 include( HP()->plugin_path() . '/includes/admin/views/html-quick-edit-contact.php' );
449 }
450
451 /**
452 * Quick and bulk edit saving
453 *
454 * @access public
455 * @param int $post_id
456 * @param WP_Post $post
457 * @return int
458 */
459 public function bulk_and_quick_edit_save_post( $post_id, $post ) {
460 // If this is an autosave, our form has not been submitted, so we don't want to do anything.
461 if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
462 return $post_id;
463 }
464
465 // Don't save revisions and autosaves
466 if ( wp_is_post_revision( $post_id ) || wp_is_post_autosave( $post_id ) ) {
467 return $post_id;
468 }
469
470 // Check post type is product
471 if ( 'contact' != $post->post_type ) {
472 return $post_id;
473 }
474
475 // Check user permission
476 if ( ! current_user_can( 'edit_post', $post_id ) ) {
477 return $post_id;
478 }
479
480 // Check nonces
481 if ( ! isset( $_REQUEST['propertyhive_quick_edit_nonce'] ) && ! isset( $_REQUEST['propertyhive_bulk_edit_nonce'] ) ) {
482 return $post_id;
483 }
484 if ( isset( $_REQUEST['propertyhive_quick_edit_nonce'] ) && ! wp_verify_nonce( $_REQUEST['propertyhive_quick_edit_nonce'], 'propertyhive_quick_edit_nonce' ) ) {
485 return $post_id;
486 }
487 if ( isset( $_REQUEST['propertyhive_bulk_edit_nonce'] ) && ! wp_verify_nonce( $_REQUEST['propertyhive_bulk_edit_nonce'], 'propertyhive_bulk_edit_nonce' ) ) {
488 return $post_id;
489 }
490
491 // Get the product and save
492 $contact = get_contact( $post );
493
494 if ( ! empty( $_REQUEST['propertyhive_quick_edit'] ) ) {
495 $this->quick_edit_save( $post_id, $contact );
496 } else {
497 $this->bulk_edit_save( $post_id, $contact );
498 }
499
500 // Clear transient
501 //ph_delete_contact_transients( $post_id );
502
503 return $post_id;
504 }
505
506 /**
507 * Quick edit
508 */
509 private function quick_edit_save( $post_id, $contact ) {
510
511 global $wpdb;
512
513 /*
514 // Save fields
515 if ( isset( $_REQUEST['_availability'] ) ) {
516 update_post_meta( $post_id, '_availability', ph__clean( $_REQUEST['_availability'] ) );
517 }*/
518
519 do_action( 'propertyhive_product_quick_edit_save', $contact );
520 }
521
522 /**
523 * Bulk edit
524 */
525 public function bulk_edit_save( $post_id, $contact ) {
526
527 /*
528 // Save fields
529 if ( ! empty( $_REQUEST['_availability'] ) ) {
530 update_post_meta( $post_id, '_availability', ph__clean( $_REQUEST['_availability'] ) );
531 }*/
532
533 do_action( 'propertyhive_contact_bulk_edit_save', $contact );
534 }
535
536 /**
537 * Filter the directory for uploads.
538 *
539 * @param array $pathdata
540 * @return array
541 */
542 public function upload_dir( $pathdata ) {
543 // Change upload dir for downloadable files
544 if ( isset( $_POST['type'] ) && 'downloadable_product' == $_POST['type'] ) {
545 if ( empty( $pathdata['subdir'] ) ) {
546 $pathdata['path'] = $pathdata['path'] . '/propertyhive_uploads';
547 $pathdata['url'] = $pathdata['url']. '/propertyhive_uploads';
548 $pathdata['subdir'] = '/propertyhive_uploads';
549 } else {
550 $new_subdir = '/propertyhive_uploads' . $pathdata['subdir'];
551
552 $pathdata['path'] = str_replace( $pathdata['subdir'], $new_subdir, $pathdata['path'] );
553 $pathdata['url'] = str_replace( $pathdata['subdir'], $new_subdir, $pathdata['url'] );
554 $pathdata['subdir'] = str_replace( $pathdata['subdir'], $new_subdir, $pathdata['subdir'] );
555 }
556 }
557
558 return $pathdata;
559 }
560 }
561
562 endif;
563
564 return new PH_Admin_CPT_Contact();
565