| 1 |
<?php |
| 2 |
if ( ! defined( 'ABSPATH' ) ) { |
| 3 |
exit; // Exit if accessed directly |
| 4 |
} |
| 5 |
global $current_user,$wpdb,$wppmfunction; |
| 6 |
if ( check_ajax_referer( 'wppm_remove_subtask', '_ajax_nonce', false ) != 1 ) { |
| 7 |
wp_send_json_error( 'Unauthorised request!', 401 ); |
| 8 |
} |
| 9 |
$subtask_id = isset($_POST) && isset($_POST['subtask_id']) ? absint(sanitize_text_field(wp_unslash($_POST['subtask_id']))) : ''; |
| 10 |
if (!$subtask_id) {exit;} |
| 11 |
|
| 12 |
$subtask = $wppmfunction->get_task($subtask_id); |
| 13 |
if (empty($subtask) || empty($subtask['parent_task_id'])) {exit;} |
| 14 |
|
| 15 |
$project_data = $wppmfunction->get_project($subtask['project']); |
| 16 |
$wppm_current_user_capability = get_user_meta( $current_user->ID, 'wppm_capability', true ); |
| 17 |
if (!(($current_user->ID && $current_user->has_cap('manage_options')) || $wppmfunction->has_permission('delete_task',$subtask_id) || $wppm_current_user_capability == 'wppm_admin' || $project_data['created_by']==$current_user->ID)) { |
| 18 |
exit; |
| 19 |
} |
| 20 |
|
| 21 |
WPPM_Functions::delete_task_and_children($subtask_id); |
| 22 |
|