| @@ -3,12 +3,13 @@ | ||
| 3 | 3 | exit; // Exit if accessed directly |
| 4 | 4 | } |
| 5 | 5 | |
| 6 | 6 | global $current_user, $wppmfunction ,$wpdb; |
| 7 | -$task_id = isset($_POST['task_id']) ? intval(sanitize_text_field($_POST['task_id'])) : 0 ; | |
| 8 | 7 | if ( check_ajax_referer( 'wppm_set_delete_task', '_ajax_nonce', false ) != 1 ) { |
| 9 | 8 | wp_send_json_error( 'Unauthorised request!', 401 ); |
| 10 | 9 | } |
| 10 | +$task_id = isset($_POST['task_id']) ? intval(sanitize_text_field(wp_unslash($_POST['task_id']))) : 0 ; | |
| 11 | + | |
| 11 | 12 | $task_data = $wppmfunction->get_task($task_id); |
| 12 | 13 | $project_data = $wppmfunction->get_project($task_data['project']); |
| 13 | 14 | $wppm_current_user_capability = get_user_meta( $current_user->ID, 'wppm_capability', true ); |
| 14 | 15 | 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 )){ |
| @@ -13,55 +14,6 @@ | ||
| 13 | 14 | $wppm_current_user_capability = get_user_meta( $current_user->ID, 'wppm_capability', true ); |
| 14 | 15 | 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 )){ |
| 15 | 16 | exit; |
| 16 | 17 | } |
| 17 | -$sql="SELECT attachment_ids FROM {$wpdb->prefix}wppm_task_comment WHERE task_id ='" .esc_sql($task_id)."'"; | |
| 18 | -$thread_attachment_ids= $wpdb->get_results( $sql ); | |
| 19 | -/***************************Code for deleting attachment files****************************************************/ | |
| 20 | -if(!empty($thread_attachment_ids)){ | |
| 21 | - foreach ($thread_attachment_ids as $thread_attachment_id){ | |
| 22 | - $attachment_ids_temp = array(); | |
| 23 | - if($thread_attachment_id->attachment_ids){ | |
| 24 | - $attachment_ids_temp = explode(',', $thread_attachment_id->attachment_ids); | |
| 25 | - } | |
| 26 | - if(!empty($attachment_ids_temp)){ | |
| 27 | - foreach ($attachment_ids_temp as $attachment_id){ | |
| 28 | - $sql="SELECT * FROM {$wpdb->prefix}wppm_attachments WHERE id ='" .esc_sql($attachment_id)."'"; | |
| 29 | - $result=$wpdb->get_row($sql); | |
| 30 | - if(!empty($result)){ | |
| 31 | - $sql_query="SELECT file_path FROM {$wpdb->prefix}wppm_attachments WHERE file_path ='".esc_sql($result->file_path)."'"; | |
| 32 | - $attach_result=$wpdb->get_results($sql_query); | |
| 33 | - $result_count = count($attach_result); | |
| 34 | - if(file_exists($result->file_path) && $result_count < 2) | |
| 35 | - { | |
| 36 | - unlink($result->file_path); | |
| 37 | - } | |
| 38 | - $wpdb->delete($wpdb->prefix.'wppm_attachments', array( 'id' => esc_sql($attachment_id))); | |
| 39 | - } | |
| 40 | - } | |
| 41 | - } | |
| 42 | - } | |
| 43 | -} | |
| 44 | -/***************************Code for deleting checklists****************************************************/ | |
| 45 | -$sql="SELECT id FROM {$wpdb->prefix}wppm_checklist WHERE task_id ='" .esc_sql($task_id)."'"; | |
| 46 | -$checklists = $wpdb->get_results( $sql ); | |
| 47 | -if(!empty($checklists)){ | |
| 48 | - foreach($checklists as $checklist){ | |
| 49 | - $chk_array = (array) $checklist; | |
| 50 | - $chk_array_id = esc_sql($chk_array['id']); | |
| 51 | - $sql="SELECT id FROM {$wpdb->prefix}wppm_checklist_items WHERE checklist_id = '".esc_sql($chk_array_id)."'"; | |
| 52 | - $checklist_items = $wpdb->get_results( $sql ); | |
| 53 | - if(!empty($checklist_items)){ | |
| 54 | - foreach($checklist_items as $ch_item){ | |
| 55 | - $chk_items_array = (array) $ch_item; | |
| 56 | - $chk_items_array_id = esc_sql($chk_items_array['id']); | |
| 57 | - $wpdb->delete($wpdb->prefix.'wppm_checklist_items',array('id'=>"$chk_items_array_id")); | |
| 58 | - } | |
| 59 | - } | |
| 60 | - $wpdb->delete($wpdb->prefix.'wppm_checklist',array('id'=>"$chk_array_id")); | |
| 61 | - } | |
| 62 | -} | |
| 63 | -$wpdb->delete($wpdb->prefix.'wppm_task',array('id'=>esc_sql($task_id))); | |
| 64 | -$wpdb->delete($wpdb->prefix.'wppm_task_meta',array('task_id'=>esc_sql($task_id))); | |
| 65 | -$wpdb->delete($wpdb->prefix.'wppm_task_comment',array('task_id'=>esc_sql($task_id))); | |
| 66 | -$wpdb->delete($wpdb->prefix.'wppm_task_comment_meta',array('task_id'=>esc_sql($task_id))); | |
| 67 | -do_action('wppm_after_delete_task',$task_id); | |
| 18 | +// Deletes the task's own attachments/checklists/comments, and cascades to any subtasks. | |
| 19 | +WPPM_Functions::delete_task_and_children($task_id); | |