← All changes
|
includes/admin/tasks/open_task/wppm_set_delete_thread.php
+56
-56
5.0.4
→
6.0.6
View file →
| @@ -1,57 +1,57 @@ | ||
| 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_set_delete_thread', '_ajax_nonce', false ) != 1 ) { | |
| 8 | - wp_send_json_error( 'Unauthorised request!', 401 ); | |
| 9 | -} | |
| 10 | -$task_id = isset($_POST['task_id']) ? intval(sanitize_text_field(wp_unslash($_POST['task_id']))) : 0 ; | |
| 11 | -$thread_id = isset($_POST['comment_id']) ? intval(sanitize_text_field(wp_unslash($_POST['comment_id']))) : 0 ; | |
| 12 | -$task_comment = $wppmfunction->get_task_comment($thread_id); | |
| 13 | -if (!(($current_user->ID && $current_user->has_cap('manage_options')) || $wppmfunction->has_comment_permission('delete_task_thread',$task_id,$thread_id))) {exit;} | |
| 14 | -$thread_id = absint($thread_id); | |
| 15 | -$task_id = absint($task_id); | |
| 16 | -$sql=$wpdb->prepare("SELECT attachment_ids FROM {$wpdb->prefix}wppm_task_comment WHERE id = %d",$thread_id); | |
| 17 | -$thread_attachment_ids = $wpdb->get_results( $sql ); | |
| 18 | -if(!empty($thread_attachment_ids) ){ | |
| 19 | - foreach ($thread_attachment_ids as $thread_attachment_id){ | |
| 20 | - $attachment_ids_temp=array(); | |
| 21 | - if($thread_attachment_id->attachment_ids){ | |
| 22 | - $attachment_ids_temp = explode(',', $thread_attachment_id->attachment_ids); | |
| 23 | - } | |
| 24 | - $attachment_ids=$attachment_ids_temp; | |
| 25 | - if(!empty($attachment_ids_temp)){ | |
| 26 | - foreach ($attachment_ids_temp as $attachment_id){ | |
| 27 | - $attachment_id = absint($attachment_id); | |
| 28 | - $sql=$wpdb->prepare("SELECT * FROM {$wpdb->prefix}wppm_attachments WHERE id = %d",$attachment_id); | |
| 29 | - $result=$wpdb->get_row($sql); | |
| 30 | - if(!empty($result)){ | |
| 31 | - $sql_query=$wpdb->prepare("SELECT file_path FROM {$wpdb->prefix}wppm_attachments WHERE file_path = %s",$result->file_path); | |
| 32 | - $attach_result=$wpdb->get_results($sql_query); | |
| 33 | - $result_count = count($attach_result); | |
| 34 | - if(file_exists($result->file_path) && $result_count < 2) | |
| 35 | - { | |
| 36 | - wp_delete_file($result->file_path); | |
| 37 | - } | |
| 38 | - $wpdb->delete($wpdb->prefix.'wppm_attachments', array( 'id' => $attachment_id)); | |
| 39 | - } | |
| 40 | - } | |
| 41 | - } | |
| 42 | - } | |
| 43 | -} | |
| 44 | -$cur_user = get_userdata($current_user->ID); | |
| 45 | -$cur_user_display_name = $cur_user->display_name; | |
| 46 | -$log_values = array('task_id'=>"$task_id",'body'=>'This comment was deleted by '.$cur_user_display_name,'attachment_ids'=>"" ); | |
| 47 | -$wpdb->update($wpdb->prefix.'wppm_task_comment', $log_values, array('id'=>"$thread_id")); | |
| 48 | -$task_log_values = array('task_id'=>"$task_id",'comment_id'=>"$thread_id",'comment_type'=>'delete_task_comment'); | |
| 49 | -$comment_meta = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->prefix}wppm_task_comment_meta WHERE comment_id = %d",$thread_id)); | |
| 50 | -if(!empty($comment_meta)){ | |
| 51 | - $comment_meta_id = absint($comment_meta->id); | |
| 52 | - $wpdb->update($wpdb->prefix . 'wppm_task_comment_meta',$task_log_values,array('id'=>"$comment_meta_id")); | |
| 53 | -}else{ | |
| 54 | - $wpdb->insert($wpdb->prefix . 'wppm_task_comment_meta',$task_log_values); | |
| 55 | - | |
| 56 | -} | |
| 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_set_delete_thread', '_ajax_nonce', false ) != 1 ) { | |
| 8 | + wp_send_json_error( 'Unauthorised request!', 401 ); | |
| 9 | +} | |
| 10 | +$task_id = isset($_POST['task_id']) ? intval(sanitize_text_field(wp_unslash($_POST['task_id']))) : 0 ; | |
| 11 | +$thread_id = isset($_POST['comment_id']) ? intval(sanitize_text_field(wp_unslash($_POST['comment_id']))) : 0 ; | |
| 12 | +$task_comment = $wppmfunction->get_task_comment($thread_id); | |
| 13 | +if (!(($current_user->ID && $current_user->has_cap('manage_options')) || $wppmfunction->has_comment_permission('delete_task_thread',$task_id,$thread_id))) {exit;} | |
| 14 | +$thread_id = absint($thread_id); | |
| 15 | +$task_id = absint($task_id); | |
| 16 | +$sql=$wpdb->prepare("SELECT attachment_ids FROM {$wpdb->prefix}wppm_task_comment WHERE id = %d",$thread_id); | |
| 17 | +$thread_attachment_ids = $wpdb->get_results( $sql ); | |
| 18 | +if(!empty($thread_attachment_ids) ){ | |
| 19 | + foreach ($thread_attachment_ids as $thread_attachment_id){ | |
| 20 | + $attachment_ids_temp=array(); | |
| 21 | + if($thread_attachment_id->attachment_ids){ | |
| 22 | + $attachment_ids_temp = explode(',', $thread_attachment_id->attachment_ids); | |
| 23 | + } | |
| 24 | + $attachment_ids=$attachment_ids_temp; | |
| 25 | + if(!empty($attachment_ids_temp)){ | |
| 26 | + foreach ($attachment_ids_temp as $attachment_id){ | |
| 27 | + $attachment_id = absint($attachment_id); | |
| 28 | + $sql=$wpdb->prepare("SELECT * FROM {$wpdb->prefix}wppm_attachments WHERE id = %d",$attachment_id); | |
| 29 | + $result=$wpdb->get_row($sql); | |
| 30 | + if(!empty($result)){ | |
| 31 | + $sql_query=$wpdb->prepare("SELECT file_path FROM {$wpdb->prefix}wppm_attachments WHERE file_path = %s",$result->file_path); | |
| 32 | + $attach_result=$wpdb->get_results($sql_query); | |
| 33 | + $result_count = count($attach_result); | |
| 34 | + if(file_exists($result->file_path) && $result_count < 2) | |
| 35 | + { | |
| 36 | + wp_delete_file($result->file_path); | |
| 37 | + } | |
| 38 | + $wpdb->delete($wpdb->prefix.'wppm_attachments', array( 'id' => $attachment_id)); | |
| 39 | + } | |
| 40 | + } | |
| 41 | + } | |
| 42 | + } | |
| 43 | +} | |
| 44 | +$cur_user = get_userdata($current_user->ID); | |
| 45 | +$cur_user_display_name = $cur_user->display_name; | |
| 46 | +$log_values = array('task_id'=>"$task_id",'body'=>'This comment was deleted by '.$cur_user_display_name,'attachment_ids'=>"" ); | |
| 47 | +$wpdb->update($wpdb->prefix.'wppm_task_comment', $log_values, array('id'=>"$thread_id")); | |
| 48 | +$task_log_values = array('task_id'=>"$task_id",'comment_id'=>"$thread_id",'comment_type'=>'delete_task_comment'); | |
| 49 | +$comment_meta = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->prefix}wppm_task_comment_meta WHERE comment_id = %d",$thread_id)); | |
| 50 | +if(!empty($comment_meta)){ | |
| 51 | + $comment_meta_id = absint($comment_meta->id); | |
| 52 | + $wpdb->update($wpdb->prefix . 'wppm_task_comment_meta',$task_log_values,array('id'=>"$comment_meta_id")); | |
| 53 | +}else{ | |
| 54 | + $wpdb->insert($wpdb->prefix . 'wppm_task_comment_meta',$task_log_values); | |
| 55 | + | |
| 56 | +} | |
| 57 | 57 | ?> |