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