PluginProbe
Taskbuilder – Project Management & Task Management Tool With Kanban Board / 6.0.6
Taskbuilder – Project Management & Task Management Tool With Kanban Board v6.0.6
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 / projects / open_project / wppm_proj_thread_attachment_remove.php

wppm_proj_thread_attachment_remove.php in Taskbuilder – Project Management & Task Management Tool With Kanban Board 6.0.6, at includes/admin/projects/open_project/wppm_proj_thread_attachment_remove.php

47 lines 2.2 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_proj_thread_attachment', '_ajax_nonce', false ) != 1 ) {
8 wp_send_json_error( 'Unauthorised request!', 401 );
9 }
10 $attachment = isset($_POST['attachment']) ? absint(wp_unslash($_POST['attachment'])) : '0' ;
11 $attachment = esc_sql($attachment);
12 $comment_id = isset($_POST['comment_id']) ? absint(wp_unslash($_POST['comment_id'])) : '0' ;
13 $comment_id = esc_sql($comment_id );
14 $proj_id = isset($_POST['proj_id']) ? absint(wp_unslash($_POST['proj_id'])) : '0' ;
15 $proj_id = esc_sql($proj_id );
16 $proj_comment = $wpdb->get_row( $wpdb->prepare("SELECT * FROM {$wpdb->prefix}wppm_project_comment WHERE id = %d AND proj_id = %d",absint($comment_id), absint($proj_id)));
17 if(!(((!empty($proj_comment)) && ($proj_comment->created_by == $current_user->ID)) || ($current_user->has_cap('manage_options')) || ($wppmfunction->has_proj_comment_permission('edit_proj_comment',$proj_id,$comment_id)))){
18 exit;
19 }
20 $result = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}wppm_attachments WHERE id = %d", $attachment));
21 $sql_query = $wpdb->prepare( "SELECT file_path FROM {$wpdb->prefix}wppm_attachments WHERE file_path = %s", $result->file_path );
22 $attach_result=$wpdb->get_results($sql_query);
23 $result_count = count($attach_result);
24 if(file_exists($result->file_path) && $result_count < 2)
25 {
26 wp_delete_file($result->file_path);
27 }
28 $success = $wpdb->delete(
29 $wpdb->prefix . 'wppm_attachments',
30 array( 'id' => $attachment )
31 );
32 if( !$success ) return false;
33 $proj_attachment = $wpdb->get_var( $wpdb->prepare( "SELECT attachment_ids FROM {$wpdb->prefix}wppm_project_comment WHERE id = %d", $comment_id ));
34 $proj_attachment = explode(",",$proj_attachment);
35 if(!empty($proj_attachment)){
36 foreach($proj_attachment as $key=>$val){
37 if($val == $attachment){
38 unset($proj_attachment[$key]);
39 }
40 }
41 }
42 $pattachment = implode(',',$proj_attachment);
43 $values=array(
44 'attachment_ids'=>$pattachment
45 );
46 $wpdb->update($wpdb->prefix.'wppm_project_comment', $values, array('id'=>"$comment_id"));
47 $attachment = apply_filters('wppm_after_delete_proj_comment_attachment',$attachment,$comment_id,$proj_id);