PluginProbe
Elementor Website Builder – more than just a page builder / 3.35.0-dev2
Elementor Website Builder – more than just a page builder v3.35.0-dev2
4.3.0-beta3 4.3.0-beta2 4.3.0-beta1 4.2.4 4.2.3 4.2.2 4.2.1 4.2.0 4.1.5 4.2.0-beta2 4.2.0-dev2 4.2.0-beta1 4.1.4 4.1.3 4.1.2 4.1.1 4.1.0 4.1.0-beta3 4.1.0-dev3 4.0.9 4.1.0-beta2 4.1.0-dev2 4.0.8 4.1.0-beta1 4.1.0-dev1 All 452 releases
elementor / app / modules / import-export / runners / revert / wp-content.php

wp-content.php in Elementor Website Builder – more than just a page builder 3.35.0-dev2, at app/modules/import-export/runners/revert/wp-content.php

74 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Elementor\App\Modules\ImportExport\Runners\Revert;
4
5 use Elementor\App\Modules\ImportExport\Utils as ImportExportUtils;
6
7 class Wp_Content extends Revert_Runner_Base {
8
9 public static function get_name(): string {
10 return 'wp-content';
11 }
12
13 public function should_revert( array $data ): bool {
14 return (
15 isset( $data['runners'] ) &&
16 array_key_exists( static::get_name(), $data['runners'] )
17 );
18 }
19
20 public function revert( array $data ) {
21 $builtin_post_types = ImportExportUtils::get_builtin_wp_post_types();
22 $custom_post_types = $data['runners']['wp-content']['custom_post_types'] ?? [];
23
24 $post_types = array_merge( $builtin_post_types, $custom_post_types );
25
26 $query_args = [
27 'post_type' => $post_types,
28 'post_status' => 'any',
29 'posts_per_page' => -1,
30 'meta_query' => [
31 [
32 'key' => static::META_KEY_ELEMENTOR_EDIT_MODE,
33 'compare' => 'NOT EXISTS',
34 ],
35 [
36 'key' => static::META_KEY_ELEMENTOR_IMPORT_SESSION_ID,
37 'value' => $data['session_id'],
38 ],
39 ],
40 ];
41
42 $query = new \WP_Query( $query_args );
43
44 foreach ( $query->posts as $post ) {
45 wp_delete_post( $post->ID, true );
46 }
47
48 /**
49 * Revert the nav menu terms.
50 * BC: The nav menu in new kits will be imported as part of the taxonomies, but old kits
51 * importing the nav menu terms as part from the wp-content import.
52 */
53 $this->revert_nav_menus( $data );
54 }
55
56 private function revert_nav_menus( array $data ) {
57 $terms = get_terms( [
58 'taxonomy' => 'nav_menu',
59 'hide_empty' => false,
60 'get' => 'all',
61 'meta_query' => [
62 [
63 'key' => static::META_KEY_ELEMENTOR_IMPORT_SESSION_ID,
64 'value' => $data['session_id'],
65 ],
66 ],
67 ] );
68
69 foreach ( $terms as $term ) {
70 wp_delete_term( $term->term_id, $term->taxonomy );
71 }
72 }
73 }
74