| 1 |
<?php |
| 2 |
if ( ! defined( 'ABSPATH' ) ) { |
| 3 |
exit; // Exit if accessed directly |
| 4 |
} |
| 5 |
|
| 6 |
global $current_user, $wppmfunction ,$wpdb; |
| 7 |
|
| 8 |
if ( check_ajax_referer( 'wppm_set_delete_bulk_tasks', '_ajax_nonce', false ) != 1 ) { |
| 9 |
wp_send_json_error( 'Unauthorised request!', 401 ); |
| 10 |
} |
| 11 |
$task_ids = isset( $_POST['task_ids'] ) ? array_filter( array_map( 'intval', explode( ',', sanitize_text_field( wp_unslash( $_POST['task_ids'] ) ) ) ) ) : array(); |
| 12 |
$wppm_current_user_capability = get_user_meta( $current_user->ID, 'wppm_capability', true ); |
| 13 |
|
| 14 |
if ( ! $task_ids ) { |
| 15 |
wp_send_json_error( 'Missing task ids', 400 ); |
| 16 |
} |
| 17 |
if ( ! empty($task_ids) ) { |
| 18 |
foreach($task_ids as $task_id){ |
| 19 |
$task_data = $wppmfunction->get_task($task_id); |
| 20 |
$project_data = $wppmfunction->get_project($task_data['project']); |
| 21 |
if ((($current_user->ID && $current_user->has_cap('manage_options')) || ($wppmfunction->has_permission('delete_task',$task_id)) || $wppm_current_user_capability == 'wppm_admin'|| $project_data['created_by']==$current_user->ID)) { |
| 22 |
// Deletes the task's own attachments/checklists/comments, and cascades to any subtasks. |
| 23 |
WPPM_Functions::delete_task_and_children($task_id); |
| 24 |
} |
| 25 |
} |
| 26 |
} |
| 27 |
do_action('wppm_after_bulk_delete_all_tasks',$task_ids); |