/var/www/html/wp-content/plugins/elementor/app/modules/import-export/runners/export/templates.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php

namespace Elementor\App\Modules\ImportExport\Runners\Export;

use 
Elementor\Core\Base\Document;
use 
Elementor\Plugin;
use 
Elementor\TemplateLibrary\Source_Local;
use 
Elementor\Utils;

class 
Templates extends Export_Runner_Base {

    public static function 
get_name() : string {
        return 
'templates';
    }

    public function 
should_export( array $data ) {
        return (
            
Utils::has_pro() &&
            isset( 
$data['include'] ) &&
            
in_array'templates'$data['include'], true )
        );
    }

    public function 
export( array $data ) {
        
$template_types array_valuesSource_Local::get_template_types() );

        
$query_args = [
            
'post_type' => Source_Local::CPT,
            
'post_status' => 'publish',
            
'posts_per_page' => -1,
            
'meta_query' => [
                [
                    
'key' => Document::TYPE_META_KEY,
                    
'value' => $template_types,
                ],
            ],
        ];

        
$templates_query = new \WP_Query$query_args );

        
$templates_manifest_data = [];
        
$files = [];

        foreach ( 
$templates_query->posts as $template_post ) {
            
$template_id $template_post->ID;

            
$template_document Plugin::$instance->documents->get$template_id );

            
$templates_manifest_data$template_id ] = $template_document->get_export_summary();

            
$files[] = [
                
'path' => 'templates/' $template_id,
                
'data' => $template_document->get_export_data(),
            ];
        }

        
$manifest_data['templates'] = $templates_manifest_data;

        return [
            
'files' => $files,
            
'manifest' => [
                
$manifest_data,
            ],
        ];
    }
}