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