| 1 |
<?php |
| 2 |
|
| 3 |
namespace Elementor\App\Modules\ImportExport\Runners\Export; |
| 4 |
|
| 5 |
use Elementor\Core\Base\Document; |
| 6 |
use Elementor\Plugin; |
| 7 |
use Elementor\TemplateLibrary\Source_Local; |
| 8 |
use Elementor\Utils; |
| 9 |
|
| 10 |
class Templates extends Export_Runner_Base { |
| 11 |
|
| 12 |
public static function get_name() : string { |
| 13 |
return 'templates'; |
| 14 |
} |
| 15 |
|
| 16 |
public function should_export( array $data ) { |
| 17 |
return ( |
| 18 |
Utils::has_pro() && |
| 19 |
isset( $data['include'] ) && |
| 20 |
in_array( 'templates', $data['include'], true ) |
| 21 |
); |
| 22 |
} |
| 23 |
|
| 24 |
public function export( array $data ) { |
| 25 |
$template_types = array_values( Source_Local::get_template_types() ); |
| 26 |
|
| 27 |
$query_args = [ |
| 28 |
'post_type' => Source_Local::CPT, |
| 29 |
'post_status' => 'publish', |
| 30 |
'posts_per_page' => -1, |
| 31 |
'meta_query' => [ |
| 32 |
[ |
| 33 |
'key' => Document::TYPE_META_KEY, |
| 34 |
'value' => $template_types, |
| 35 |
], |
| 36 |
], |
| 37 |
]; |
| 38 |
|
| 39 |
$templates_query = new \WP_Query( $query_args ); |
| 40 |
|
| 41 |
$templates_manifest_data = []; |
| 42 |
$files = []; |
| 43 |
|
| 44 |
foreach ( $templates_query->posts as $template_post ) { |
| 45 |
$template_id = $template_post->ID; |
| 46 |
|
| 47 |
$template_document = Plugin::$instance->documents->get( $template_id ); |
| 48 |
|
| 49 |
$templates_manifest_data[ $template_id ] = $template_document->get_export_summary(); |
| 50 |
|
| 51 |
$files[] = [ |
| 52 |
'path' => 'templates/' . $template_id, |
| 53 |
'data' => $template_document->get_export_data(), |
| 54 |
]; |
| 55 |
} |
| 56 |
|
| 57 |
$manifest_data['templates'] = $templates_manifest_data; |
| 58 |
|
| 59 |
return [ |
| 60 |
'files' => $files, |
| 61 |
'manifest' => [ |
| 62 |
$manifest_data, |
| 63 |
], |
| 64 |
]; |
| 65 |
} |
| 66 |
} |
| 67 |
|