| 1 |
<?php |
| 2 |
|
| 3 |
namespace HelloPlus\Modules\TemplateParts\Classes\Runners; |
| 4 |
|
| 5 |
if ( ! defined( 'ABSPATH' ) ) { |
| 6 |
exit; // Exit if accessed directly. |
| 7 |
} |
| 8 |
|
| 9 |
use Elementor\App\Modules\ImportExport\Runners\Revert\Revert_Runner_Base; |
| 10 |
use Elementor\Core\Base\Document; |
| 11 |
|
| 12 |
use Elementor\TemplateLibrary\Source_Local; |
| 13 |
use HelloPlus\Includes\Utils; |
| 14 |
|
| 15 |
class Revert extends Revert_Runner_Base { |
| 16 |
|
| 17 |
public static function get_name(): string { |
| 18 |
return 'templates'; |
| 19 |
} |
| 20 |
|
| 21 |
public function should_revert( array $data ): bool { |
| 22 |
return isset( $data['runners'][ static::get_name() ] ); |
| 23 |
} |
| 24 |
|
| 25 |
public function revert( 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' => 'any', |
| 31 |
'posts_per_page' => -1, |
| 32 |
'meta_query' => [ |
| 33 |
[ |
| 34 |
'key' => Document::TYPE_META_KEY, |
| 35 |
'value' => $template_types, |
| 36 |
], |
| 37 |
[ |
| 38 |
'key' => static::META_KEY_ELEMENTOR_IMPORT_SESSION_ID, |
| 39 |
'value' => $data['session_id'], |
| 40 |
], |
| 41 |
], |
| 42 |
]; |
| 43 |
|
| 44 |
$templates_query = new \WP_Query( $query_args ); |
| 45 |
|
| 46 |
foreach ( $templates_query->posts as $template_post ) { |
| 47 |
$template_document = Utils::elementor()->documents->get( $template_post->ID ); |
| 48 |
$template_document->delete(); |
| 49 |
} |
| 50 |
} |
| 51 |
} |
| 52 |
|