| 1 |
<?php |
| 2 |
namespace Elementor\Core\Upgrade; |
| 3 |
|
| 4 |
use Elementor\Api; |
| 5 |
use Elementor\Core\Breakpoints\Manager as Breakpoints_Manager; |
| 6 |
use Elementor\Core\Experiments\Manager as Experiments_Manager; |
| 7 |
use Elementor\Core\Schemes\Base; |
| 8 |
use Elementor\Core\Settings\Manager as SettingsManager; |
| 9 |
use Elementor\Core\Settings\Page\Manager as SettingsPageManager; |
| 10 |
use Elementor\Icons_Manager; |
| 11 |
use Elementor\Modules\Usage\Module; |
| 12 |
use Elementor\Plugin; |
| 13 |
use Elementor\Tracker; |
| 14 |
use Elementor\Utils; |
| 15 |
|
| 16 |
if ( ! defined( 'ABSPATH' ) ) { |
| 17 |
exit; // Exit if accessed directly. |
| 18 |
} |
| 19 |
|
| 20 |
/** |
| 21 |
* Elementor upgrades. |
| 22 |
* |
| 23 |
* Elementor upgrades handler class is responsible for updating different |
| 24 |
* Elementor versions. |
| 25 |
* |
| 26 |
* @since 1.0.0 |
| 27 |
*/ |
| 28 |
class Upgrades { |
| 29 |
|
| 30 |
public static function _on_each_version( $updater ) { |
| 31 |
self::recalc_usage_data( $updater ); |
| 32 |
self::remove_remote_info_api_data(); |
| 33 |
|
| 34 |
$uploads_manager = Plugin::$instance->uploads_manager; |
| 35 |
|
| 36 |
$temp_dir = $uploads_manager->get_temp_dir(); |
| 37 |
|
| 38 |
if ( file_exists( $temp_dir ) ) { |
| 39 |
$uploads_manager->remove_file_or_dir( $temp_dir ); |
| 40 |
} |
| 41 |
} |
| 42 |
|
| 43 |
/** |
| 44 |
* Upgrade Elementor 0.3.2 |
| 45 |
* |
| 46 |
* Change the image widget link URL, setting is to `custom` link. |
| 47 |
* |
| 48 |
* @since 2.0.0 |
| 49 |
* @static |
| 50 |
* @access public |
| 51 |
*/ |
| 52 |
public static function _v_0_3_2() { |
| 53 |
global $wpdb; |
| 54 |
|
| 55 |
$post_ids = $wpdb->get_col( |
| 56 |
'SELECT `post_id` FROM `' . $wpdb->postmeta . '` |
| 57 |
WHERE `meta_key` = \'_elementor_version\' |
| 58 |
AND `meta_value` = \'0.1\';' |
| 59 |
); |
| 60 |
|
| 61 |
if ( empty( $post_ids ) ) { |
| 62 |
return; |
| 63 |
} |
| 64 |
|
| 65 |
foreach ( $post_ids as $post_id ) { |
| 66 |
$document = Plugin::$instance->documents->get( $post_id ); |
| 67 |
|
| 68 |
if ( $document ) { |
| 69 |
$data = $document->get_elements_data(); |
| 70 |
} |
| 71 |
|
| 72 |
if ( empty( $data ) ) { |
| 73 |
continue; |
| 74 |
} |
| 75 |
|
| 76 |
$data = Plugin::$instance->db->iterate_data( $data, function( $element ) { |
| 77 |
if ( empty( $element['widgetType'] ) || 'image' !== $element['widgetType'] ) { |
| 78 |
return $element; |
| 79 |
} |
| 80 |
|
| 81 |
if ( ! empty( $element['settings']['link']['url'] ) && ! isset( $element['settings']['link_to'] ) ) { |
| 82 |
$element['settings']['link_to'] = 'custom'; |
| 83 |
} |
| 84 |
|
| 85 |
return $element; |
| 86 |
} ); |
| 87 |
|
| 88 |
$document = Plugin::$instance->documents->get( $post_id ); |
| 89 |
|
| 90 |
$document->save( [ |
| 91 |
'elements' => $data, |
| 92 |
] ); |
| 93 |
} |
| 94 |
} |
| 95 |
|
| 96 |
/** |
| 97 |
* Upgrade Elementor 0.9.2 |
| 98 |
* |
| 99 |
* Change the icon widget, icon-box widget and the social-icons widget, |
| 100 |
* setting their icon padding size to an empty string. |
| 101 |
* |
| 102 |
* Change the image widget, setting the image size to full image size. |
| 103 |
* |
| 104 |
* @since 2.0.0 |
| 105 |
* @static |
| 106 |
* @access public |
| 107 |
*/ |
| 108 |
public static function _v_0_9_2() { |
| 109 |
global $wpdb; |
| 110 |
|
| 111 |
// Fix Icon/Icon Box Widgets padding. |
| 112 |
$post_ids = $wpdb->get_col( |
| 113 |
'SELECT `post_id` FROM `' . $wpdb->postmeta . '` |
| 114 |
WHERE `meta_key` = \'_elementor_version\' |
| 115 |
AND `meta_value` = \'0.2\';' |
| 116 |
); |
| 117 |
|
| 118 |
if ( empty( $post_ids ) ) { |
| 119 |
return; |
| 120 |
} |
| 121 |
|
| 122 |
foreach ( $post_ids as $post_id ) { |
| 123 |
$document = Plugin::$instance->documents->get( $post_id ); |
| 124 |
|
| 125 |
if ( $document ) { |
| 126 |
$data = $document->get_elements_data(); |
| 127 |
} |
| 128 |
|
| 129 |
if ( empty( $data ) ) { |
| 130 |
continue; |
| 131 |
} |
| 132 |
|
| 133 |
$data = Plugin::$instance->db->iterate_data( $data, function( $element ) { |
| 134 |
if ( empty( $element['widgetType'] ) ) { |
| 135 |
return $element; |
| 136 |
} |
| 137 |
|
| 138 |
if ( in_array( $element['widgetType'], [ 'icon', 'icon-box', 'social-icons' ] ) ) { |
| 139 |
if ( ! empty( $element['settings']['icon_padding']['size'] ) ) { |
| 140 |
$element['settings']['icon_padding']['size'] = ''; |
| 141 |
} |
| 142 |
} |
| 143 |
|
| 144 |
if ( 'image' === $element['widgetType'] ) { |
| 145 |
if ( empty( $element['settings']['image_size'] ) ) { |
| 146 |
$element['settings']['image_size'] = 'full'; |
| 147 |
} |
| 148 |
} |
| 149 |
|
| 150 |
return $element; |
| 151 |
} ); |
| 152 |
|
| 153 |
$document = Plugin::$instance->documents->get( $post_id ); |
| 154 |
|
| 155 |
$document->save( [ |
| 156 |
'elements' => $data, |
| 157 |
] ); |
| 158 |
} |
| 159 |
} |
| 160 |
|
| 161 |
/** |
| 162 |
* Upgrade Elementor 0.11.0 |
| 163 |
* |
| 164 |
* Change the button widget sizes, setting up new button sizes. |
| 165 |
* |
| 166 |
* @since 2.0.0 |
| 167 |
* @static |
| 168 |
* @access public |
| 169 |
*/ |
| 170 |
public static function _v_0_11_0() { |
| 171 |
global $wpdb; |
| 172 |
|
| 173 |
// Fix Button widget to new sizes options. |
| 174 |
$post_ids = $wpdb->get_col( |
| 175 |
'SELECT `post_id` FROM `' . $wpdb->postmeta . '` |
| 176 |
WHERE `meta_key` = \'_elementor_version\' |
| 177 |
AND `meta_value` = \'0.3\';' |
| 178 |
); |
| 179 |
|
| 180 |
if ( empty( $post_ids ) ) { |
| 181 |
return; |
| 182 |
} |
| 183 |
|
| 184 |
foreach ( $post_ids as $post_id ) { |
| 185 |
$document = Plugin::$instance->documents->get( $post_id ); |
| 186 |
|
| 187 |
if ( $document ) { |
| 188 |
$data = $document->get_elements_data(); |
| 189 |
} |
| 190 |
|
| 191 |
if ( empty( $data ) ) { |
| 192 |
continue; |
| 193 |
} |
| 194 |
|
| 195 |
$data = Plugin::$instance->db->iterate_data( $data, function( $element ) { |
| 196 |
if ( empty( $element['widgetType'] ) ) { |
| 197 |
return $element; |
| 198 |
} |
| 199 |
|
| 200 |
if ( 'button' === $element['widgetType'] ) { |
| 201 |
$size_to_replace = [ |
| 202 |
'small' => 'xs', |
| 203 |
'medium' => 'sm', |
| 204 |
'large' => 'md', |
| 205 |
'xl' => 'lg', |
| 206 |
'xxl' => 'xl', |
| 207 |
]; |
| 208 |
|
| 209 |
if ( ! empty( $element['settings']['size'] ) ) { |
| 210 |
$old_size = $element['settings']['size']; |
| 211 |
|
| 212 |
if ( isset( $size_to_replace[ $old_size ] ) ) { |
| 213 |
$element['settings']['size'] = $size_to_replace[ $old_size ]; |
| 214 |
} |
| 215 |
} |
| 216 |
} |
| 217 |
|
| 218 |
return $element; |
| 219 |
} ); |
| 220 |
|
| 221 |
$document = Plugin::$instance->documents->get( $post_id ); |
| 222 |
|
| 223 |
$document->save( [ |
| 224 |
'elements' => $data, |
| 225 |
] ); |
| 226 |
} |
| 227 |
} |
| 228 |
|
| 229 |
/** |
| 230 |
* Upgrade Elementor 2.0.0 |
| 231 |
* |
| 232 |
* Fix post titles for old autosave drafts that saved with the format 'Auto Save 2018-03-18 17:24'. |
| 233 |
* |
| 234 |
* @static |
| 235 |
* @since 2.0.0 |
| 236 |
* @access public |
| 237 |
*/ |
| 238 |
public static function _v_2_0_0() { |
| 239 |
global $wpdb; |
| 240 |
|
| 241 |
$posts = $wpdb->get_results( |
| 242 |
'SELECT `ID`, `post_title`, `post_parent` |
| 243 |
FROM `' . $wpdb->posts . '` p |
| 244 |
LEFT JOIN `' . $wpdb->postmeta . '` m ON p.ID = m.post_id |
| 245 |
WHERE `post_status` = \'inherit\' |
| 246 |
AND `post_title` = CONCAT(\'Auto Save \', DATE_FORMAT(post_date, "%Y-%m-%d %H:%i")) |
| 247 |
AND m.`meta_key` = \'_elementor_data\';' |
| 248 |
); |
| 249 |
|
| 250 |
if ( empty( $posts ) ) { |
| 251 |
return; |
| 252 |
} |
| 253 |
|
| 254 |
foreach ( $posts as $post ) { |
| 255 |
wp_update_post( [ |
| 256 |
'ID' => $post->ID, |
| 257 |
'post_title' => get_the_title( $post->post_parent ), |
| 258 |
] ); |
| 259 |
} |
| 260 |
} |
| 261 |
|
| 262 |
/** |
| 263 |
* Upgrade Elementor 2.0.1 |
| 264 |
* |
| 265 |
* Fix post titles for old autosave drafts that saved with the format 'Auto Save...'. |
| 266 |
* |
| 267 |
* @since 2.0.2 |
| 268 |
* @static |
| 269 |
* @access public |
| 270 |
*/ |
| 271 |
public static function _v_2_0_1() { |
| 272 |
global $wpdb; |
| 273 |
|
| 274 |
$posts = $wpdb->get_results( |
| 275 |
'SELECT `ID`, `post_title`, `post_parent` |
| 276 |
FROM `' . $wpdb->posts . '` p |
| 277 |
LEFT JOIN `' . $wpdb->postmeta . '` m ON p.ID = m.post_id |
| 278 |
WHERE `post_status` = \'inherit\' |
| 279 |
AND `post_title` REGEXP \'^Auto Save [0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}$\' |
| 280 |
AND m.`meta_key` = \'_elementor_data\';' |
| 281 |
); |
| 282 |
|
| 283 |
if ( empty( $posts ) ) { |
| 284 |
return; |
| 285 |
} |
| 286 |
|
| 287 |
foreach ( $posts as $post ) { |
| 288 |
$parent = get_post( $post->post_parent ); |
| 289 |
$title = isset( $parent->post_title ) ? $parent->post_title : ''; |
| 290 |
|
| 291 |
wp_update_post( [ |
| 292 |
'ID' => $post->ID, |
| 293 |
'post_title' => $title, |
| 294 |
] ); |
| 295 |
} |
| 296 |
} |
| 297 |
|
| 298 |
/** |
| 299 |
* Upgrade Elementor 2.0.10 |
| 300 |
* |
| 301 |
* Fix post titles for old autosave drafts that saved with the format 'Auto Save...'. |
| 302 |
* Fix also Translated titles. |
| 303 |
* |
| 304 |
* @since 2.0.10 |
| 305 |
* @static |
| 306 |
* @access public |
| 307 |
*/ |
| 308 |
public static function _v_2_0_10() { |
| 309 |
global $wpdb; |
| 310 |
|
| 311 |
$posts = $wpdb->get_results( |
| 312 |
'SELECT `ID`, `post_title`, `post_parent` |
| 313 |
FROM `' . $wpdb->posts . '` p |
| 314 |
LEFT JOIN `' . $wpdb->postmeta . '` m ON p.ID = m.post_id |
| 315 |
WHERE `post_status` = \'inherit\' |
| 316 |
AND `post_title` REGEXP \'[[:alnum:]]+ [[:alnum:]]+ [0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}$\' |
| 317 |
AND m.`meta_key` = \'_elementor_data\';' |
| 318 |
); |
| 319 |
|
| 320 |
if ( empty( $posts ) ) { |
| 321 |
return; |
| 322 |
} |
| 323 |
|
| 324 |
foreach ( $posts as $post ) { |
| 325 |
$parent = get_post( $post->post_parent ); |
| 326 |
$title = isset( $parent->post_title ) ? $parent->post_title : ''; |
| 327 |
|
| 328 |
wp_update_post( [ |
| 329 |
'ID' => $post->ID, |
| 330 |
'post_title' => $title, |
| 331 |
] ); |
| 332 |
} |
| 333 |
} |
| 334 |
|
| 335 |
public static function _v_2_1_0() { |
| 336 |
global $wpdb; |
| 337 |
|
| 338 |
// upgrade `video` widget settings (merge providers). |
| 339 |
$post_ids = $wpdb->get_col( |
| 340 |
'SELECT `post_id` FROM `' . $wpdb->postmeta . '` WHERE `meta_key` = "_elementor_data" AND `meta_value` LIKE \'%"widgetType":"video"%\';' |
| 341 |
); |
| 342 |
|
| 343 |
if ( empty( $post_ids ) ) { |
| 344 |
return; |
| 345 |
} |
| 346 |
|
| 347 |
foreach ( $post_ids as $post_id ) { |
| 348 |
$do_update = false; |
| 349 |
$document = Plugin::$instance->documents->get( $post_id ); |
| 350 |
|
| 351 |
if ( $document ) { |
| 352 |
$data = $document->get_elements_data(); |
| 353 |
} |
| 354 |
|
| 355 |
if ( empty( $data ) ) { |
| 356 |
continue; |
| 357 |
} |
| 358 |
|
| 359 |
$data = Plugin::$instance->db->iterate_data( $data, function( $element ) use ( &$do_update ) { |
| 360 |
if ( empty( $element['widgetType'] ) || 'video' !== $element['widgetType'] ) { |
| 361 |
return $element; |
| 362 |
} |
| 363 |
|
| 364 |
$replacements = []; |
| 365 |
|
| 366 |
if ( empty( $element['settings']['video_type'] ) || 'youtube' === $element['settings']['video_type'] ) { |
| 367 |
$replacements = [ |
| 368 |
'yt_autoplay' => 'autoplay', |
| 369 |
'yt_controls' => 'controls', |
| 370 |
'yt_mute' => 'mute', |
| 371 |
'yt_rel' => 'rel', |
| 372 |
'link' => 'youtube_url', |
| 373 |
]; |
| 374 |
} elseif ( 'vimeo' === $element['settings']['video_type'] ) { |
| 375 |
$replacements = [ |
| 376 |
'vimeo_autoplay' => 'autoplay', |
| 377 |
'vimeo_loop' => 'loop', |
| 378 |
'vimeo_color' => 'color', |
| 379 |
'vimeo_link' => 'vimeo_url', |
| 380 |
]; |
| 381 |
} |
| 382 |
|
| 383 |
// cleanup old unused settings. |
| 384 |
unset( $element['settings']['yt_rel_videos'] ); |
| 385 |
|
| 386 |
foreach ( $replacements as $old => $new ) { |
| 387 |
if ( ! empty( $element['settings'][ $old ] ) ) { |
| 388 |
$element['settings'][ $new ] = $element['settings'][ $old ]; |
| 389 |
$do_update = true; |
| 390 |
} |
| 391 |
} |
| 392 |
|
| 393 |
return $element; |
| 394 |
} ); |
| 395 |
|
| 396 |
// Only update if needed. |
| 397 |
if ( ! $do_update ) { |
| 398 |
continue; |
| 399 |
} |
| 400 |
|
| 401 |
// We need the `wp_slash` in order to avoid the unslashing during the `update_post_meta` |
| 402 |
$json_value = wp_slash( wp_json_encode( $data ) ); |
| 403 |
|
| 404 |
update_metadata( 'post', $post_id, '_elementor_data', $json_value ); |
| 405 |
|
| 406 |
// Clear WP cache for next step. |
| 407 |
wp_cache_flush(); |
| 408 |
} // End foreach(). |
| 409 |
} |
| 410 |
|
| 411 |
/** |
| 412 |
* @param Updater $updater |
| 413 |
* |
| 414 |
* @return bool |
| 415 |
*/ |
| 416 |
public static function _v_2_3_0_widget_image( $updater ) { |
| 417 |
global $wpdb; |
| 418 |
|
| 419 |
// upgrade `video` widget settings (merge providers). |
| 420 |
$post_ids = $updater->query_col( |
| 421 |
'SELECT `post_id` FROM `' . $wpdb->postmeta . '` WHERE `meta_key` = "_elementor_data" AND ( |
| 422 |
`meta_value` LIKE \'%"widgetType":"image"%\' |
| 423 |
OR `meta_value` LIKE \'%"widgetType":"theme-post-featured-image"%\' |
| 424 |
OR `meta_value` LIKE \'%"widgetType":"theme-site-logo"%\' |
| 425 |
OR `meta_value` LIKE \'%"widgetType":"woocommerce-category-image"%\' |
| 426 |
);' |
| 427 |
); |
| 428 |
|
| 429 |
if ( empty( $post_ids ) ) { |
| 430 |
return false; |
| 431 |
} |
| 432 |
|
| 433 |
$widgets = [ |
| 434 |
'image', |
| 435 |
'theme-post-featured-image', |
| 436 |
'theme-site-logo', |
| 437 |
'woocommerce-category-image', |
| 438 |
]; |
| 439 |
|
| 440 |
foreach ( $post_ids as $post_id ) { |
| 441 |
// Clear WP cache for next step. |
| 442 |
wp_cache_flush(); |
| 443 |
|
| 444 |
$do_update = false; |
| 445 |
|
| 446 |
$document = Plugin::$instance->documents->get( $post_id ); |
| 447 |
|
| 448 |
if ( ! $document ) { |
| 449 |
continue; |
| 450 |
} |
| 451 |
|
| 452 |
$data = $document->get_elements_data(); |
| 453 |
|
| 454 |
if ( empty( $data ) ) { |
| 455 |
continue; |
| 456 |
} |
| 457 |
|
| 458 |
$data = Plugin::$instance->db->iterate_data( $data, function( $element ) use ( &$do_update, $widgets ) { |
| 459 |
if ( empty( $element['widgetType'] ) || ! in_array( $element['widgetType'], $widgets ) ) { |
| 460 |
return $element; |
| 461 |
} |
| 462 |
|
| 463 |
if ( ! empty( $element['settings']['caption'] ) ) { |
| 464 |
if ( ! isset( $element['settings']['caption_source'] ) ) { |
| 465 |
$element['settings']['caption_source'] = 'custom'; |
| 466 |
|
| 467 |
$do_update = true; |
| 468 |
} |
| 469 |
} |
| 470 |
|
| 471 |
return $element; |
| 472 |
} ); |
| 473 |
|
| 474 |
// Only update if needed. |
| 475 |
if ( ! $do_update ) { |
| 476 |
continue; |
| 477 |
} |
| 478 |
|
| 479 |
// We need the `wp_slash` in order to avoid the unslashing during the `update_post_meta` |
| 480 |
$json_value = wp_slash( wp_json_encode( $data ) ); |
| 481 |
|
| 482 |
update_metadata( 'post', $post_id, '_elementor_data', $json_value ); |
| 483 |
} // End foreach(). |
| 484 |
|
| 485 |
return $updater->should_run_again( $post_ids ); |
| 486 |
} |
| 487 |
|
| 488 |
/** |
| 489 |
* @param Updater $updater |
| 490 |
* |
| 491 |
* @return bool |
| 492 |
*/ |
| 493 |
public static function _v_2_3_0_template_type( $updater ) { |
| 494 |
global $wpdb; |
| 495 |
|
| 496 |
$post_ids = $updater->query_col( |
| 497 |
'SELECT p.ID |
| 498 |
FROM `' . $wpdb->posts . '` AS p |
| 499 |
LEFT JOIN `' . $wpdb->postmeta . '` AS pm1 ON (p.ID = pm1.post_id) |
| 500 |
LEFT JOIN `' . $wpdb->postmeta . '` AS pm2 ON (pm1.post_id = pm2.post_id AND pm2.meta_key = "_elementor_template_type") |
| 501 |
WHERE p.post_status != "inherit" AND pm1.`meta_key` = "_elementor_data" AND pm2.post_id IS NULL;' |
| 502 |
); |
| 503 |
|
| 504 |
if ( empty( $post_ids ) ) { |
| 505 |
return false; |
| 506 |
} |
| 507 |
|
| 508 |
foreach ( $post_ids as $post_id ) { |
| 509 |
// Clear WP cache for next step. |
| 510 |
wp_cache_flush(); |
| 511 |
|
| 512 |
$document = Plugin::$instance->documents->get( $post_id ); |
| 513 |
|
| 514 |
if ( ! $document ) { |
| 515 |
continue; |
| 516 |
} |
| 517 |
|
| 518 |
$document->save_template_type(); |
| 519 |
} // End foreach(). |
| 520 |
|
| 521 |
return $updater->should_run_again( $post_ids ); |
| 522 |
} |
| 523 |
|
| 524 |
/** |
| 525 |
* Set FontAwesome Migration needed flag |
| 526 |
*/ |
| 527 |
public static function _v_2_6_0_fa4_migration_flag() { |
| 528 |
add_option( 'elementor_icon_manager_needs_update', 'yes' ); |
| 529 |
add_option( 'elementor_load_fa4_shim', 'yes' ); |
| 530 |
} |
| 531 |
|
| 532 |
/** |
| 533 |
* migrate Icon control string value to Icons control array value |
| 534 |
* |
| 535 |
* @param array $element |
| 536 |
* @param array $args |
| 537 |
* |
| 538 |
* @return mixed |
| 539 |
*/ |
| 540 |
public static function _migrate_icon_fa4_value( $element, $args ) { |
| 541 |
$widget_id = $args['widget_id']; |
| 542 |
|
| 543 |
if ( empty( $element['widgetType'] ) || $widget_id !== $element['widgetType'] ) { |
| 544 |
return $element; |
| 545 |
} |
| 546 |
foreach ( $args['control_ids'] as $old_name => $new_name ) { |
| 547 |
// exit if new value exists |
| 548 |
if ( isset( $element['settings'][ $new_name ] ) ) { |
| 549 |
continue; |
| 550 |
} |
| 551 |
|
| 552 |
// exit if no value to migrate |
| 553 |
if ( ! isset( $element['settings'][ $old_name ] ) ) { |
| 554 |
continue; |
| 555 |
} |
| 556 |
|
| 557 |
$element['settings'][ $new_name ] = Icons_Manager::fa4_to_fa5_value_migration( $element['settings'][ $old_name ] ); |
| 558 |
$args['do_update'] = true; |
| 559 |
} |
| 560 |
return $element; |
| 561 |
} |
| 562 |
|
| 563 |
/** |
| 564 |
* Set FontAwesome 5 value Migration on for button widget |
| 565 |
* |
| 566 |
* @param Updater $updater |
| 567 |
*/ |
| 568 |
public static function _v_2_6_6_fa4_migration_button( $updater ) { |
| 569 |
$changes = [ |
| 570 |
[ |
| 571 |
'callback' => [ 'Elementor\Core\Upgrade\Upgrades', '_migrate_icon_fa4_value' ], |
| 572 |
'control_ids' => [ |
| 573 |
'icon' => 'selected_icon', |
| 574 |
], |
| 575 |
], |
| 576 |
]; |
| 577 |
Upgrade_Utils::_update_widget_settings( 'button', $updater, $changes ); |
| 578 |
Upgrade_Utils::_update_widget_settings( 'icon-box', $updater, $changes ); |
| 579 |
} |
| 580 |
|
| 581 |
/** |
| 582 |
* Update database to separate page from post. |
| 583 |
* |
| 584 |
* @param Updater $updater |
| 585 |
* |
| 586 |
* @param string $type |
| 587 |
* |
| 588 |
* @return bool |
| 589 |
*/ |
| 590 |
public static function rename_document_base_to_wp( $updater, $type ) { |
| 591 |
global $wpdb; |
| 592 |
|
| 593 |
$post_ids = $updater->query_col( $wpdb->prepare( |
| 594 |
"SELECT p1.ID FROM {$wpdb->posts} AS p |
| 595 |
LEFT JOIN {$wpdb->posts} AS p1 ON (p.ID = p1.post_parent || p.ID = p1.ID) |
| 596 |
WHERE p.post_type = %s;", $type ) ); |
| 597 |
|
| 598 |
if ( empty( $post_ids ) ) { |
| 599 |
return false; |
| 600 |
} |
| 601 |
|
| 602 |
$sql_post_ids = implode( ',', $post_ids ); |
| 603 |
|
| 604 |
$wpdb->query( $wpdb->prepare( |
| 605 |
"UPDATE $wpdb->postmeta SET meta_value = %s |
| 606 |
WHERE meta_key = '_elementor_template_type' && post_id in ( %s ); |
| 607 |
", 'wp-' . $type, $sql_post_ids ) ); |
| 608 |
|
| 609 |
return $updater->should_run_again( $post_ids ); |
| 610 |
} |
| 611 |
|
| 612 |
/** |
| 613 |
* Update database to separate page from post. |
| 614 |
* |
| 615 |
* @param Updater $updater |
| 616 |
* |
| 617 |
* @return bool |
| 618 |
*/ |
| 619 |
// Because the query is slow on large sites, temporary don't upgrade. |
| 620 |
/* public static function _v_2_7_0_rename_document_types_to_wp( $updater ) { |
| 621 |
return self::rename_document_base_to_wp( $updater, 'post' ) || self::rename_document_base_to_wp( $updater, 'page' ); |
| 622 |
}*/ |
| 623 |
|
| 624 |
// Upgrade code was fixed & moved to _v_2_7_1_remove_old_usage_data. |
| 625 |
/* public static function _v_2_7_0_remove_old_usage_data() {} */ |
| 626 |
|
| 627 |
// Upgrade code moved to _v_2_7_1_recalc_usage_data. |
| 628 |
/* public static function _v_2_7_0_recalc_usage_data( $updater ) {} */ |
| 629 |
|
| 630 |
/** |
| 631 |
* Don't use the old data anymore. |
| 632 |
* Since 2.7.1 the key was changed from `elementor_elements_usage` to `elementor_controls_usage`. |
| 633 |
*/ |
| 634 |
public static function _v_2_7_1_remove_old_usage_data() { |
| 635 |
delete_option( 'elementor_elements_usage' ); |
| 636 |
delete_post_meta_by_key( '_elementor_elements_usage' ); |
| 637 |
} |
| 638 |
|
| 639 |
/** |
| 640 |
* Recalc usage. |
| 641 |
* |
| 642 |
* @param Updater $updater |
| 643 |
* |
| 644 |
* @return bool |
| 645 |
*/ |
| 646 |
public static function recalc_usage_data( $updater ) { |
| 647 |
if ( ! Tracker::is_allow_track() ) { |
| 648 |
return false; |
| 649 |
} |
| 650 |
|
| 651 |
/** @var Module $module */ |
| 652 |
$module = Plugin::$instance->modules_manager->get_modules( 'usage' ); |
| 653 |
|
| 654 |
$post_count = $module->recalc_usage( $updater->get_limit(), $updater->get_current_offset() ); |
| 655 |
|
| 656 |
return ( $post_count === $updater->get_limit() ); |
| 657 |
} |
| 658 |
|
| 659 |
public static function _v_2_7_1_recalc_usage_data( $updater ) { |
| 660 |
return self::recalc_usage_data( $updater ); |
| 661 |
} |
| 662 |
|
| 663 |
public static function _v_2_8_3_recalc_usage_data( $updater ) { |
| 664 |
// Re-calc since older version(s) had invalid values. |
| 665 |
return self::recalc_usage_data( $updater ); |
| 666 |
} |
| 667 |
|
| 668 |
/** |
| 669 |
* Move general & lightbox settings to active kit and all it's revisions. |
| 670 |
* |
| 671 |
* @param Updater $updater |
| 672 |
* |
| 673 |
* @return bool |
| 674 |
*/ |
| 675 |
public static function _v_3_0_0_move_general_settings_to_kit( $updater ) { |
| 676 |
$callback = function( $kit_id ) { |
| 677 |
$kit = Plugin::$instance->documents->get( $kit_id ); |
| 678 |
|
| 679 |
if ( ! $kit ) { |
| 680 |
self::notice( 'Kit not found. nothing to do.' ); |
| 681 |
return; |
| 682 |
} |
| 683 |
|
| 684 |
$meta_key = SettingsPageManager::META_KEY; |
| 685 |
$current_settings = get_option( '_elementor_general_settings', [] ); |
| 686 |
// Take the `space_between_widgets` from the option due to a bug on E < 3.0.0 that the value `0` is stored separated. |
| 687 |
$current_settings['space_between_widgets'] = get_option( 'elementor_space_between_widgets', '' ); |
| 688 |
$current_settings[ Breakpoints_Manager::BREAKPOINT_SETTING_PREFIX . 'md' ] = get_option( 'elementor_viewport_md', '' ); |
| 689 |
$current_settings[ Breakpoints_Manager::BREAKPOINT_SETTING_PREFIX . 'lg' ] = get_option( 'elementor_viewport_lg', '' ); |
| 690 |
|
| 691 |
$kit_settings = $kit->get_meta( $meta_key ); |
| 692 |
|
| 693 |
// Already exist. |
| 694 |
if ( isset( $kit_settings['default_generic_fonts'] ) ) { |
| 695 |
self::notice( 'General Settings already exist. nothing to do.' ); |
| 696 |
return; |
| 697 |
} |
| 698 |
|
| 699 |
if ( empty( $current_settings ) ) { |
| 700 |
self::notice( 'Current settings are empty. nothing to do.' ); |
| 701 |
return; |
| 702 |
} |
| 703 |
|
| 704 |
if ( ! $kit_settings ) { |
| 705 |
$kit_settings = []; |
| 706 |
} |
| 707 |
|
| 708 |
// Convert some setting to Elementor slider format. |
| 709 |
$settings_to_slider = [ |
| 710 |
'container_width', |
| 711 |
'space_between_widgets', |
| 712 |
]; |
| 713 |
|
| 714 |
foreach ( $settings_to_slider as $setting ) { |
| 715 |
if ( isset( $current_settings[ $setting ] ) ) { |
| 716 |
$current_settings[ $setting ] = [ |
| 717 |
'unit' => 'px', |
| 718 |
'size' => $current_settings[ $setting ], |
| 719 |
]; |
| 720 |
} |
| 721 |
} |
| 722 |
|
| 723 |
$kit_settings = array_merge( $kit_settings, $current_settings ); |
| 724 |
|
| 725 |
$page_settings_manager = SettingsManager::get_settings_managers( 'page' ); |
| 726 |
$page_settings_manager->save_settings( $kit_settings, $kit_id ); |
| 727 |
}; |
| 728 |
|
| 729 |
return self::move_settings_to_kit( $callback, $updater ); |
| 730 |
} |
| 731 |
|
| 732 |
/** |
| 733 |
* Move default colors settings to active kit and all it's revisions. |
| 734 |
* |
| 735 |
* @param Updater $updater |
| 736 |
* |
| 737 |
* @return bool |
| 738 |
*/ |
| 739 |
public static function _v_3_0_0_move_default_colors_to_kit( $updater, $include_revisions = true ) { |
| 740 |
$callback = function( $kit_id ) { |
| 741 |
if ( ! Plugin::$instance->kits_manager->is_custom_colors_enabled() ) { |
| 742 |
self::notice( 'System colors are disabled. nothing to do.' ); |
| 743 |
return; |
| 744 |
} |
| 745 |
|
| 746 |
$kit = Plugin::$instance->documents->get( $kit_id ); |
| 747 |
|
| 748 |
// Already exist. use raw settings that doesn't have default values. |
| 749 |
$meta_key = SettingsPageManager::META_KEY; |
| 750 |
$kit_raw_settings = $kit->get_meta( $meta_key ); |
| 751 |
if ( isset( $kit_raw_settings['system_colors'] ) ) { |
| 752 |
self::notice( 'System colors already exist. nothing to do.' ); |
| 753 |
return; |
| 754 |
} |
| 755 |
|
| 756 |
$scheme_obj = Plugin::$instance->schemes_manager->get_scheme( 'color' ); |
| 757 |
|
| 758 |
$default_colors = $scheme_obj->get_scheme(); |
| 759 |
|
| 760 |
$new_ids = [ |
| 761 |
'primary', |
| 762 |
'secondary', |
| 763 |
'text', |
| 764 |
'accent', |
| 765 |
]; |
| 766 |
|
| 767 |
foreach ( $default_colors as $index => $color ) { |
| 768 |
$kit->add_repeater_row( 'system_colors', [ |
| 769 |
'_id' => $new_ids[ $index - 1 ], // $default_colors starts from 1. |
| 770 |
'title' => $color['title'], |
| 771 |
'color' => strtoupper( $color['value'] ), |
| 772 |
] ); |
| 773 |
} |
| 774 |
}; |
| 775 |
|
| 776 |
return self::move_settings_to_kit( $callback, $updater, $include_revisions ); |
| 777 |
} |
| 778 |
|
| 779 |
/** |
| 780 |
* Move saved colors settings to active kit and all it's revisions. |
| 781 |
* |
| 782 |
* @param Updater $updater |
| 783 |
* |
| 784 |
* @return bool |
| 785 |
*/ |
| 786 |
public static function _v_3_0_0_move_saved_colors_to_kit( $updater, $include_revisions = true ) { |
| 787 |
$callback = function( $kit_id ) { |
| 788 |
$kit = Plugin::$instance->documents->get( $kit_id ); |
| 789 |
|
| 790 |
// Already exist. use raw settings that doesn't have default values. |
| 791 |
$meta_key = SettingsPageManager::META_KEY; |
| 792 |
$kit_raw_settings = $kit->get_meta( $meta_key ); |
| 793 |
if ( isset( $kit_raw_settings['custom_colors'] ) ) { |
| 794 |
self::notice( 'Custom colors already exist. nothing to do.' ); |
| 795 |
return; |
| 796 |
} |
| 797 |
|
| 798 |
$system_colors_rows = $kit->get_settings( 'system_colors' ); |
| 799 |
|
| 800 |
if ( ! $system_colors_rows ) { |
| 801 |
$system_colors_rows = []; |
| 802 |
} |
| 803 |
|
| 804 |
$system_colors = []; |
| 805 |
|
| 806 |
foreach ( $system_colors_rows as $color_row ) { |
| 807 |
$system_colors[] = strtoupper( $color_row['color'] ); |
| 808 |
} |
| 809 |
|
| 810 |
$saved_scheme_obj = Plugin::$instance->schemes_manager->get_scheme( 'color-picker' ); |
| 811 |
|
| 812 |
$current_saved_colors_rows = $saved_scheme_obj->get_scheme(); |
| 813 |
|
| 814 |
$current_saved_colors = []; |
| 815 |
|
| 816 |
foreach ( $current_saved_colors_rows as $color_row ) { |
| 817 |
$current_saved_colors[] = strtoupper( $color_row['value'] ); |
| 818 |
} |
| 819 |
|
| 820 |
$colors_to_save = array_diff( $current_saved_colors, $system_colors ); |
| 821 |
|
| 822 |
if ( empty( $colors_to_save ) ) { |
| 823 |
self::notice( 'Saved colors not found. nothing to do.' ); |
| 824 |
return; |
| 825 |
} |
| 826 |
|
| 827 |
foreach ( $colors_to_save as $index => $color ) { |
| 828 |
$kit->add_repeater_row( 'custom_colors', [ |
| 829 |
'_id' => Utils::generate_random_string(), |
| 830 |
'title' => esc_html__( 'Saved Color', 'elementor' ) . ' #' . ( $index + 1 ), |
| 831 |
'color' => $color, |
| 832 |
] ); |
| 833 |
} |
| 834 |
}; |
| 835 |
|
| 836 |
return self::move_settings_to_kit( $callback, $updater, $include_revisions ); |
| 837 |
} |
| 838 |
|
| 839 |
/** |
| 840 |
* Move default typography settings to active kit and all it's revisions. |
| 841 |
* |
| 842 |
* @param Updater $updater |
| 843 |
* |
| 844 |
* @return bool |
| 845 |
*/ |
| 846 |
public static function _v_3_0_0_move_default_typography_to_kit( $updater, $include_revisions = true ) { |
| 847 |
$callback = function( $kit_id ) { |
| 848 |
if ( ! Plugin::$instance->kits_manager->is_custom_typography_enabled() ) { |
| 849 |
self::notice( 'System typography is disabled. nothing to do.' ); |
| 850 |
return; |
| 851 |
} |
| 852 |
|
| 853 |
$kit = Plugin::$instance->documents->get( $kit_id ); |
| 854 |
|
| 855 |
// Already exist. use raw settings that doesn't have default values. |
| 856 |
$meta_key = SettingsPageManager::META_KEY; |
| 857 |
$kit_raw_settings = $kit->get_meta( $meta_key ); |
| 858 |
if ( isset( $kit_raw_settings['system_typography'] ) ) { |
| 859 |
self::notice( 'System typography already exist. nothing to do.' ); |
| 860 |
return; |
| 861 |
} |
| 862 |
|
| 863 |
$scheme_obj = Plugin::$instance->schemes_manager->get_scheme( 'typography' ); |
| 864 |
|
| 865 |
$default_typography = $scheme_obj->get_scheme(); |
| 866 |
|
| 867 |
$new_ids = [ |
| 868 |
'primary', |
| 869 |
'secondary', |
| 870 |
'text', |
| 871 |
'accent', |
| 872 |
]; |
| 873 |
|
| 874 |
foreach ( $default_typography as $index => $typography ) { |
| 875 |
$kit->add_repeater_row( 'system_typography', [ |
| 876 |
'_id' => $new_ids[ $index - 1 ], // $default_typography starts from 1. |
| 877 |
'title' => $typography['title'], |
| 878 |
'typography_typography' => 'custom', |
| 879 |
'typography_font_family' => $typography['value']['font_family'], |
| 880 |
'typography_font_weight' => $typography['value']['font_weight'], |
| 881 |
] ); |
| 882 |
} |
| 883 |
}; |
| 884 |
|
| 885 |
return self::move_settings_to_kit( $callback, $updater, $include_revisions ); |
| 886 |
} |
| 887 |
|
| 888 |
public static function v_3_1_0_move_optimized_dom_output_to_experiments() { |
| 889 |
$saved_option = get_option( 'elementor_optimized_dom_output' ); |
| 890 |
|
| 891 |
if ( $saved_option ) { |
| 892 |
$new_option = 'enabled' === $saved_option ? Experiments_Manager::STATE_ACTIVE : Experiments_Manager::STATE_INACTIVE; |
| 893 |
|
| 894 |
add_option( 'elementor_experiment-e_dom_optimization', $new_option ); |
| 895 |
} |
| 896 |
} |
| 897 |
|
| 898 |
public static function _v_3_2_0_migrate_breakpoints_to_new_system( $updater, $include_revisions = true ) { |
| 899 |
$callback = function( $kit_id ) { |
| 900 |
$kit = Plugin::$instance->documents->get( $kit_id ); |
| 901 |
|
| 902 |
$kit_settings = $kit->get_meta( SettingsPageManager::META_KEY ); |
| 903 |
|
| 904 |
if ( ! $kit_settings ) { |
| 905 |
// Nothing to upgrade. |
| 906 |
return; |
| 907 |
} |
| 908 |
|
| 909 |
$prefix = Breakpoints_Manager::BREAKPOINT_SETTING_PREFIX; |
| 910 |
$old_mobile_option_key = $prefix . 'md'; |
| 911 |
$old_tablet_option_key = $prefix . 'lg'; |
| 912 |
|
| 913 |
$breakpoint_values = [ |
| 914 |
$old_mobile_option_key => Plugin::$instance->kits_manager->get_current_settings( $old_mobile_option_key ), |
| 915 |
$old_tablet_option_key => Plugin::$instance->kits_manager->get_current_settings( $old_tablet_option_key ), |
| 916 |
]; |
| 917 |
|
| 918 |
// Breakpoint values are either a number, or an empty string (empty setting). |
| 919 |
array_walk( $breakpoint_values, function( &$breakpoint_value, $breakpoint_key ) { |
| 920 |
if ( $breakpoint_value ) { |
| 921 |
// If the saved breakpoint value is a number, 1px is reduced because the new breakpoints system is |
| 922 |
// based on max-width, as opposed to the old breakpoints system that worked based on min-width. |
| 923 |
$breakpoint_value--; |
| 924 |
} |
| 925 |
|
| 926 |
return $breakpoint_value; |
| 927 |
} ); |
| 928 |
|
| 929 |
$kit_settings[ $prefix . Breakpoints_Manager::BREAKPOINT_KEY_MOBILE ] = $breakpoint_values[ $old_mobile_option_key ]; |
| 930 |
$kit_settings[ $prefix . Breakpoints_Manager::BREAKPOINT_KEY_TABLET ] = $breakpoint_values[ $old_tablet_option_key ]; |
| 931 |
|
| 932 |
$page_settings_manager = SettingsManager::get_settings_managers( 'page' ); |
| 933 |
$page_settings_manager->save_settings( $kit_settings, $kit_id ); |
| 934 |
}; |
| 935 |
|
| 936 |
return self::move_settings_to_kit( $callback, $updater, $include_revisions ); |
| 937 |
} |
| 938 |
|
| 939 |
public static function _v_3_4_8_fix_font_awesome_default_value_from_1_to_yes() { |
| 940 |
// if `Icons_Manager::LOAD_FA4_SHIM_OPTION_KEY` value is '1', then set it to `yes`. |
| 941 |
$load_fa4_shim_option = get_option( Icons_Manager::LOAD_FA4_SHIM_OPTION_KEY ); |
| 942 |
|
| 943 |
if ( '1' === $load_fa4_shim_option ) { |
| 944 |
update_option( Icons_Manager::LOAD_FA4_SHIM_OPTION_KEY, 'yes' ); |
| 945 |
} |
| 946 |
} |
| 947 |
|
| 948 |
public static function _v_3_5_0_remove_old_elementor_scheme() { |
| 949 |
global $wpdb; |
| 950 |
|
| 951 |
$key = Base::SCHEME_OPTION_PREFIX; |
| 952 |
|
| 953 |
$wpdb->query( "DELETE FROM {$wpdb->options} WHERE option_name LIKE '{$key}%';" ); // phpcs:ignore |
| 954 |
} |
| 955 |
|
| 956 |
public static function remove_remote_info_api_data() { |
| 957 |
global $wpdb; |
| 958 |
|
| 959 |
$key = Api::TRANSIENT_KEY_PREFIX; |
| 960 |
|
| 961 |
return $wpdb->query( "DELETE FROM {$wpdb->options} WHERE option_name LIKE '{$key}%';" ); // phpcs:ignore |
| 962 |
} |
| 963 |
|
| 964 |
/** |
| 965 |
* @param callback $callback |
| 966 |
* @param Updater $updater |
| 967 |
* |
| 968 |
* @param bool $include_revisions |
| 969 |
* |
| 970 |
* @return mixed |
| 971 |
*/ |
| 972 |
private static function move_settings_to_kit( $callback, $updater, $include_revisions = true ) { |
| 973 |
$active_kit_id = Plugin::$instance->kits_manager->get_active_id(); |
| 974 |
if ( ! $active_kit_id ) { |
| 975 |
self::notice( 'Active kit not found. nothing to do.' ); |
| 976 |
return false; |
| 977 |
} |
| 978 |
|
| 979 |
$offset = $updater->get_current_offset(); |
| 980 |
|
| 981 |
// On first iteration apply on active kit itself. |
| 982 |
// (don't include it with revisions in order to avoid offset/iteration count wrong numbers) |
| 983 |
if ( 0 === $offset ) { |
| 984 |
$callback( $active_kit_id ); |
| 985 |
} |
| 986 |
|
| 987 |
if ( ! $include_revisions ) { |
| 988 |
return false; |
| 989 |
} |
| 990 |
|
| 991 |
$revisions_ids = wp_get_post_revisions( $active_kit_id, [ |
| 992 |
'fields' => 'ids', |
| 993 |
'posts_per_page' => $updater->get_limit(), |
| 994 |
'offset' => $offset, |
| 995 |
] ); |
| 996 |
|
| 997 |
foreach ( $revisions_ids as $revision_id ) { |
| 998 |
$callback( $revision_id ); |
| 999 |
} |
| 1000 |
|
| 1001 |
return $updater->should_run_again( $revisions_ids ); |
| 1002 |
} |
| 1003 |
|
| 1004 |
private static function notice( $message ) { |
| 1005 |
$logger = Plugin::$instance->logger->get_logger(); |
| 1006 |
$logger->notice( $message ); |
| 1007 |
} |
| 1008 |
} |
| 1009 |
|