PluginProbe
Taskbuilder – Project Management & Task Management Tool With Kanban Board / 5.0.4
Taskbuilder – Project Management & Task Management Tool With Kanban Board v5.0.4
6.0.6 6.0.5 6.0.2 6.0.3 6.0.4 6.0.1 6.0.0 5.0.8 5.0.9 4.0.9 5.0.0 5.0.1 5.0.2 5.0.3 5.0.4 5.0.5 5.0.6 5.0.7 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 All 58 releases
taskbuilder / includes / admin / tasks / open_task / wppm_thread_attachment_remove.php

wppm_thread_attachment_remove.php in Taskbuilder – Project Management & Task Management Tool With Kanban Board 5.0.4, at includes/admin/tasks/open_task/wppm_thread_attachment_remove.php

47 lines 2.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if ( ! defined( 'ABSPATH' ) ) {
3 exit; // Exit if accessed directly
4 }
5
6 global $current_user, $wppmfunction, $wpdb;
7 if ( check_ajax_referer( 'wppm_remove_thread_attachment', '_ajax_nonce', false ) != 1 ) {
8 wp_send_json_error( 'Unauthorised request!', 401 );
9 }
10 $attachment = isset($_POST['attachment']) ? intval(sanitize_text_field(wp_unslash($_POST['attachment']))) : '0' ;
11 $attachment = esc_sql($attachment);
12 $comment_id = isset($_POST['comment_id']) ? intval(sanitize_text_field(wp_unslash($_POST['comment_id']))) : '0' ;
13 $task_id = isset($_POST['task_id']) ? intval(sanitize_text_field(wp_unslash($_POST['task_id']))) : '0' ;
14 $task_comment = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}wppm_task_comment WHERE id = %d AND task_id = %d", $comment_id,$task_id));
15 if(!(((!empty($task_comment)) && ($task_comment->created_by == $current_user->ID)) || ($current_user->has_cap('manage_options')) || ($wppmfunction->has_comment_permission('edit_task_comment',$task_id,$comment_id)))){
16 exit;
17 }
18 $attachment = absint( $attachment );
19 $result = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}wppm_attachments WHERE id = %d", $attachment ));
20 $file_path = isset( $result->file_path ) ? $result->file_path : '';
21 $attach_result = $wpdb->get_results( $wpdb->prepare( "SELECT file_path FROM {$wpdb->prefix}wppm_attachments WHERE file_path = %s", $file_path));
22 $result_count = count($attach_result);
23 if(file_exists($result->file_path) && $result_count < 2)
24 {
25 wp_delete_file($result->file_path);
26 }
27 $success = $wpdb->delete(
28 $wpdb->prefix . 'wppm_attachments',
29 array( 'id' => "$attachment" )
30 );
31 if( !$success ) return false;
32 $comment_id = isset( $comment_id ) ? absint( $comment_id ) : 0;
33 $task_attachment = $wpdb->get_var( $wpdb->prepare( "SELECT attachment_ids FROM {$wpdb->prefix}wppm_task_comment WHERE id = %d", $comment_id));
34 $task_attachment = explode(",",$task_attachment);
35 if(!empty($task_attachment)){
36 foreach($task_attachment as $key=>$val){
37 if($val == $attachment){
38 unset($task_attachment[$key]);
39 }
40 }
41 }
42 $tattachment = implode(',',$task_attachment);
43 $values=array(
44 'attachment_ids'=>esc_sql($tattachment)
45 );
46 $wpdb->update($wpdb->prefix.'wppm_task_comment', $values, array('id'=>"$comment_id"));
47 $attachment = apply_filters('wppm_after_delete_comment_attachment',$attachment,$comment_id,$task_id);