PluginProbe
Taskbuilder – Project Management & Task Management Tool With Kanban Board / 6.0.1
Taskbuilder – Project Management & Task Management Tool With Kanban Board v6.0.1
6.0.5 6.0.2 6.0.3 6.0.4 6.0.1 6.0.0 5.0.8 5.0.9 4.0.9 5.0.0 5.0.1 5.0.2 5.0.3 5.0.4 5.0.5 5.0.6 5.0.7 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 All 57 releases
taskbuilder / includes / admin / tasks / wppm_set_delete_task.php

wppm_set_delete_task.php in Taskbuilder – Project Management & Task Management Tool With Kanban Board 6.0.1, at includes/admin/tasks/wppm_set_delete_task.php

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