add_attachment.php
1 month ago
admin_head.php
1 month ago
admin_init.php
1 month ago
admin_menu.php
1 month ago
admin_notices.php
1 month ago
attachment_updated.php
1 month ago
delete_post.php
1 month ago
pmxi_after_xml_import.php
1 month ago
pmxi_before_xml_import.php
1 month ago
pmxi_extend_options_custom_fields.php
1 month ago
wp_ajax_auto_detect_cf.php
1 month ago
wp_ajax_auto_detect_sf.php
1 month ago
wp_ajax_delete_import.php
1 month ago
wp_ajax_dismiss_notifications.php
1 month ago
wp_ajax_import_failed.php
1 month ago
wp_ajax_test_images.php
1 month ago
wp_ajax_wpai_dismiss_review_modal.php
1 month ago
wp_ajax_wpai_send_feedback.php
1 month ago
wpmu_new_blog.php
1 month ago
wp_ajax_delete_import.php
95 lines
| 1 | <?php |
| 2 | if ( ! defined( 'ABSPATH' ) ) exit; |
| 3 | function pmxi_wp_ajax_delete_import(){ |
| 4 | |
| 5 | if ( ! check_ajax_referer( 'wp_all_import_secure', 'security', false )){ |
| 6 | exit( json_encode(array('result' => false, 'msg' => __('Security check', 'wp-all-import'))) ); |
| 7 | } |
| 8 | |
| 9 | if ( ! current_user_can( PMXI_Plugin::$capabilities ) ){ |
| 10 | exit( json_encode(array('result' => false, 'msg' => __('Security check', 'wp-all-import'))) ); |
| 11 | } |
| 12 | |
| 13 | $input = new PMXI_Input(); |
| 14 | |
| 15 | $post = $input->post(array( |
| 16 | 'data' => '', |
| 17 | 'iteration' => 1 |
| 18 | )); |
| 19 | |
| 20 | $params = array(); |
| 21 | parse_str($post['data'], $params); |
| 22 | |
| 23 | $response = array( |
| 24 | 'result' => false, |
| 25 | 'msg' => '' |
| 26 | ); |
| 27 | |
| 28 | $get_import_id = $params['import_ids'][0]; |
| 29 | |
| 30 | $import = new PMXI_Import_Record(); |
| 31 | $import->getById($get_import_id); |
| 32 | |
| 33 | if ( ! $import->isEmpty() ) |
| 34 | { |
| 35 | if (!empty($import['options']['custom_type'])){ |
| 36 | switch ($import['options']['custom_type']){ |
| 37 | |
| 38 | case 'import_users': |
| 39 | $custom_type = new stdClass(); |
| 40 | $custom_type->label = __('Users', 'wp-all-import'); |
| 41 | break; |
| 42 | case 'shop_customer': |
| 43 | $custom_type = new stdClass(); |
| 44 | $custom_type->label = __('Customers', 'wp-all-import'); |
| 45 | break; |
| 46 | default: |
| 47 | $custom_type = get_post_type_object( $import['options']['custom_type'] ); |
| 48 | break; |
| 49 | } |
| 50 | $cpt_name = ( ! empty($custom_type)) ? strtolower($custom_type->label) : ''; |
| 51 | } else { |
| 52 | $cpt_name = ''; |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | if ( $params['is_delete_import'] and ! $params['is_delete_posts'] ) { |
| 57 | $response['redirect'] = esc_url_raw(add_query_arg('pmxi_nt', urlencode(__('Import deleted', 'wp-all-import')), $params['base_url'])); |
| 58 | } elseif( ! $params['is_delete_import'] and $params['is_delete_posts']) { |
| 59 | /* translators: see placeholders in the string below */ |
| 60 | $response['redirect'] = esc_url_raw(add_query_arg('pmxi_nt', urlencode(sprintf(__('All associated %s deleted.', 'wp-all-import'), $cpt_name)), $params['base_url'])); |
| 61 | } elseif( $params['is_delete_import'] and $params['is_delete_posts']) { |
| 62 | /* translators: see placeholders in the string below */ |
| 63 | $response['redirect'] = esc_url_raw(add_query_arg('pmxi_nt', urlencode(sprintf(__('Import and all associated %s deleted.', 'wp-all-import'), $cpt_name)), $params['base_url'])); |
| 64 | } else { |
| 65 | $response['redirect'] = esc_url_raw(add_query_arg('pmxi_nt', urlencode(__('Nothing to delete.', 'wp-all-import')), $params['base_url'])); |
| 66 | exit( json_encode( $response )); |
| 67 | } |
| 68 | |
| 69 | if ( ! empty($params['import_ids'])) { |
| 70 | foreach ($params['import_ids'] as $key => $id) { |
| 71 | $import = new PMXI_Import_Record(); |
| 72 | $import->getById($id); |
| 73 | if ( ! $import->isEmpty() ) { |
| 74 | if ((int) $post['iteration'] === 1) { |
| 75 | $import->set(array( |
| 76 | 'deleted' => 0 |
| 77 | ))->update(); |
| 78 | } |
| 79 | |
| 80 | $is_all_records_deleted = $import->deletePostsAjax( ! $params['is_delete_posts'], $params['is_delete_images'], $params['is_delete_attachments'] ); |
| 81 | |
| 82 | $response['result'] = (empty($params['import_ids'][$key + 1])) ? $is_all_records_deleted : false; |
| 83 | /* translators: see placeholders in the string below */ |
| 84 | $response['msg'] = sprintf(__('Import #%1$d - %2$d records deleted', 'wp-all-import'), intval($import->id), intval($import->deleted)); |
| 85 | |
| 86 | if ( $is_all_records_deleted === true ) |
| 87 | { |
| 88 | $import->delete( ! $params['is_delete_posts'], $params['is_delete_images'], $params['is_delete_attachments'], $params['is_delete_import'] ); |
| 89 | } |
| 90 | } |
| 91 | } |
| 92 | } |
| 93 | |
| 94 | exit( json_encode( $response )); |
| 95 | } |