PluginProbe
Elementor Website Builder – more than just a page builder / 3.0.3
Elementor Website Builder – more than just a page builder v3.0.3
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 4.0.7 All 451 releases
← All changes | includes/db.php +54 -115 4.2.0-dev23.0.3 View file →
@@ -1,10 +1,8 @@
1 1 <?php
2 2 namespace Elementor;
3 3
4 -use Elementor\Core\Base\Document;
5 4 use Elementor\Core\DynamicTags\Manager;
6 -use Elementor\TemplateLibrary\Source_Local;
7 5
8 6 if ( ! defined( 'ABSPATH' ) ) {
9 7 exit; // Exit if accessed directly.
10 8 }
@@ -25,40 +23,30 @@
25 23 const DB_VERSION = '0.4';
26 24
27 25 /**
28 26 * Post publish status.
29 - *
30 - * @deprecated 3.1.0 Use `Document::STATUS_PUBLISH` const instead.
31 27 */
32 - const STATUS_PUBLISH = Document::STATUS_PUBLISH;
28 + const STATUS_PUBLISH = 'publish';
33 29
34 30 /**
35 31 * Post draft status.
36 - *
37 - * @deprecated 3.1.0 Use `Document::STATUS_DRAFT` const instead.
38 32 */
39 - const STATUS_DRAFT = Document::STATUS_DRAFT;
33 + const STATUS_DRAFT = 'draft';
40 34
41 35 /**
42 36 * Post private status.
43 - *
44 - * @deprecated 3.1.0 Use `Document::STATUS_PRIVATE` const instead.
45 37 */
46 - const STATUS_PRIVATE = Document::STATUS_PRIVATE;
38 + const STATUS_PRIVATE = 'private';
47 39
48 40 /**
49 41 * Post autosave status.
50 - *
51 - * @deprecated 3.1.0 Use `Document::STATUS_AUTOSAVE` const instead.
52 42 */
53 - const STATUS_AUTOSAVE = Document::STATUS_AUTOSAVE;
43 + const STATUS_AUTOSAVE = 'autosave';
54 44
55 45 /**
56 46 * Post pending status.
57 - *
58 - * @deprecated 3.1.0 Use `Document::STATUS_PENDING` const instead.
59 47 */
60 - const STATUS_PENDING = Document::STATUS_PENDING;
48 + const STATUS_PENDING = 'pending';
61 49
62 50 /**
63 51 * Switched post data.
64 52 *
@@ -88,27 +76,18 @@
88 76 *
89 77 * Retrieve editor data from the database.
90 78 *
91 79 * @since 1.0.0
92 - * @deprecated 3.1.0 Use `Plugin::$instance->documents->get( $post_id )->get_elements_raw_data( null, true )` OR `Plugin::$instance->documents->get_doc_or_auto_save( $post_id )->get_elements_raw_data( null, true )` instead.
80 + *
93 81 * @access public
94 82 *
95 - * @param int $post_id Post ID.
96 - * @param string $status Optional. Post status. Default is `publish`.
83 + * @param int $post_id Post ID.
84 + * @param string $status Optional. Post status. Default is `publish`.
97 85 *
98 86 * @return array Editor data.
99 87 */
100 - public function get_builder( $post_id, $status = Document::STATUS_PUBLISH ) {
101 - Plugin::$instance->modules_manager
102 - ->get_modules( 'dev-tools' )
103 - ->deprecation
104 - ->deprecated_function(
105 - __METHOD__,
106 - '3.1.0',
107 - '`Plugin::$instance->documents->get( $post_id )->get_elements_raw_data( null, true )` OR `Plugin::$instance->documents->get_doc_or_auto_save( $post_id )->get_elements_raw_data( null, true )`'
108 - );
109 -
110 - if ( Document::STATUS_DRAFT === $status ) {
88 + public function get_builder( $post_id, $status = self::STATUS_PUBLISH ) {
89 + if ( self::STATUS_DRAFT === $status ) {
111 90 $document = Plugin::$instance->documents->get_doc_or_auto_save( $post_id );
112 91 } else {
113 92 $document = Plugin::$instance->documents->get( $post_id );
114 93 }
@@ -135,10 +114,8 @@
135 114 *
136 115 * @return array Decoded JSON data from post meta.
137 116 */
138 117 protected function _get_json_meta( $post_id, $key ) {
139 - Plugin::$instance->modules_manager->get_modules( 'dev-tools' )->deprecation->deprecated_function( __METHOD__, '3.1.0' );
140 -
141 118 $meta = get_post_meta( $post_id, $key, true );
142 119
143 120 if ( is_string( $meta ) && ! empty( $meta ) ) {
144 121 $meta = json_decode( $meta, true );
@@ -151,14 +128,39 @@
151 128 return $meta;
152 129 }
153 130
154 131 /**
132 + * Get new editor from WordPress editor.
133 + *
134 + * When editing the with Elementor the first time, the current page content
135 + * is parsed into Text Editor Widget that contains the original data.
136 + *
137 + * @since 2.1.0
138 + * @deprecated 2.3.0 Use `Plugin::$instance->documents->get( $post_id )->convert_to_elementor()` instead
139 + * @access public
140 + *
141 + * @param int $post_id Post ID.
142 + *
143 + * @return array Content in Elementor format.
144 + */
145 + public function get_new_editor_from_wp_editor( $post_id ) {
146 + _deprecated_function( __METHOD__, '2.3.0', 'Plugin::$instance->documents->get( $post_id )->convert_to_elementor()' );
147 +
148 + $document = Plugin::$instance->documents->get( $post_id );
149 +
150 + if ( $document ) {
151 + return $document->convert_to_elementor();
152 + }
153 +
154 + return [];
155 + }
156 +
157 + /**
155 158 * Is using Elementor.
156 159 *
157 160 * Set whether the page is using Elementor or not.
158 161 *
159 162 * @since 1.5.0
160 - * @deprecated 3.1.0 Use `Plugin::$instance->documents->get( $post_id )->set_is_build_with_elementor( $is_elementor )` instead.
161 163 * @access public
162 164 *
163 165 * @param int $post_id Post ID.
164 166 * @param bool $is_elementor Optional. Whether the page is elementor page.
@@ -164,24 +166,14 @@
164 166 * @param bool $is_elementor Optional. Whether the page is elementor page.
165 167 * Default is true.
166 168 */
167 169 public function set_is_elementor_page( $post_id, $is_elementor = true ) {
168 - Plugin::$instance->modules_manager
169 - ->get_modules( 'dev-tools' )
170 - ->deprecation
171 - ->deprecated_function(
172 - __METHOD__,
173 - '3.1.0',
174 - 'Plugin::$instance->documents->get( $post_id )->set_is_build_with_elementor( $is_elementor )'
175 - );
176 -
177 - $document = Plugin::$instance->documents->get( $post_id );
178 -
179 - if ( ! $document ) {
180 - return;
170 + if ( $is_elementor ) {
171 + // Use the string `builder` and not a boolean for rollback compatibility
172 + update_post_meta( $post_id, '_elementor_edit_mode', 'builder' );
173 + } else {
174 + delete_post_meta( $post_id, '_elementor_edit_mode' );
181 175 }
182 -
183 - $document->set_is_built_with_elementor( $is_elementor );
184 176 }
185 177
186 178 /**
187 179 * Render element plain content.
@@ -251,9 +243,9 @@
251 243 * @access public
252 244 *
253 245 * @param array $data_container Any type of elementor data.
254 246 * @param callable $callback A function to iterate data by.
255 - * @param array $args Array of args pointers for passing parameters in & out of the callback.
247 + * @param array $args Array of args pointers for passing parameters in & out of the callback
256 248 *
257 249 * @return mixed Iterated data.
258 250 */
259 251 public function iterate_data( $data_container, $callback, $args = [] ) {
@@ -277,39 +269,8 @@
277 269
278 270 return $data_container;
279 271 }
280 272
281 - public static function iterate_elementor_documents( $callback, $batch_size = 100, $additional_post_types = [] ) {
282 - $processed_posts = 0;
283 -
284 - while ( true ) {
285 - $args = wp_parse_args( [
286 - 'post_type' => array_merge( [ Source_Local::CPT, 'post', 'page' ], $additional_post_types ),
287 - 'post_status' => [ 'publish' ],
288 - 'posts_per_page' => $batch_size,
289 - 'meta_key' => Document::BUILT_WITH_ELEMENTOR_META_KEY,
290 - 'meta_value' => 'builder',
291 - 'offset' => $processed_posts,
292 - 'fields' => 'ids',
293 - ] );
294 -
295 - $query = new \WP_Query( $args );
296 -
297 - if ( empty( $query->posts ) ) {
298 - break;
299 - }
300 -
301 - foreach ( $query->posts as $post_id ) {
302 - $document = Plugin::$instance->documents->get( $post_id );
303 - $elements_data = $document->get_json_meta( Document::ELEMENTOR_DATA_META_KEY );
304 -
305 - $callback( $document, $elements_data );
306 -
307 - ++$processed_posts;
308 - }
309 - }
310 - }
311 -
312 273 /**
313 274 * Safely copy Elementor meta.
314 275 *
315 276 * Make sure the original page was built with Elementor and the post is not
@@ -324,15 +285,14 @@
324 285 */
325 286 public function safe_copy_elementor_meta( $from_post_id, $to_post_id ) {
326 287 // It's from WP-Admin & not from Elementor.
327 288 if ( ! did_action( 'elementor/db/before_save' ) ) {
328 - $from_document = Plugin::$instance->documents->get( $from_post_id );
329 289
330 - if ( ! $from_document || ! $from_document->is_built_with_elementor() ) {
290 + if ( ! Plugin::$instance->db->is_built_with_elementor( $from_post_id ) ) {
331 291 return;
332 292 }
333 293
334 - // It's an exited Elementor auto-save.
294 + // It's an exited Elementor auto-save
335 295 if ( get_post_meta( $to_post_id, '_elementor_data', true ) ) {
336 296 return;
337 297 }
338 298 }
@@ -349,13 +309,12 @@
349 309 *
350 310 * @since 1.1.0
351 311 * @access public
352 312 *
353 - * @param int $from_post_id Original post ID.
354 - * @param int $to_post_id Target post ID.
355 - * @param ?array $specific_meta_keys Optional. Specific meta keys to copy. Default is null, which copies all elementor meta keys.
313 + * @param int $from_post_id Original post ID.
314 + * @param int $to_post_id Target post ID.
356 315 */
357 - public function copy_elementor_meta( $from_post_id, $to_post_id, $specific_meta_keys = null ) {
316 + public function copy_elementor_meta( $from_post_id, $to_post_id ) {
358 317 $from_post_meta = get_post_meta( $from_post_id );
359 318 $core_meta = [
360 319 '_wp_page_template',
361 320 '_thumbnail_id',
@@ -361,17 +320,13 @@
361 320 '_thumbnail_id',
362 321 ];
363 322
364 323 foreach ( $from_post_meta as $meta_key => $values ) {
365 - if ( $specific_meta_keys && ! in_array( $meta_key, $specific_meta_keys, true ) ) {
366 - continue;
367 - }
368 -
369 - // Copy only meta with the `_elementor` prefix.
324 + // Copy only meta with the `_elementor` prefix
370 325 if ( 0 === strpos( $meta_key, '_elementor' ) || in_array( $meta_key, $core_meta, true ) ) {
371 326 $value = $values[0];
372 327
373 - // The elementor JSON needs slashes before saving.
328 + // The elementor JSON needs slashes before saving
374 329 if ( '_elementor_data' === $meta_key ) {
375 330 $value = wp_slash( $value );
376 331 } else {
377 332 $value = maybe_unserialize( $value );
@@ -376,9 +331,9 @@
376 331 } else {
377 332 $value = maybe_unserialize( $value );
378 333 }
379 334
380 - // Don't use `update_post_meta` that can't handle `revision` post type.
335 + // Don't use `update_post_meta` that can't handle `revision` post type
381 336 update_metadata( 'post', $to_post_id, $meta_key, $value );
382 337 }
383 338 }
384 339 }
@@ -388,9 +343,8 @@
388 343 *
389 344 * Check whether the post was built with Elementor.
390 345 *
391 346 * @since 1.0.10
392 - * @deprecated 3.2.0 Use `Plugin::$instance->documents->get( $post_id )->is_built_with_elementor()` instead.
393 347 * @access public
394 348 *
395 349 * @param int $post_id Post ID.
396 350 *
@@ -396,24 +350,9 @@
396 350 *
397 351 * @return bool Whether the post was built with Elementor.
398 352 */
399 353 public function is_built_with_elementor( $post_id ) {
400 - Plugin::$instance->modules_manager
401 - ->get_modules( 'dev-tools' )
402 - ->deprecation
403 - ->deprecated_function(
404 - __METHOD__,
405 - '3.2.0',
406 - 'Plugin::$instance->documents->get( $post_id )->is_built_with_elementor()'
407 - );
408 -
409 - $document = Plugin::$instance->documents->get( $post_id );
410 -
411 - if ( ! $document ) {
412 - return false;
413 - }
414 -
415 - return $document->is_built_with_elementor();
354 + return ! ! get_post_meta( $post_id, '_elementor_edit_mode', true );
416 355 }
417 356
418 357 /**
419 358 * Switch to post.
@@ -434,9 +373,9 @@
434 373 }
435 374
436 375 $this->switched_post_data[] = [
437 376 'switched_id' => $post_id,
438 - 'original_id' => get_the_ID(), // Note, it can be false if the global isn't set.
377 + 'original_id' => get_the_ID(), // Note, it can be false if the global isn't set
439 378 ];
440 379
441 380 $GLOBALS['post'] = get_post( $post_id ); // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
442 381
@@ -458,9 +397,9 @@
458 397 if ( ! $data ) {
459 398 return;
460 399 }
461 400
462 - // It was switched from an empty global post, restore this state and unset the global post.
401 + // It was switched from an empty global post, restore this state and unset the global post
463 402 if ( false === $data['original_id'] ) {
464 403 unset( $GLOBALS['post'] );
465 404 return;
466 405 }
@@ -507,9 +446,9 @@
507 446 $this->switched_data[] = $switched_data;
508 447
509 448 $wp_query = $new_query; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
510 449
511 - // Ensure the global post is set only if needed.
450 + // Ensure the global post is set only if needed
512 451 unset( $GLOBALS['post'] );
513 452
514 453 if ( isset( $new_query->posts[0] ) ) {
515 454 if ( $force_global_post || $new_query->is_singular() ) {