get_proj_comment($thread_id); if (!(($current_user->ID && $current_user->has_cap('manage_options')) || $wppmfunction->has_proj_comment_permission('delete_proj_thread',$proj_id,$thread_id))) {exit;} $thread_attachment_ids = $wpdb->get_results( $wpdb->prepare( "SELECT attachment_ids FROM {$wpdb->prefix}wppm_project_comment WHERE id = %d", $thread_id )); 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){ $result = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}wppm_attachments WHERE id = %d", $attachment_id)); if(!empty($result)){ $res_file_path = esc_sql($result->file_path); $attach_result = $wpdb->get_results( $wpdb->prepare( "SELECT file_path FROM {$wpdb->prefix}wppm_attachments WHERE file_path = %s",$res_file_path)); $result_count = count($attach_result); if(file_exists($result->file_path) && $result_count < 2) { wp_delete_file($result->file_path); } $attachment_id = esc_sql($attachment_id); $wpdb->delete($wpdb->prefix.'wppm_attachments', array( 'id' => "$attachment_id")); } } } } } $cur_user = get_userdata($current_user->ID); $log_values = array('proj_id'=>"$proj_id",'body'=>'This comment was deleted by '.$cur_user->display_name,'attachment_ids'=>""); $wpdb->update($wpdb->prefix.'wppm_project_comment', $log_values, array('id'=>"$thread_id")); $comment_meta = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}wppm_project_comment_meta WHERE comment_id = %d",$thread_id)); $proj_log_values = array('proj_id'=>"$proj_id",'comment_id'=>"$thread_id",'comment_type'=>'delete_proj_comment'); if(!empty($comment_meta)){ $wpdb->update($wpdb->prefix . 'wppm_project_comment_meta',$proj_log_values,array('id'=>esc_sql($comment_meta->id))); } else{ $wpdb->insert($wpdb->prefix . 'wppm_project_comment_meta',$proj_log_values); } do_action('wppm_after_delete_project_thread',$thread_id,$proj_id); ?>