PluginProbe ʕ •ᴥ•ʔ
Kubio AI Page Builder / 2.6.3
Kubio AI Page Builder v2.6.3
2.8.4 2.8.3 2.8.2 2.8.1 trunk 1.0.0 1.0.1 1.1.0 1.2.0 1.2.1 1.2.2 1.2.3 1.3.0 1.3.1 1.3.2 1.4.0 1.4.1 1.4.2 1.4.3 1.5.0 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.7.0 1.7.1 1.7.2 1.7.3 1.8.0 1.8.1 1.8.2 1.9.0 2.0.0 2.1.1 2.1.2 2.1.3 2.2.0 2.2.3 2.2.4 2.2.5 2.3.0 2.3.1 2.3.3 2.3.4 2.4.0 2.4.1 2.4.2 2.4.3 2.4.5 2.5.0 2.5.1 2.5.2 2.5.3 2.6.0 2.6.1 2.6.2 2.6.3 2.6.5 2.6.6 2.6.7 2.7.0 2.7.1 2.7.2 2.7.3 2.8.0
kubio / lib / filters / wp-import.php
kubio / lib / filters Last commit date
after-kubio-activation.php 1 year ago allow-kubio-blog-override.php 2 years ago cache-plugins.php 4 years ago default-editor-overlay.php 1 year ago dismissable-notice.php 1 year ago gutenerg-plugin-check.php 1 year ago image-size-auto-fix.php 1 year ago kubio-fresh-site.php 2 years ago post-insert.php 11 months ago register-meta-fields.php 3 years ago requirements-notices.php 1 year ago site-urls.php 1 year ago starter-sites-feature.php 1 year ago svg-kses.php 1 year ago wp-import.php 1 year ago
wp-import.php
250 lines
1 <?php
2
3 namespace Kubio;
4
5 use IlluminateAgnostic\Arr\Support\Arr;
6 use Kubio\Core\Importer;
7 use Kubio\Core\Utils;
8
9 class WPImportFilters {
10
11 private $supported_theme = array( 'elevate-wp', 'pathway', 'kubio', 'pixy' );
12 private $global_data_processed = false;
13 private $fresh_site = false;
14
15 private $handled_by_kubio = array();
16
17 private function __construct() {
18 $this->fresh_site = kubio_is_fresh_site();
19
20 add_action( 'import_end', array( $this, 'handleKubioImports' ) );
21 add_action( 'wp_get_object_terms', array( $this, 'addExtraTermsToExport' ) );
22 add_filter( 'wp_import_posts', array( $this, 'filterImportedPosts' ), 5 );
23 }
24
25 public function addExtraTermsToExport( $terms ) {
26 if ( defined( 'WXR_VERSION' ) ) {
27 // exclude if active theme is not kubio compatible
28 if ( ! kubio_theme_has_kubio_block_support() ) {
29 return $terms;
30 }
31
32 $stylesheet = \get_stylesheet();
33 foreach ( $terms as $term ) {
34 if ( $term->taxonomy === 'wp_theme' && $term->name === $stylesheet ) {
35 $terms[] = (object) array(
36 'taxonomy' => '_kubio_suports_rename',
37 'slug' => $stylesheet,
38 'name' => $stylesheet,
39 );
40 break;
41 }
42 }
43 }
44
45 return $terms;
46 }
47
48 public function filterImportedPosts( $posts ) {
49
50 if ( defined( 'KUBIO_IS_STARTER_SITES_IMPORT' ) ) {
51 return $posts;
52 }
53
54 $template = get_stylesheet();
55 $is_supported_theme = kubio_theme_has_kubio_block_support();
56
57 kubio_register_wp_theme_taxonomy( true );
58 kubio_register_wp_template_part_area_taxonomy( true );
59
60 wp_insert_term( $template, 'wp_theme', array( 'slug' => $template ) );
61
62 $this->log( "Theme: {$template}" );
63 $this->log( $this->fresh_site ? 'Fresh site' : 'Not a fresh site' );
64
65 $contains_pages = false;
66 foreach ( $posts as $index => $post ) {
67 $post_type = Arr::get( $post, 'post_type', null );
68
69 switch ( $post_type ) {
70 case 'page':
71 $contains_pages = true;
72 break;
73 case 'wp_template':
74 case 'wp_template_part':
75 $posts[ $index ] = $this->processFSETemplate( $post, $template, $is_supported_theme );
76 break;
77
78 case kubio_global_data_post_type():
79 $posts[ $index ] = $this->processGlobalData( $posts );
80 break;
81 }
82 }
83
84 // remove precreated front and blog page if the site is fresh & the xml file contains pages to reduce pages duplication
85 if ( count( $this->handled_by_kubio ) > 0 && $contains_pages ) {
86 $this->log( 'Cleanup Kubio intial pages' );
87 wp_cache_flush();
88 $page_on_front = intval( get_option( 'page_on_front', 0 ) );
89 $page_for_posts = intval( get_option( 'page_for_posts', 0 ) );
90
91 if ( $page_on_front && intval( get_post_meta( $page_on_front, '_kubio_created_at_activation', true ) ) ) {
92 update_option( 'show_on_front', 'posts' );
93 wp_delete_post( $page_on_front, true );
94 }
95
96 if ( $page_for_posts && intval( get_post_meta( $page_for_posts, '_kubio_created_at_activation', true ) ) ) {
97 wp_delete_post( $page_for_posts, true );
98 }
99 wp_cache_flush();
100 }
101
102 $posts = array_filter( $posts );
103
104 return $posts;
105 }
106
107 private function processFSETemplate( $post, $template, $is_supported_theme ) {
108 $terms = Arr::get( $post, 'terms', array() );
109 $supports_rename = false;
110
111 // remove _kubio_suports_rename temporrary term if exists
112 foreach ( $terms as $term_index => $term ) {
113 $domain = Arr::get( $term, 'domain', null );
114 if ( $domain === '_kubio_suports_rename' ) {
115 $supports_rename = true;
116 unset( $terms[ $term_index ] );
117 break;
118 }
119 }
120
121 if ( ! $is_supported_theme || ! $this->fresh_site ) {
122 $post['terms'] = $terms;
123 return $post;
124 }
125
126 $use_kubio_importer = $supports_rename;
127
128 foreach ( $terms as $term ) {
129 $domain = Arr::get( $term, 'domain', null );
130 if ( $domain === 'wp_theme' ) {
131 $use_kubio_importer = $use_kubio_importer || in_array( $term['slug'], $this->supported_theme, true );
132 break;
133 }
134 }
135
136 if ( $use_kubio_importer ) {
137 $blocks = parse_blocks( $post['post_content'] );
138 $blocks = kubio_blocks_update_template_parts_theme( $blocks, $template );
139 $content = kubio_serialize_blocks( $blocks );
140
141 $this->handled_by_kubio[] = array(
142 'slug' => $post['post_name'],
143 'type' => $post['post_type'],
144 'content' => $content,
145 );
146
147 return false;
148 }
149
150 return $post;
151 }
152
153 private function processGlobalData( $posts ) {
154 if ( $this->global_data_processed || ! $this->fresh_site ) {
155 return false;
156 }
157
158 $global_data_post = null;
159
160 foreach ( $posts as $post ) {
161 $post_type = Arr::get( $post, 'post_type', null );
162 if ( $post_type !== kubio_global_data_post_type() ) {
163 continue;
164 }
165
166 if ( ! $global_data_post ) {
167 $global_data_post = $post;
168 }
169
170 $terms = Arr::get( $post, 'terms', array() );
171
172 $is_theme_global_data = false;
173
174 foreach ( $terms as $term ) {
175 $domain = Arr::get( $term, 'domain', null );
176 if ( $domain === '_kubio_suports_rename' ) {
177 $is_theme_global_data = true;
178 break;
179 }
180 }
181
182 if ( $is_theme_global_data ) {
183 $global_data_post = $post;
184 break;
185 }
186 }
187
188 $this->handled_by_kubio[] = array(
189 'slug' => kubio_global_data_post_type(),
190 'type' => kubio_global_data_post_type(),
191 'content' => $global_data_post['post_content'],
192 );
193
194 $this->global_data_processed = true;
195 return false;
196 }
197
198 public function handleKubioImports() {
199
200 $stylesheet = \get_stylesheet();
201
202 if ( Utils::isCLI() ) {
203 add_filter( 'user_has_cap', array( Importer::class, 'allowImportCaps' ), 10, 2 );
204 }
205
206 if ( ! count( $this->handled_by_kubio ) ) {
207 _kubio_remove_fresh_install_flag();
208 return;
209 }
210
211 foreach ( $this->handled_by_kubio as $import ) {
212 $type = $import['type'];
213
214 $this->log( "Import entity: {$type} - {$import['slug']}" );
215
216 switch ( $type ) {
217 case 'wp_template':
218 Importer::createTemplate( $import['slug'], $import['content'], true, 'kubio' );
219 break;
220 case 'wp_template_part':
221 Importer::createTemplatePart( $import['slug'], $import['content'], true, 'kubio' );
222 break;
223 case kubio_global_data_post_type():
224 kubio_replace_global_data_content( $import['content'], $stylesheet );
225 break;
226 }
227 }
228
229 $this->handled_by_kubio = array();
230 }
231
232 public static function load() {
233 new static();
234 }
235
236 private function log( $message ) {
237 if ( defined( 'WP_CLI' ) ) {
238 \WP_CLI::log( "Kubio Imported -- $message" );
239 } else {
240 if ( defined( 'WP_DEBUG' ) ) {
241 printf( '<script>console.log(%s)</script>', wp_json_encode( "Kubio Log: {$message}" ) );
242 }
243 }
244 }
245 }
246
247
248
249 WPImportFilters::load();
250