| 1 |
<?php |
| 2 |
if ( ! defined( 'ABSPATH' ) ) { |
| 3 |
exit; // Exit if accessed directly |
| 4 |
} |
| 5 |
global $wpdb,$wppmfunction,$current_user; |
| 6 |
if ( check_ajax_referer( 'wppm_set_bulk_change_task_priority', '_ajax_nonce', false ) != 1 ) { |
| 7 |
wp_send_json_error( 'Unauthorised request!', 401 ); |
| 8 |
} |
| 9 |
|
| 10 |
$task_ids = isset( $_POST['task_ids'] ) ? array_filter( array_map( 'intval', explode( ',', sanitize_text_field( wp_unslash( $_POST['task_ids'] ) ) ) ) ) : array(); |
| 11 |
if ( ! $task_ids ) { |
| 12 |
wp_send_json_error( 'Missing task ids', 400 ); |
| 13 |
} |
| 14 |
$task_priority = isset($_POST['wppm_task_priority']) ? intval(sanitize_text_field(wp_unslash($_POST['wppm_task_priority']))) : 0 ; |
| 15 |
if(!empty($task_ids)){ |
| 16 |
foreach($task_ids as $task_id){ |
| 17 |
$task_data = $wppmfunction->get_task($task_id); |
| 18 |
$wppm_current_user_capability = get_user_meta( $current_user->ID, 'wppm_capability', true ); |
| 19 |
if ((($current_user->ID && $current_user->has_cap('manage_options')) || $wppmfunction->has_permission('change_task_details',$task_id))) { |
| 20 |
if( !$task_priority ){ |
| 21 |
die(); |
| 22 |
} |
| 23 |
$old_priority_id = $task_data['priority']; |
| 24 |
|
| 25 |
if( $task_priority && $task_priority != $old_priority_id){ |
| 26 |
$wppmfunction->change_priority( $task_id, $task_priority); |
| 27 |
$change_priority_value = array('prev_prio'=>"$task_data[priority]",'new_prio'=>"$task_priority"); |
| 28 |
$change_priority_obj = serialize($change_priority_value); |
| 29 |
$log_values = array('task_id'=>esc_sql($task_id),'body'=>$change_priority_obj,'attachment_ids'=>"",'create_time'=>wp_date("Y-m-d h:i:sa"),'created_by'=>esc_sql($current_user->ID)); |
| 30 |
$wpdb->insert($wpdb->prefix . 'wppm_task_comment',$log_values); |
| 31 |
$log_id = $wpdb->insert_id; |
| 32 |
$task_log_values = array('task_id'=>esc_sql($task_id),'comment_id'=>esc_sql($log_id),'comment_type'=>'change_task_priority'); |
| 33 |
$wpdb->insert($wpdb->prefix . 'wppm_task_comment_meta',$task_log_values); |
| 34 |
} |
| 35 |
} |
| 36 |
} |
| 37 |
} |
| 38 |
do_action('wppm_after_set_bulk_change_task_priority',$task_ids, $task_priority); |