# taskbuilder/6.0.6/includes/admin/projects/wppm_set_delete_project.php

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

- Page: https://pluginprobe.com/plugins/taskbuilder/6.0.6/code/includes/admin/projects/wppm_set_delete_project.php
- Raw: https://pluginprobe.com/plugins/taskbuilder/6.0.6/raw/includes/admin/projects/wppm_set_delete_project.php
- Modified: 2026-08-26T12:08:58+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/6.0.6/code/includes/admin/projects/wppm_set_delete_project.php#L10-L20`.

```php
<?php
if ( ! defined( 'ABSPATH' ) ) {
	exit; // Exit if accessed directly
}

global $current_user, $wppmfunction ,$wpdb;

if ( check_ajax_referer( 'wppm_set_delete_project', '_ajax_nonce', false ) != 1 ) {
    wp_send_json_error( 'Unauthorised request!', 401 );
}
$project_id  = isset($_POST['project_id']) ? intval(sanitize_text_field(wp_unslash($_POST['project_id']))) : 0 ;
$project = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->prefix}wppm_project where id = %d",absint($project_id)));
$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_project_permission('delete_project',$project_id) || ($project->created_by==$current_user->ID && $wppm_current_user_capability == 'wppm_manager') || ($current_user->ID && $current_user->has_cap('wppm_admin')))) {exit;}

$tasks = $wpdb->get_results($wpdb->prepare("SELECT * FROM {$wpdb->prefix}wppm_task where project = %d",absint($project_id)));
/*************delete project********/
    $wpdb->delete($wpdb->prefix.'wppm_project',array('id'=>"$project_id"));

/*************delete project comment********/
$sql=$wpdb->prepare("SELECT attachment_ids FROM {$wpdb->prefix}wppm_project_comment WHERE proj_id = %d",absint($project_id));
$proj_comm_attachment_ids= $wpdb->get_results( $sql );
if(!empty($proj_comm_attachment_ids)){
    foreach ($proj_comm_attachment_ids as $proj_attachment_id){
        $proj_attachment_ids_temp=array();
        if($proj_attachment_id->attachment_ids){
            $proj_attachment_ids_temp=  explode(',', $proj_attachment_id->attachment_ids);
        }
        foreach ($proj_attachment_ids_temp as $proj_attachment_id){
            $proj_attachment_id = absint($proj_attachment_id);
            $sql=$wpdb->prepare("SELECT * FROM {$wpdb->prefix}wppm_attachments WHERE id = %d",absint($proj_attachment_id));
            $att_result=$wpdb->get_row($sql);
            if(!empty($att_result)){
                $sql_query=$wpdb->prepare("SELECT file_path FROM {$wpdb->prefix}wppm_attachments WHERE file_path = %s",esc_sql($att_result->file_path));
                $proj_attach_result=$wpdb->get_results($sql_query);
                $proj_result_count = count($proj_attach_result);
                if(file_exists($att_result->file_path) && $proj_result_count < 2)
                {
                    wp_delete_file($att_result->file_path);
                }
                $wpdb->delete($wpdb->prefix.'wppm_attachments', array( 'id' => "$proj_attachment_id"));
            }
        }
    }
}
$wpdb->delete($wpdb->prefix.'wppm_project_comment',array('proj_id'=>absint($project_id)));
$wpdb->delete($wpdb->prefix.'wppm_project_meta',array('project_id'=>absint($project_id)));
$wpdb->delete($wpdb->prefix.'wppm_project_comment_meta',array('proj_id'=>absint($project_id)));

/*************delete project's tasks and comments********/
foreach($tasks as $task){
    $sql=$wpdb->prepare("SELECT attachment_ids FROM {$wpdb->prefix}wppm_task_comment WHERE task_id = %d",absint($task->id));
    $thread_attachment_ids= $wpdb->get_results( $sql );
    $tid = absint($task->id);
    /***************************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);
            }
            //$attachment_ids=$attachment_ids_temp;
            foreach ($attachment_ids_temp as $attachment_id){
                $sql=$wpdb->prepare("SELECT * FROM {$wpdb->prefix}wppm_attachments WHERE id = %d",absint($attachment_id));
                $result=$wpdb->get_row($sql);
                if(!empty($result)){
                    $sql_query=$wpdb->prepare("SELECT file_path FROM {$wpdb->prefix}wppm_attachments WHERE file_path = %s",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)
                    {
                        wp_delete_file($result->file_path);
                    }
                    $wpdb->delete($wpdb->prefix.'wppm_attachments', array( 'id' => absint($attachment_id)));
                }
            }
        }
    }
    /***************************Code for deleting checklists****************************************************/
    $sql=$wpdb->prepare("SELECT id FROM {$wpdb->prefix}wppm_checklist WHERE task_id = %d",$tid);
    $checklists = $wpdb->get_results( $sql );
    if(!empty($checklists)){
        foreach($checklists as $checklist){
            $chk_array = (array) $checklist;
            $chk_id = absint($chk_array['id']);
            $sql=$wpdb->prepare("SELECT id FROM {$wpdb->prefix}wppm_checklist_items WHERE checklist_id = %d",$chk_id);
            $checklist_items = $wpdb->get_results( $sql );
            if(!empty($checklist_items)){
                foreach($checklist_items as $ch_item){
                    $chk_items_array = (array) $ch_item;
                    $chk_item_id = absint($chk_items_array['id']);
                    $wpdb->delete($wpdb->prefix.'wppm_checklist_items',array('id'=>"$chk_item_id"));
                }
            }
            $wpdb->delete($wpdb->prefix.'wppm_checklist',array('id'=> "$chk_id"));
        }
    }
    $wpdb->delete($wpdb->prefix.'wppm_task',array('project'=>absint($project_id)));
    $wpdb->delete($wpdb->prefix.'wppm_task_meta',array('task_id'=>absint($tid)));
    $wpdb->delete($wpdb->prefix.'wppm_task_comment',array('task_id'=>absint($tid)));
    $wpdb->delete($wpdb->prefix.'wppm_task_comment_meta',array('task_id'=>absint($tid)));
}

```
