get_task_comment($thread_id); if (!(($current_user->ID && $current_user->has_cap('manage_options')) || $wppmfunction->has_comment_permission('delete_task_thread',$task_id,$thread_id))) {exit;} if ( check_ajax_referer( 'wppm_set_delete_thread', '_ajax_nonce', false ) != 1 ) { wp_send_json_error( 'Unauthorised request!', 401 ); } $thread_id = esc_sql($thread_id); $task_id = esc_sql($task_id); $sql="SELECT attachment_ids FROM {$wpdb->prefix}wppm_task_comment WHERE id ='$thread_id'"; $thread_attachment_ids = $wpdb->get_results( $sql ); 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; if(!empty($attachment_ids_temp)){ foreach ($attachment_ids_temp as $attachment_id){ $attachment_id = esc_sql($attachment_id); $sql="SELECT * FROM {$wpdb->prefix}wppm_attachments WHERE id = '$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' => $attachment_id)); } } } } } $cur_user = get_userdata($current_user->ID); $cur_user_display_name = $cur_user->display_name; $log_values = array('task_id'=>"$task_id",'body'=>'This comment was deleted by '.$cur_user_display_name,'attachment_ids'=>"" ); $wpdb->update($wpdb->prefix.'wppm_task_comment', $log_values, array('id'=>"$thread_id")); $task_log_values = array('task_id'=>"$task_id",'comment_id'=>"$thread_id",'comment_type'=>'delete_task_comment'); $comment_meta = $wpdb->get_row("SELECT * FROM {$wpdb->prefix}wppm_task_comment_meta WHERE comment_id='$thread_id' "); if(!empty($comment_meta)){ $comment_meta_id = esc_sql($comment_meta->id); $wpdb->update($wpdb->prefix . 'wppm_task_comment_meta',$task_log_values,array('id'=>"$comment_meta_id")); }else{ $wpdb->insert($wpdb->prefix . 'wppm_task_comment_meta',$task_log_values); } ?>