/var/www/html/wp-content/plugins/elementor/core/upgrade/upgrade-utils.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?php
namespace Elementor\Core\Upgrade;

use 
Elementor\Plugin;

if ( ! 
defined'ABSPATH' ) ) {
    exit; 
// Exit if accessed directly
}

class 
Upgrade_Utils {

    
/**
     *  _update_widget_settings
     *
     * @param string $widget_id  widget type id
     * @param Updater $updater   updater instance
     * @param array $changes     array containing updating control_ids, callback and other data needed by the callback
     *
     * @return bool
     */
    
public static function _update_widget_settings$widget_id$updater$changes ) {
        global 
$wpdb;

        
$post_ids $updater->query_col(
            
'SELECT `post_id` 
                    FROM `' 
$wpdb->postmeta '` 
                    WHERE `meta_key` = "_elementor_data" 
                    AND `meta_value` LIKE \'%"widgetType":"' 
$widget_id '"%\';'
        
);

        if ( empty( 
$post_ids ) ) {
            return 
false;
        }

        foreach ( 
$post_ids as $post_id ) {
            
$do_update false;

            
$document Plugin::instance()->documents->get$post_id );

            if ( ! 
$document ) {
                continue;
            }

            
$data $document->get_elements_data();

            if ( empty( 
$data ) ) {
                continue;
            }

            
// loop thru callbacks & array
            
foreach ( $changes as $change ) {
                
$args = [
                    
'do_update' => &$do_update,
                    
'widget_id' => $widget_id,
                    
'control_ids' => $change['control_ids'],
                ];

                if ( isset( 
$change['prefix'] ) ) {
                    
$args['prefix'] = $change['prefix'];
                    
$args['new_id'] = $change['new_id'];
                }

                
$data Plugin::instance()->db->iterate_data$data$change['callback'], $args );
                if ( ! 
$do_update ) {
                    continue;
                }

                
// We need the `wp_slash` in order to avoid the unslashing during the `update_metadata`
                
$json_value wp_slashwp_json_encode$data ) );

                
update_metadata'post'$post_id'_elementor_data'$json_value );
            }
        } 
// End foreach().

        
return $updater->should_run_again$post_ids );
    }
}