/** * Common CSV batch export code to start the batch export step and provide the JSON response. * * @access private * @since 8.5 * * @uses wp_send_json_error() * @uses is_wp_error() * @uses wp_send_json_success() * @uses wp_create_nonce() * @uses self_admin_url() * * @param cnCSV_Batch_Export $export * @param string $type * @param int $step * @param string $nonce */ private static function csvBatchExport($export, $type, $step, $nonce) { if (!$export->can_export()) { wp_send_json_error(array('message' => __('You do not have permission to export data.', 'connections'))); } if (!$export->is_writable) { wp_send_json_error(array('message' => __('Export location or file not writable.', 'connections'))); } $result = $export->process($step); if (is_wp_error($result)) { wp_send_json_error(array('message' => $result->get_error_message())); } $count = $export->getCount(); $exported = $count > $step * $export->limit ? $step * $export->limit : $count; $remaining = 0 < $count - $exported ? $count - $exported : $count; $percentage = $export->getPercentageComplete(); if ($result) { $step += 1; wp_send_json_success(array('step' => $step, 'count' => $count, 'exported' => $exported, 'remaining' => $remaining, 'percentage' => $percentage, 'nonce' => $nonce)); } elseif (TRUE === $export->is_empty) { wp_send_json_error(array('message' => __('No data found for export parameters.', 'connections'))); } else { $args = array('cn-action' => 'download_batch_export', 'type' => $type, 'nonce' => wp_create_nonce('cn-batch-export-download')); $url = add_query_arg($args, self_admin_url()); wp_send_json_success(array('step' => 'completed', 'url' => $url)); } }
/** * Setup the export. * * @access public * @since 8.5.1 */ public function __construct() { @ini_set('memory_limit', apply_filters('cn_csv_import_memory_limit', WP_MAX_MEMORY_LIMIT)); parent::__construct(); $this->initConfig(); }