| 1 |
<?php |
| 2 |
if ( ! defined( 'ABSPATH' ) ) { |
| 3 |
exit; // Exit if accessed directly |
| 4 |
} |
| 5 |
|
| 6 |
global $current_user, $wppmfunction ,$wpdb; |
| 7 |
$task_id = isset($_POST['task_id']) ? sanitize_text_field($_POST['task_id']) : 0 ; |
| 8 |
$thread_id = isset($_POST['comment_id']) ? sanitize_text_field($_POST['comment_id']) : 0 ; |
| 9 |
$task_comment = $wppmfunction->get_task_comment($thread_id); |
| 10 |
if (!(($current_user->ID && $current_user->has_cap('manage_options')) || $wppmfunction->has_comment_permission('delete_task_thread',$task_id,$thread_id))) {exit;} |
| 11 |
$sql="SELECT attachment_ids FROM {$wpdb->prefix}wppm_task_comment WHERE id =".$thread_id; |
| 12 |
$thread_attachment_ids = $wpdb->get_results( $sql ); |
| 13 |
if(!empty($thread_attachment_ids) ){ |
| 14 |
foreach ($thread_attachment_ids as $thread_attachment_id){ |
| 15 |
$attachment_ids_temp=array(); |
| 16 |
if($thread_attachment_id->attachment_ids){ |
| 17 |
$attachment_ids_temp = explode(',', $thread_attachment_id->attachment_ids); |
| 18 |
} |
| 19 |
$attachment_ids=$attachment_ids_temp; |
| 20 |
if(!empty($attachment_ids_temp)){ |
| 21 |
foreach ($attachment_ids_temp as $attachment_id){ |
| 22 |
$sql="SELECT * FROM {$wpdb->prefix}wppm_attachments WHERE id =".$attachment_id; |
| 23 |
$result=$wpdb->get_row($sql); |
| 24 |
if(!empty($result)){ |
| 25 |
$sql_query="SELECT file_path FROM {$wpdb->prefix}wppm_attachments WHERE file_path ='".$result->file_path."'"; |
| 26 |
$attach_result=$wpdb->get_results($sql_query); |
| 27 |
$result_count = count($attach_result); |
| 28 |
if(file_exists($result->file_path) && $result_count < 2) |
| 29 |
{ |
| 30 |
unlink($result->file_path); |
| 31 |
} |
| 32 |
$wpdb->delete($wpdb->prefix.'wppm_attachments', array( 'id' => $attachment_id)); |
| 33 |
} |
| 34 |
} |
| 35 |
} |
| 36 |
} |
| 37 |
} |
| 38 |
$wpdb->delete($wpdb->prefix.'wppm_task_comment',array('id'=>$thread_id)); |
| 39 |
|
| 40 |
?> |