| 1 |
<?php |
| 2 |
|
| 3 |
namespace Elementor\App\Modules\ImportExportCustomization\Runners\Revert; |
| 4 |
|
| 5 |
use Elementor\Plugin; |
| 6 |
use Elementor\TemplateLibrary\Source_Local; |
| 7 |
use Elementor\Core\Base\Document; |
| 8 |
|
| 9 |
class Templates extends Revert_Runner_Base { |
| 10 |
public static function get_name(): string { |
| 11 |
return 'templates'; |
| 12 |
} |
| 13 |
|
| 14 |
public function should_revert( array $data ): bool { |
| 15 |
return ( |
| 16 |
isset( $data['runners'] ) && |
| 17 |
array_key_exists( static::get_name(), $data['runners'] ) |
| 18 |
); |
| 19 |
} |
| 20 |
|
| 21 |
public function revert( array $data ) { |
| 22 |
$template_types = array_values( Source_Local::get_template_types() ); |
| 23 |
|
| 24 |
$query_args = [ |
| 25 |
'post_type' => Source_Local::CPT, |
| 26 |
'post_status' => 'any', |
| 27 |
'posts_per_page' => -1, |
| 28 |
'meta_query' => [ |
| 29 |
[ |
| 30 |
'key' => Document::TYPE_META_KEY, |
| 31 |
'value' => $template_types, |
| 32 |
], |
| 33 |
[ |
| 34 |
'key' => static::META_KEY_ELEMENTOR_IMPORT_SESSION_ID, |
| 35 |
'value' => $data['session_id'], |
| 36 |
], |
| 37 |
], |
| 38 |
]; |
| 39 |
|
| 40 |
$templates_query = new \WP_Query( $query_args ); |
| 41 |
|
| 42 |
foreach ( $templates_query->posts as $template_post ) { |
| 43 |
$template_document = Plugin::$instance->documents->get( $template_post->ID ); |
| 44 |
$template_document->delete(); |
| 45 |
} |
| 46 |
|
| 47 |
do_action( 'elementor/import-export-customization/revert/templates', $data ); |
| 48 |
} |
| 49 |
} |
| 50 |
|