# taskbuilder/5.0.2/includes/admin/tasks/wppm_set_delete_task.php

Taskbuilder – Project Management &amp; Task Management Tool With Kanban Board, version 5.0.2. 67 lines.

- Page: https://pluginprobe.com/plugins/taskbuilder/5.0.2/code/includes/admin/tasks/wppm_set_delete_task.php
- Raw: https://pluginprobe.com/plugins/taskbuilder/5.0.2/raw/includes/admin/tasks/wppm_set_delete_task.php
- Modified: 2025-08-27T06:53:18+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/taskbuilder/5.0.2/code/includes/admin/tasks/wppm_set_delete_task.php#L10-L20`.

```php
<?php
if ( ! defined( 'ABSPATH' ) ) {
	exit; // Exit if accessed directly
}

global $current_user, $wppmfunction ,$wpdb;
$task_id  = isset($_POST['task_id']) ? intval(sanitize_text_field($_POST['task_id'])) : 0 ;
if ( check_ajax_referer( 'wppm_set_delete_task', '_ajax_nonce', false ) != 1 ) {
	wp_send_json_error( 'Unauthorised request!', 401 );
}
$task_data = $wppmfunction->get_task($task_id);
$project_data = $wppmfunction->get_project($task_data['project']);
$wppm_current_user_capability = get_user_meta( $current_user->ID, 'wppm_capability', true );
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 )){
    exit;
}
$sql="SELECT attachment_ids FROM {$wpdb->prefix}wppm_task_comment WHERE task_id ='" .esc_sql($task_id)."'";
$thread_attachment_ids= $wpdb->get_results( $sql );
/***************************Code for deleting attachment files****************************************************/
if(!empty($thread_attachment_ids)){
    foreach ($thread_attachment_ids as $thread_attachment_id){
        $attachment_ids_temp = array();
        if($thread_attachment_id->attachment_ids){
            $attachment_ids_temp = explode(',', $thread_attachment_id->attachment_ids);
        }
        if(!empty($attachment_ids_temp)){
            foreach ($attachment_ids_temp as $attachment_id){
                $sql="SELECT * FROM {$wpdb->prefix}wppm_attachments WHERE id  ='" .esc_sql($attachment_id)."'";
                $result=$wpdb->get_row($sql);
                if(!empty($result)){
                    $sql_query="SELECT file_path FROM {$wpdb->prefix}wppm_attachments WHERE file_path ='".esc_sql($result->file_path)."'";
                    $attach_result=$wpdb->get_results($sql_query);
                    $result_count = count($attach_result);
                    if(file_exists($result->file_path) && $result_count < 2)
                    {
                        unlink($result->file_path);
                    }
                    $wpdb->delete($wpdb->prefix.'wppm_attachments', array( 'id' => esc_sql($attachment_id)));
                }
            }
        }
    }
}
/***************************Code for deleting checklists****************************************************/
$sql="SELECT id FROM {$wpdb->prefix}wppm_checklist WHERE task_id ='" .esc_sql($task_id)."'";
$checklists = $wpdb->get_results( $sql );
if(!empty($checklists)){
    foreach($checklists as $checklist){
        $chk_array = (array) $checklist;
        $chk_array_id = esc_sql($chk_array['id']);
        $sql="SELECT id FROM {$wpdb->prefix}wppm_checklist_items WHERE checklist_id = '".esc_sql($chk_array_id)."'";
        $checklist_items = $wpdb->get_results( $sql );
        if(!empty($checklist_items)){
            foreach($checklist_items as $ch_item){
                $chk_items_array = (array) $ch_item;
                $chk_items_array_id = esc_sql($chk_items_array['id']);
                $wpdb->delete($wpdb->prefix.'wppm_checklist_items',array('id'=>"$chk_items_array_id"));
            }
        }
        $wpdb->delete($wpdb->prefix.'wppm_checklist',array('id'=>"$chk_array_id"));
    }
}
$wpdb->delete($wpdb->prefix.'wppm_task',array('id'=>esc_sql($task_id)));
$wpdb->delete($wpdb->prefix.'wppm_task_meta',array('task_id'=>esc_sql($task_id)));
$wpdb->delete($wpdb->prefix.'wppm_task_comment',array('task_id'=>esc_sql($task_id)));
$wpdb->delete($wpdb->prefix.'wppm_task_comment_meta',array('task_id'=>esc_sql($task_id)));
do_action('wppm_after_delete_task',$task_id);
```
