← All changes
|
includes/admin/tasks/wppm_set_delete_bulk_tasks.php
+26
-73
6.0.0
→
6.0.6
View file →
| @@ -1,74 +1,27 @@ | ||
| 1 | -<?php | |
| 2 | -if ( ! defined( 'ABSPATH' ) ) { | |
| 3 | - exit; // Exit if accessed directly | |
| 4 | -} | |
| 5 | - | |
| 6 | -global $current_user, $wppmfunction ,$wpdb; | |
| 7 | - | |
| 8 | -if ( check_ajax_referer( 'wppm_set_delete_bulk_tasks', '_ajax_nonce', false ) != 1 ) { | |
| 9 | - wp_send_json_error( 'Unauthorised request!', 401 ); | |
| 10 | -} | |
| 11 | -$task_ids = isset( $_POST['task_ids'] ) ? array_filter( array_map( 'intval', explode( ',', sanitize_text_field( wp_unslash( $_POST['task_ids'] ) ) ) ) ) : array(); | |
| 12 | -$wppm_current_user_capability = get_user_meta( $current_user->ID, 'wppm_capability', true ); | |
| 13 | - | |
| 14 | -if ( ! $task_ids ) { | |
| 15 | - wp_send_json_error( 'Missing task ids', 400 ); | |
| 16 | -} | |
| 17 | -if ( ! empty($task_ids) ) { | |
| 18 | - foreach($task_ids as $task_id){ | |
| 19 | - $task_data = $wppmfunction->get_task($task_id); | |
| 20 | - $project_data = $wppmfunction->get_project($task_data['project']); | |
| 21 | - if ((($current_user->ID && $current_user->has_cap('manage_options')) || ($wppmfunction->has_permission('delete_task',$task_id)) || $wppm_current_user_capability == 'wppm_admin'|| $project_data['created_by']==$current_user->ID)) { | |
| 22 | - $task_id = absint( $task_id ); | |
| 23 | - $thread_attachment_ids = $wpdb->get_results( $wpdb->prepare( "SELECT attachment_ids FROM {$wpdb->prefix}wppm_task_comment WHERE task_id = %d", $task_id )); | |
| 24 | - /***************************Code for deleting attachment files****************************************************/ | |
| 25 | - if(!empty($thread_attachment_ids)){ | |
| 26 | - foreach ($thread_attachment_ids as $thread_attachment_id){ | |
| 27 | - $attachment_ids_temp = array(); | |
| 28 | - if($thread_attachment_id->attachment_ids){ | |
| 29 | - $attachment_ids_temp = explode(',', $thread_attachment_id->attachment_ids); | |
| 30 | - } | |
| 31 | - if(!empty($attachment_ids_temp)){ | |
| 32 | - foreach ($attachment_ids_temp as $attachment_id){ | |
| 33 | - $attachment_id = absint( $attachment_id ); | |
| 34 | - $result = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}wppm_attachments WHERE id = %d", $attachment_id)); | |
| 35 | - if(!empty($result)){ | |
| 36 | - $file_path = isset( $result->file_path ) ? sanitize_text_field( $result->file_path ) : ''; | |
| 37 | - $attach_result = $wpdb->get_results( $wpdb->prepare( "SELECT file_path FROM {$wpdb->prefix}wppm_attachments WHERE file_path = %s", $file_path)); | |
| 38 | - $result_count = count($attach_result); | |
| 39 | - if(file_exists($result->file_path) && $result_count < 2) | |
| 40 | - { | |
| 41 | - wp_delete_file($result->file_path); | |
| 42 | - } | |
| 43 | - $wpdb->delete($wpdb->prefix.'wppm_attachments', array( 'id' => esc_sql($attachment_id))); | |
| 44 | - } | |
| 45 | - } | |
| 46 | - } | |
| 47 | - } | |
| 48 | - } | |
| 49 | - /***************************Code for deleting checklists****************************************************/ | |
| 50 | - $task_id = absint( $task_id ); | |
| 51 | - $checklists = $wpdb->get_results( $wpdb->prepare( "SELECT id FROM {$wpdb->prefix}wppm_checklist WHERE task_id = %d", $task_id)); | |
| 52 | - if(!empty($checklists)){ | |
| 53 | - foreach($checklists as $checklist){ | |
| 54 | - $chk_array = (array) $checklist; | |
| 55 | - $checklist_id = isset( $chk_array['id'] ) ? absint( $chk_array['id'] ) : 0; | |
| 56 | - $checklist_items = $wpdb->get_results( $wpdb->prepare( "SELECT id FROM {$wpdb->prefix}wppm_checklist_items WHERE checklist_id = %d", $checklist_id)); | |
| 57 | - if(!empty($checklist_items)){ | |
| 58 | - foreach($checklist_items as $ch_item){ | |
| 59 | - $chk_items_array = (array) $ch_item; | |
| 60 | - $wpdb->delete($wpdb->prefix.'wppm_checklist_items',array('id'=>esc_sql($chk_items_array['id']))); | |
| 61 | - } | |
| 62 | - } | |
| 63 | - $wpdb->delete($wpdb->prefix.'wppm_checklist',array('id'=>esc_sql($chk_array['id']))); | |
| 64 | - } | |
| 65 | - } | |
| 66 | - $wpdb->delete($wpdb->prefix.'wppm_task',array('id'=>esc_sql($task_id))); | |
| 67 | - $wpdb->delete($wpdb->prefix.'wppm_task_meta',array('task_id'=>esc_sql($task_id))); | |
| 68 | - $wpdb->delete($wpdb->prefix.'wppm_task_comment',array('task_id'=>esc_sql($task_id))); | |
| 69 | - $wpdb->delete($wpdb->prefix.'wppm_task_comment_meta',array('task_id'=>esc_sql($task_id))); | |
| 70 | - do_action('wppm_after_delete_task',$task_id); | |
| 71 | - } | |
| 72 | - } | |
| 73 | -} | |
| 1 | +<?php | |
| 2 | +if ( ! defined( 'ABSPATH' ) ) { | |
| 3 | + exit; // Exit if accessed directly | |
| 4 | +} | |
| 5 | + | |
| 6 | +global $current_user, $wppmfunction ,$wpdb; | |
| 7 | + | |
| 8 | +if ( check_ajax_referer( 'wppm_set_delete_bulk_tasks', '_ajax_nonce', false ) != 1 ) { | |
| 9 | + wp_send_json_error( 'Unauthorised request!', 401 ); | |
| 10 | +} | |
| 11 | +$task_ids = isset( $_POST['task_ids'] ) ? array_filter( array_map( 'intval', explode( ',', sanitize_text_field( wp_unslash( $_POST['task_ids'] ) ) ) ) ) : array(); | |
| 12 | +$wppm_current_user_capability = get_user_meta( $current_user->ID, 'wppm_capability', true ); | |
| 13 | + | |
| 14 | +if ( ! $task_ids ) { | |
| 15 | + wp_send_json_error( 'Missing task ids', 400 ); | |
| 16 | +} | |
| 17 | +if ( ! empty($task_ids) ) { | |
| 18 | + foreach($task_ids as $task_id){ | |
| 19 | + $task_data = $wppmfunction->get_task($task_id); | |
| 20 | + $project_data = $wppmfunction->get_project($task_data['project']); | |
| 21 | + if ((($current_user->ID && $current_user->has_cap('manage_options')) || ($wppmfunction->has_permission('delete_task',$task_id)) || $wppm_current_user_capability == 'wppm_admin'|| $project_data['created_by']==$current_user->ID)) { | |
| 22 | + // Deletes the task's own attachments/checklists/comments, and cascades to any subtasks. | |
| 23 | + WPPM_Functions::delete_task_and_children($task_id); | |
| 24 | + } | |
| 25 | + } | |
| 26 | +} | |
| 74 | 27 | do_action('wppm_after_bulk_delete_all_tasks',$task_ids); |