public function export_template($item_id)
{
$template_data = $this->get_content($item_id, 'raw');
$template_data = $this->process_export_import_data($template_data, 'on_export');
if (empty($template_data)) {
return new \WP_Error('404', 'The template does not exist');
}
// TODO: More fields to export?
$export_data = ['version' => DB::DB_VERSION, 'title' => get_the_title($item_id), 'type' => get_post_meta($item_id, self::TYPE_META_KEY, true), 'data' => $template_data];
$filename = 'elementor-' . $item_id . '-' . date('Y-m-d') . '.json';
$template_contents = wp_json_encode($export_data);
$filesize = strlen($template_contents);
// Headers to prompt "Save As"
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename=' . $filename);
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . $filesize);
// Clear buffering just in case
@ob_end_clean();
flush();
// Output file contents
echo $template_contents;
die;
}