function cherry_plugin_export_content() { $exclude_files = array('xml', 'json'); /** * Filters folders to exclude from export parser * @var array */ $exclude_folder = apply_filters('cherry_export_exclude_folders', array('woocommerce_uploads', 'wc-logs')); $response = array('what' => 'status', 'action' => 'export_content', 'id' => '1', 'data' => __('Export content done', CHERRY_PLUGIN_DOMAIN)); $response_file = array('what' => 'file', 'action' => 'export_content', 'id' => '2'); $zip_name = UPLOAD_BASE_DIR . '/sample_data.zip'; cherry_plugin_delete_file($zip_name); if (is_dir(UPLOAD_BASE_DIR)) { $file_string = cherry_plugin_scan_dir(UPLOAD_BASE_DIR, $exclude_folder, $exclude_files); } $zip = new PclZip($zip_name); $result = $zip->create($file_string, PCLZIP_OPT_REMOVE_ALL_PATH); //export json $json_file = cherry_plugin_export_json(); if (is_wp_error($json_file)) { $response['data'] = "Error : " . $json_file->get_error_message(); } else { $zip->add($json_file, PCLZIP_OPT_REMOVE_ALL_PATH); cherry_plugin_delete_file($json_file); } //export xml $xml_file = cherry_plugin_export_xml(); if (is_wp_error($xml_file)) { $response['data'] = "Error : " . $xml_file->get_error_message(); } else { $zip->add($xml_file, PCLZIP_OPT_REMOVE_ALL_PATH); cherry_plugin_delete_file($xml_file); } $nonce = wp_create_nonce('cherry_plugin_download_content'); $file_url = add_query_arg(array('action' => 'cherry_plugin_get_export_file', 'file' => $zip_name, '_wpnonce' => $nonce), admin_url('admin-ajax.php')); if ($result == 0) { $response['data'] = "Error : " . $zip->errorInfo(true); } else { $response_file['data'] = $file_url; } $xmlResponse = new WP_Ajax_Response($response); $xmlResponse->add($response_file); $xmlResponse->send(); exit; }
function cherry_plugin_export_content() { $exclude_files = array('xml', 'json'); $exclude_folder = array('woocommerce_uploads'); $response = array('what' => 'status', 'action' => 'export_content', 'id' => '1', 'data' => __('Export content done', CHERRY_PLUGIN_DOMAIN)); $response_file = array('what' => 'file', 'action' => 'export_content', 'id' => '2'); $zip_name = UPLOAD_BASE_DIR . '/sample_data.zip'; cherry_plugin_delete_file($zip_name); if (is_dir(UPLOAD_BASE_DIR)) { $file_string = cherry_plugin_scan_dir(UPLOAD_BASE_DIR, $exclude_folder, $exclude_files); } $zip = new PclZip($zip_name); $result = $zip->create($file_string, PCLZIP_OPT_REMOVE_ALL_PATH); //export json $json_file = cherry_plugin_export_json(); if (is_wp_error($json_file)) { $response['data'] = "Error : " . $json_file->get_error_message(); } else { $zip->add($json_file, PCLZIP_OPT_REMOVE_ALL_PATH); cherry_plugin_delete_file($json_file); } //export xml $xml_file = cherry_plugin_export_xml(); if (is_wp_error($xml_file)) { $response['data'] = "Error : " . $xml_file->get_error_message(); } else { $zip->add($xml_file, PCLZIP_OPT_REMOVE_ALL_PATH); cherry_plugin_delete_file($xml_file); } if ($result == 0) { $response['data'] = "Error : " . $zip->errorInfo(true); } else { $response_file['data'] = $zip_name; } $xmlResponse = new WP_Ajax_Response($response); $xmlResponse->add($response_file); $xmlResponse->send(); exit; }