| 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, 'contact_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 |
add_action( 'manage_posts_extra_tablenav', array( $this, 'generate_applicant_list_action') ); |
| 82 |
|
| 83 |
// Call PH_Admin_CPT constructor |
| 84 |
parent::__construct(); |
| 85 |
} |
| 86 |
|
| 87 |
public function ph_message_admin_notice() |
| 88 |
{ |
| 89 |
$message = ''; |
| 90 |
|
| 91 |
if ( isset($_GET['ph_message']) ) |
| 92 |
{ |
| 93 |
switch ( $_GET['ph_message'] ) |
| 94 |
{ |
| 95 |
case "1": { |
| 96 |
$message = __( 'All done! The selected properties will be emailed to the applicant shortly.', 'propertyhive' ); |
| 97 |
break; |
| 98 |
} |
| 99 |
case "2": { |
| 100 |
$message = __( 'Selected properties successfully removed from applicant matches', 'propertyhive' ); |
| 101 |
break; |
| 102 |
} |
| 103 |
} |
| 104 |
} |
| 105 |
|
| 106 |
if ( $message != '' ) |
| 107 |
{ |
| 108 |
echo "<div class=\"notice notice-success\"> |
| 109 |
<p>" . $message . "</p> |
| 110 |
</div>"; |
| 111 |
} |
| 112 |
} |
| 113 |
|
| 114 |
/** |
| 115 |
* Check if we're editing or adding a contact |
| 116 |
* @return boolean |
| 117 |
*/ |
| 118 |
private function is_editing_contact() { |
| 119 |
if ( ! empty( $_GET['post_type'] ) && 'contact' == $_GET['post_type'] ) { |
| 120 |
return true; |
| 121 |
} |
| 122 |
if ( ! empty( $_GET['post'] ) && 'contact' == get_post_type( (int)$_GET['post'] ) ) { |
| 123 |
return true; |
| 124 |
} |
| 125 |
if ( ! empty( $_REQUEST['post_id'] ) && 'contact' == get_post_type( (int)$_REQUEST['post_id'] ) ) { |
| 126 |
return true; |
| 127 |
} |
| 128 |
return false; |
| 129 |
} |
| 130 |
|
| 131 |
/** |
| 132 |
* Change title boxes in admin. |
| 133 |
* @param string $text |
| 134 |
* @param object $post |
| 135 |
* @return string |
| 136 |
*/ |
| 137 |
public function enter_title_here( $text, $post ) { |
| 138 |
if ( is_admin() && $post->post_type == 'contact' ) { |
| 139 |
return __( 'Enter Contact Name(s)', 'propertyhive' ); |
| 140 |
} |
| 141 |
|
| 142 |
return $text; |
| 143 |
} |
| 144 |
|
| 145 |
/** |
| 146 |
* Some functions, like the term recount, require the visibility to be set prior. Lets save that here. |
| 147 |
* |
| 148 |
* @param int $post_id |
| 149 |
*/ |
| 150 |
public function pre_post_update( $post_id ) { |
| 151 |
|
| 152 |
} |
| 153 |
|
| 154 |
/** |
| 155 |
* Forces certain product data based on the product's type, e.g. grouped products cannot have a parent. |
| 156 |
* |
| 157 |
* @param array $data |
| 158 |
* @return array |
| 159 |
*/ |
| 160 |
public function wp_insert_post_data( $data ) { |
| 161 |
|
| 162 |
|
| 163 |
return $data; |
| 164 |
} |
| 165 |
|
| 166 |
/** |
| 167 |
* Change the columns shown in admin. |
| 168 |
*/ |
| 169 |
public function edit_columns( $existing_columns ) { |
| 170 |
|
| 171 |
if ( empty( $existing_columns ) && ! is_array( $existing_columns ) ) { |
| 172 |
$existing_columns = array(); |
| 173 |
} |
| 174 |
|
| 175 |
unset( $existing_columns['title'], $existing_columns['comments'], $existing_columns['date'] ); |
| 176 |
|
| 177 |
$columns = array(); |
| 178 |
$columns['cb'] = '<input type="checkbox" />'; |
| 179 |
$columns['name'] = __( 'Name', 'propertyhive' ); |
| 180 |
$columns['address'] = __( 'Address', 'propertyhive' ); |
| 181 |
$columns['contact_details'] = __( 'Contact Details', 'propertyhive' ); |
| 182 |
|
| 183 |
return array_merge( $columns, $existing_columns ); |
| 184 |
} |
| 185 |
|
| 186 |
/** |
| 187 |
* Define our custom columns shown in admin. |
| 188 |
* @param string $column |
| 189 |
*/ |
| 190 |
public function custom_columns( $column ) { |
| 191 |
global $post, $propertyhive, $the_contact; |
| 192 |
|
| 193 |
if ( empty( $the_contact ) || $the_contact->ID != $post->ID ) |
| 194 |
{ |
| 195 |
$the_contact = new PH_Contact( $post->ID ); |
| 196 |
} |
| 197 |
|
| 198 |
switch ( $column ) { |
| 199 |
case 'name' : |
| 200 |
|
| 201 |
$edit_link = get_edit_post_link( $post->ID ); |
| 202 |
//$title = _draft_or_post_title(); |
| 203 |
$title = $the_contact->post_title; |
| 204 |
|
| 205 |
$post_type_object = get_post_type_object( $post->post_type ); |
| 206 |
$can_edit_post = current_user_can( $post_type_object->cap->edit_post, $post->ID ); |
| 207 |
|
| 208 |
echo '<strong><a class="row-title" href="' . esc_url( $edit_link ) .'">' . $title.'</a>'; |
| 209 |
if ( isset( $_GET['_contact_type'] ) && strpos( ph_clean($_GET['_contact_type']), 'applicant' ) !== FALSE && in_array('applicant', $the_contact->_contact_types) && $the_contact->_hot_applicant == 'yes' ) |
| 210 |
{ |
| 211 |
echo ' <span style="color:#C00;">(' . __( 'Hot Applicant', 'propertyhive' ) . ')</span>'; |
| 212 |
} |
| 213 |
echo '</strong>'; |
| 214 |
|
| 215 |
/*if ( $post->post_parent > 0 ) { |
| 216 |
echo ' ← <a href="'. get_edit_post_link( $post->post_parent ) .'">'. get_the_title( $post->post_parent ) .'</a>'; |
| 217 |
} |
| 218 |
|
| 219 |
// Excerpt view |
| 220 |
if ( isset( $_GET['mode'] ) && 'excerpt' == $_GET['mode'] ) { |
| 221 |
echo apply_filters( 'the_excerpt', $post->post_excerpt ); |
| 222 |
}*/ |
| 223 |
|
| 224 |
// Get actions |
| 225 |
$actions = array(); |
| 226 |
|
| 227 |
if ( $can_edit_post && 'trash' != $post->post_status ) { |
| 228 |
$actions['edit'] = '<a href="' . get_edit_post_link( $post->ID, true ) . '" title="' . esc_attr( __( 'Edit this item', 'propertyhive' ) ) . '">' . __( 'Edit', 'propertyhive' ) . '</a>'; |
| 229 |
} |
| 230 |
if ( current_user_can( $post_type_object->cap->delete_post, $post->ID ) ) { |
| 231 |
if ( 'trash' == $post->post_status ) { |
| 232 |
$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 . '&action=untrash', $post->ID ) ), 'untrash-post_' . $post->ID ) . '">' . __( 'Restore', 'propertyhive' ) . '</a>'; |
| 233 |
} elseif ( EMPTY_TRASH_DAYS ) { |
| 234 |
//$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>'; |
| 235 |
} |
| 236 |
|
| 237 |
if ( 'trash' == $post->post_status || ! EMPTY_TRASH_DAYS ) { |
| 238 |
$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>'; |
| 239 |
} |
| 240 |
} |
| 241 |
if ( $post_type_object->public ) { |
| 242 |
if ( in_array( $post->post_status, array( 'pending', 'draft', 'future' ) ) ) { |
| 243 |
if ( $can_edit_post ) |
| 244 |
$actions['view'] = '<a href="' . esc_url( add_query_arg( 'preview', 'true', get_permalink( $post->ID ) ) ) . '" title="' . esc_attr( sprintf( __( 'Preview “%s”', 'propertyhive' ), $title ) ) . '" rel="permalink">' . __( 'Preview', 'propertyhive' ) . '</a>'; |
| 245 |
} elseif ( 'trash' != $post->post_status ) { |
| 246 |
$actions['view'] = '<a href="' . get_permalink( $post->ID ) . '" title="' . esc_attr( sprintf( __( 'View “%s”', 'propertyhive' ), $title ) ) . '" rel="permalink">' . __( 'View', 'propertyhive' ) . '</a>'; |
| 247 |
} |
| 248 |
} |
| 249 |
|
| 250 |
$actions = apply_filters( 'post_row_actions', $actions, $post ); |
| 251 |
|
| 252 |
echo '<div class="row-actions">'; |
| 253 |
|
| 254 |
$i = 0; |
| 255 |
$action_count = sizeof($actions); |
| 256 |
|
| 257 |
foreach ( $actions as $action => $link ) { |
| 258 |
++$i; |
| 259 |
( $i == $action_count ) ? $sep = '' : $sep = ' | '; |
| 260 |
echo '<span class="' . $action . '">' . $link . $sep . '</span>'; |
| 261 |
} |
| 262 |
echo '</div>'; |
| 263 |
|
| 264 |
/*get_inline_data( $post );*/ |
| 265 |
|
| 266 |
/* Custom inline data for propertyhive */ |
| 267 |
/*echo ' |
| 268 |
<div class="hidden" id="propertyhive_inline_' . $post->ID . '"> |
| 269 |
<div class="menu_order">' . $post->menu_order . '</div> |
| 270 |
</div> |
| 271 |
';*/ |
| 272 |
|
| 273 |
break; |
| 274 |
case 'address' : |
| 275 |
|
| 276 |
echo $the_contact->get_formatted_full_address(); |
| 277 |
|
| 278 |
break; |
| 279 |
case 'contact_details' : |
| 280 |
|
| 281 |
echo 'T: ' . $the_contact->_telephone_number . '<br>'; |
| 282 |
echo 'E: ' . $the_contact->_email_address; |
| 283 |
|
| 284 |
break; |
| 285 |
default : |
| 286 |
break; |
| 287 |
} |
| 288 |
} |
| 289 |
|
| 290 |
/** |
| 291 |
* Remove bulk edit option |
| 292 |
* @param array $actions |
| 293 |
*/ |
| 294 |
public function remove_bulk_actions( $actions ) { |
| 295 |
unset( $actions['edit'] ); |
| 296 |
return $actions; |
| 297 |
} |
| 298 |
|
| 299 |
/** |
| 300 |
* Search by email and phone number |
| 301 |
* Phone numbers are stripped of any none numeric or comma charactors |
| 302 |
* |
| 303 |
* @param string $where |
| 304 |
* @return string |
| 305 |
*/ |
| 306 |
public function contact_search( $where ) { |
| 307 |
|
| 308 |
global $pagenow, $wpdb, $wp; |
| 309 |
|
| 310 |
if ( 'edit.php' != $pagenow || ! is_search() || ! isset( $wp->query_vars['s'] ) || 'contact' != $wp->query_vars['post_type'] ) { |
| 311 |
return $where; |
| 312 |
} |
| 313 |
|
| 314 |
if ( trim($wp->query_vars['s']) == '' ) |
| 315 |
{ |
| 316 |
return $where; |
| 317 |
} |
| 318 |
|
| 319 |
$search_ids = array(); |
| 320 |
$terms = explode( ',', $wp->query_vars['s'] ); |
| 321 |
|
| 322 |
foreach ( $terms as $term ) |
| 323 |
{ |
| 324 |
if ( is_numeric( $term ) ) |
| 325 |
{ |
| 326 |
$search_ids[] = $term; |
| 327 |
} |
| 328 |
|
| 329 |
$phone_number = preg_replace( "/[^0-9,]/", "", $term ); |
| 330 |
|
| 331 |
// Attempt to get an ID by searching for phone and email address |
| 332 |
$query = $wpdb->prepare( |
| 333 |
"SELECT |
| 334 |
ID |
| 335 |
FROM |
| 336 |
{$wpdb->posts} |
| 337 |
INNER JOIN {$wpdb->postmeta} AS mt1 ON {$wpdb->posts}.ID = mt1.post_id |
| 338 |
WHERE |
| 339 |
( |
| 340 |
(mt1.meta_key='_telephone_number_clean' AND mt1.meta_value LIKE NULLIF(%s,'%%%')) |
| 341 |
OR |
| 342 |
(mt1.meta_key='_email_address' AND mt1.meta_value LIKE %s) |
| 343 |
) |
| 344 |
AND |
| 345 |
post_type='contact' |
| 346 |
GROUP BY ID |
| 347 |
", |
| 348 |
'%' . $wpdb->esc_like( ph_clean( ph_clean_telephone_number( $term ) ) ) . '%', |
| 349 |
'%' . $wpdb->esc_like( ph_clean( $term ) ) . '%' |
| 350 |
); |
| 351 |
|
| 352 |
$search_posts = $wpdb->get_results( $query ); |
| 353 |
$search_posts = wp_list_pluck( $search_posts, 'ID' ); |
| 354 |
|
| 355 |
if ( sizeof( $search_posts ) > 0 ) |
| 356 |
{ |
| 357 |
$search_ids = array_merge( $search_ids, $search_posts ); |
| 358 |
} |
| 359 |
} |
| 360 |
$search_ids = array_filter( array_unique( array_map( 'absint', $search_ids ) ) ); |
| 361 |
if ( sizeof( $search_ids ) > 0 ) |
| 362 |
{ |
| 363 |
$where = str_replace( 'AND (((', "AND ( ({$wpdb->posts}.ID IN (" . implode( ',', $search_ids ) . ")) OR ((", $where ); |
| 364 |
} |
| 365 |
return $where; |
| 366 |
} |
| 367 |
|
| 368 |
/** |
| 369 |
* Make contact columns sortable |
| 370 |
* |
| 371 |
* https://gist.github.com/906872 |
| 372 |
* |
| 373 |
* @access public |
| 374 |
* @param mixed $columns |
| 375 |
* @return array |
| 376 |
*/ |
| 377 |
public function custom_columns_sort( $columns ) { |
| 378 |
$custom = array( |
| 379 |
'name' => 'title' |
| 380 |
); |
| 381 |
return wp_parse_args( $custom, $columns ); |
| 382 |
} |
| 383 |
|
| 384 |
/** |
| 385 |
* Product column orderby |
| 386 |
* |
| 387 |
* http://scribu.net/wordpress/custom-sortable-columns.html#comment-4732 |
| 388 |
* |
| 389 |
* @access public |
| 390 |
* @param mixed $vars |
| 391 |
* @return array |
| 392 |
*/ |
| 393 |
public function custom_columns_orderby( $vars ) { |
| 394 |
/*if ( isset( $vars['orderby'] ) ) { |
| 395 |
if ( 'price' == $vars['orderby'] ) { |
| 396 |
$vars = array_merge( $vars, array( |
| 397 |
'meta_key' => 'price', |
| 398 |
'orderby' => 'meta_value_num' |
| 399 |
) ); |
| 400 |
} |
| 401 |
}*/ |
| 402 |
|
| 403 |
return $vars; |
| 404 |
} |
| 405 |
|
| 406 |
/** |
| 407 |
* Product sorting link |
| 408 |
* |
| 409 |
* Based on Simple Page Ordering by 10up (http://wordpress.org/extend/plugins/simple-page-ordering/) |
| 410 |
* |
| 411 |
* @param array $views |
| 412 |
* @return array |
| 413 |
*/ |
| 414 |
public function default_sorting_link( $views ) { |
| 415 |
global $post_type, $wp_query; |
| 416 |
|
| 417 |
if ( ! current_user_can('edit_others_pages') ) { |
| 418 |
return $views; |
| 419 |
} |
| 420 |
|
| 421 |
$class = ( isset( $wp_query->query['orderby'] ) && $wp_query->query['orderby'] == 'menu_order title' ) ? 'current' : ''; |
| 422 |
$query_string = remove_query_arg(array( 'orderby', 'order' )); |
| 423 |
$query_string = add_query_arg( 'orderby', urlencode('menu_order title'), $query_string ); |
| 424 |
$query_string = add_query_arg( 'order', urlencode('ASC'), $query_string ); |
| 425 |
$views['byorder'] = '<a href="'. $query_string . '" class="' . esc_attr( $class ) . '">' . __( 'Sort Contacts', 'propertyhive' ) . '</a>'; |
| 426 |
|
| 427 |
return $views; |
| 428 |
} |
| 429 |
|
| 430 |
/** |
| 431 |
* Show a category filter box |
| 432 |
*/ |
| 433 |
public function propertyhive_filters() { |
| 434 |
global $typenow, $wp_query; |
| 435 |
|
| 436 |
if ( 'contact' != $typenow ) { |
| 437 |
return; |
| 438 |
} |
| 439 |
|
| 440 |
|
| 441 |
echo apply_filters( 'propertyhive_contact_filters', $output ); |
| 442 |
} |
| 443 |
|
| 444 |
/** |
| 445 |
* Filter the contacts in admin based on options |
| 446 |
* |
| 447 |
* @param mixed $query |
| 448 |
*/ |
| 449 |
public function contact_filters_query( $query ) { |
| 450 |
global $typenow, $wp_query; |
| 451 |
|
| 452 |
if ( 'contact' == $typenow ) { |
| 453 |
|
| 454 |
} |
| 455 |
} |
| 456 |
|
| 457 |
/** |
| 458 |
* Maintain term hierarchy when editing a property. |
| 459 |
* @param array $args |
| 460 |
* @return array |
| 461 |
*/ |
| 462 |
public function disable_checked_ontop( $args ) { |
| 463 |
if ( 'product_cat' == $args['taxonomy'] ) { |
| 464 |
$args['checked_ontop'] = false; |
| 465 |
} |
| 466 |
|
| 467 |
return $args; |
| 468 |
} |
| 469 |
|
| 470 |
/** |
| 471 |
* Custom bulk edit - form |
| 472 |
* |
| 473 |
* @access public |
| 474 |
* @param mixed $column_name |
| 475 |
* @param mixed $post_type |
| 476 |
*/ |
| 477 |
public function bulk_edit( $column_name, $post_type ) { |
| 478 |
if ( 'price' != $column_name || 'property' != $post_type ) { |
| 479 |
return; |
| 480 |
} |
| 481 |
|
| 482 |
include( HP()->plugin_path() . '/includes/admin/views/html-bulk-edit-product.php' ); |
| 483 |
} |
| 484 |
|
| 485 |
/** |
| 486 |
* Custom quick edit - form |
| 487 |
* |
| 488 |
* @access public |
| 489 |
* @param mixed $column_name |
| 490 |
* @param mixed $post_type |
| 491 |
*/ |
| 492 |
public function quick_edit( $column_name, $post_type ) { |
| 493 |
if ( 'price' != $column_name || 'property' != $post_type ) { |
| 494 |
return; |
| 495 |
} |
| 496 |
|
| 497 |
include( HP()->plugin_path() . '/includes/admin/views/html-quick-edit-contact.php' ); |
| 498 |
} |
| 499 |
|
| 500 |
/** |
| 501 |
* Quick and bulk edit saving |
| 502 |
* |
| 503 |
* @access public |
| 504 |
* @param int $post_id |
| 505 |
* @param WP_Post $post |
| 506 |
* @return int |
| 507 |
*/ |
| 508 |
public function bulk_and_quick_edit_save_post( $post_id, $post ) { |
| 509 |
// If this is an autosave, our form has not been submitted, so we don't want to do anything. |
| 510 |
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) { |
| 511 |
return $post_id; |
| 512 |
} |
| 513 |
|
| 514 |
// Don't save revisions and autosaves |
| 515 |
if ( wp_is_post_revision( $post_id ) || wp_is_post_autosave( $post_id ) ) { |
| 516 |
return $post_id; |
| 517 |
} |
| 518 |
|
| 519 |
// Check post type is product |
| 520 |
if ( 'contact' != $post->post_type ) { |
| 521 |
return $post_id; |
| 522 |
} |
| 523 |
|
| 524 |
// Check user permission |
| 525 |
if ( ! current_user_can( 'edit_post', $post_id ) ) { |
| 526 |
return $post_id; |
| 527 |
} |
| 528 |
|
| 529 |
// Check nonces |
| 530 |
if ( ! isset( $_REQUEST['propertyhive_quick_edit_nonce'] ) && ! isset( $_REQUEST['propertyhive_bulk_edit_nonce'] ) ) { |
| 531 |
return $post_id; |
| 532 |
} |
| 533 |
if ( isset( $_REQUEST['propertyhive_quick_edit_nonce'] ) && ! wp_verify_nonce( $_REQUEST['propertyhive_quick_edit_nonce'], 'propertyhive_quick_edit_nonce' ) ) { |
| 534 |
return $post_id; |
| 535 |
} |
| 536 |
if ( isset( $_REQUEST['propertyhive_bulk_edit_nonce'] ) && ! wp_verify_nonce( $_REQUEST['propertyhive_bulk_edit_nonce'], 'propertyhive_bulk_edit_nonce' ) ) { |
| 537 |
return $post_id; |
| 538 |
} |
| 539 |
|
| 540 |
// Get the product and save |
| 541 |
$contact = get_contact( $post ); |
| 542 |
|
| 543 |
if ( ! empty( $_REQUEST['propertyhive_quick_edit'] ) ) { |
| 544 |
$this->quick_edit_save( $post_id, $contact ); |
| 545 |
} else { |
| 546 |
$this->bulk_edit_save( $post_id, $contact ); |
| 547 |
} |
| 548 |
|
| 549 |
// Clear transient |
| 550 |
//ph_delete_contact_transients( $post_id ); |
| 551 |
|
| 552 |
return $post_id; |
| 553 |
} |
| 554 |
|
| 555 |
/** |
| 556 |
* Quick edit |
| 557 |
*/ |
| 558 |
private function quick_edit_save( $post_id, $contact ) { |
| 559 |
|
| 560 |
global $wpdb; |
| 561 |
|
| 562 |
/* |
| 563 |
// Save fields |
| 564 |
if ( isset( $_REQUEST['_availability'] ) ) { |
| 565 |
update_post_meta( $post_id, '_availability', ph_clean( $_REQUEST['_availability'] ) ); |
| 566 |
}*/ |
| 567 |
|
| 568 |
do_action( 'propertyhive_product_quick_edit_save', $contact ); |
| 569 |
} |
| 570 |
|
| 571 |
/** |
| 572 |
* Bulk edit |
| 573 |
*/ |
| 574 |
public function bulk_edit_save( $post_id, $contact ) { |
| 575 |
|
| 576 |
/* |
| 577 |
// Save fields |
| 578 |
if ( ! empty( $_REQUEST['_availability'] ) ) { |
| 579 |
update_post_meta( $post_id, '_availability', ph_clean( $_REQUEST['_availability'] ) ); |
| 580 |
}*/ |
| 581 |
|
| 582 |
do_action( 'propertyhive_contact_bulk_edit_save', $contact ); |
| 583 |
} |
| 584 |
|
| 585 |
/** |
| 586 |
* Filter the directory for uploads. |
| 587 |
* |
| 588 |
* @param array $pathdata |
| 589 |
* @return array |
| 590 |
*/ |
| 591 |
public function upload_dir( $pathdata ) { |
| 592 |
// Change upload dir for downloadable files |
| 593 |
if ( isset( $_POST['type'] ) && 'downloadable_product' == $_POST['type'] ) { |
| 594 |
if ( empty( $pathdata['subdir'] ) ) { |
| 595 |
$pathdata['path'] = $pathdata['path'] . '/propertyhive_uploads'; |
| 596 |
$pathdata['url'] = $pathdata['url']. '/propertyhive_uploads'; |
| 597 |
$pathdata['subdir'] = '/propertyhive_uploads'; |
| 598 |
} else { |
| 599 |
$new_subdir = '/propertyhive_uploads' . $pathdata['subdir']; |
| 600 |
|
| 601 |
$pathdata['path'] = str_replace( $pathdata['subdir'], $new_subdir, $pathdata['path'] ); |
| 602 |
$pathdata['url'] = str_replace( $pathdata['subdir'], $new_subdir, $pathdata['url'] ); |
| 603 |
$pathdata['subdir'] = str_replace( $pathdata['subdir'], $new_subdir, $pathdata['subdir'] ); |
| 604 |
} |
| 605 |
} |
| 606 |
|
| 607 |
return $pathdata; |
| 608 |
} |
| 609 |
|
| 610 |
public function generate_applicant_list_action( $which ) |
| 611 |
{ |
| 612 |
global $typenow, $wp_query; |
| 613 |
|
| 614 |
if ( 'contact' != $typenow ) { |
| 615 |
return; |
| 616 |
} |
| 617 |
|
| 618 |
if ( $which == 'top' && isset($_GET['_contact_type']) && $_GET['_contact_type'] == 'applicant' ) |
| 619 |
{ |
| 620 |
echo '<div class="alignleft actions"><a href="' . admin_url('admin.php?page=ph-generate-applicant-list') . '" id="generate_applicant_list_button" class="button">' . __( 'Generate Applicant List', 'propertyhive' ) . '</a></div>'; |
| 621 |
} |
| 622 |
} |
| 623 |
} |
| 624 |
|
| 625 |
endif; |
| 626 |
|
| 627 |
return new PH_Admin_CPT_Contact(); |
| 628 |
|