/var/www/html_us/wp-content/plugins/elementor/modules/wp-cli/command.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
<?php
namespace Elementor\Modules\WpCli;

use 
Elementor\Api;
use 
Elementor\Plugin;
use 
Elementor\TemplateLibrary\Source_Local;
use 
Elementor\Utils;

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

/**
 * Elementor Page Builder cli tools.
 */
class Command extends \WP_CLI_Command {

    
/**
     * Flush the Elementor Page Builder CSS Cache.
     *
     * [--network]
     *      Flush CSS Cache for all the sites in the network.
     *
     * [--regenerate]
     *      Re-create the CSS files. Otherwise they will be created by a page visit.
     *
     * ## EXAMPLES
     *
     *  1. wp elementor flush-css
     *      - This will flush the CSS files for elementor page builder.
     *
     *  2. wp elementor flush-css --network
     *      - This will flush the CSS files for elementor page builder for all the sites in the network.
     *
     *  3. wp elementor flush-css --regenerate
     *      - This will flush the CSS files for elementor page builder and re-create the new CSS files.
     *
     * @since 2.1.0
     * @access public
     * @alias flush-css
     */
    
public function flush_css$args$assoc_args ) {
        
$network = ! empty( $assoc_args['network'] ) && is_multisite();
        
$should_regenerate = ! empty( $assoc_args['regenerate'] );

        if ( 
$network ) {
            
$blog_ids get_sites( [
                
'fields' => 'ids',
                
'number' => 0,
            ] );

            foreach ( 
$blog_ids as $blog_id ) {
                
switch_to_blog$blog_id );

                
$this->handle_flush$should_regenerate'Flushed the Elementor CSS Cache for site - ' get_option'home' ) );

                
restore_current_blog();
            }
        } else {
            
$this->handle_flush$should_regenerate'Flushed the Elementor CSS Cache' );
        }
    }

    private function 
handle_flushbool $should_regeneratestring $success_message ): void {
        
Plugin::$instance->files_manager->clear_cache();

        if ( 
$should_regenerate ) {
            
Plugin::$instance->files_manager->generate_css();
        }

        
\WP_CLI::success$success_message );
    }

    
/**
     * Print system info powered by Elementor
     *
     * ## EXAMPLES
     *
     *  1. wp elementor system-info
     *      - This will print the System Info in JSON format
     *
     * @since 3.0.11
     * @access public
     * @alias system-info
     */
    
public function system_info() {
        echo 
wp_json_encode\Elementor\Tracker::get_tracking_data() );
    }

    
/**
     * Replace old URLs with new URLs in all Elementor pages.
     *
     * [--force]
     *      Suppress error messages. instead, return "0 database rows affected.".
     *
     * ## EXAMPLES
     *
     *  1. wp elementor replace-urls <old> <new>
     *      - This will replace all <old> URLs with the <new> URL.
     *
     *  2. wp elementor replace-urls <old> <new> --force
     *      - This will replace all <old> URLs with the <new> URL without throw errors.
     *
     * @access public
     * @alias replace-urls
     */
    
public function replace_urls$args$assoc_args ) {
        if ( empty( 
$args[0] ) ) {
            
\WP_CLI::error'Please set the `old` URL' );
        }

        if ( empty( 
$args[1] ) ) {
            
\WP_CLI::error'Please set the `new` URL' );
        }

        try {
            
$results Utils::replace_urls$args[0], $args[1] );
            
\WP_CLI::success$results );
        } catch ( 
\Exception $e ) {
            if ( isset( 
$assoc_args['force'] ) ) {
                
\WP_CLI::success'0 database rows affected.' );
            } else {
                
\WP_CLI::error$e->getMessage() );
            }
        }
    }

    
/**
     * Sync Elementor Library.
     *
     * ## EXAMPLES
     *
     *  1. wp elementor sync-library
     *      - This will sync the library with Elementor cloud library.
     *
     * @since 2.1.0
     * @access public
     * @alias sync-library
     */
    
public function sync_library$args$assoc_args ) {
        
// TODO:
        // \WP_CLI::warning( 'command is deprecated since 2.8.0 Please use: wp elementor library sync' );

        
$data Api::get_library_datatrue );

        if ( empty( 
$data ) ) {
            
\WP_CLI::error'Cannot sync library.' );
        }

        
\WP_CLI::success'Library has been synced.' );
    }

    
/**
     * Import template files to the Library.
     *
     * ## EXAMPLES
     *
     *  1. wp elementor import-library <file-path>
     *      - This will import a file or a zip of multiple files to the library.
     *
     * @since 2.1.0
     * @access public
     * @alias import-library
     */
    
public function import_library$args$assoc_args ) {
        
// TODO:
        // \WP_CLI::warning( 'command is deprecated since 2.8.0 Please use: wp elementor library import' );

        
if ( empty( $args[0] ) ) {
            
\WP_CLI::error'Please set file path.' );
        }

        
/** @var Source_Local $source */
        
$source Plugin::$instance->templates_manager->get_source'local' );

        
$imported_items $source->import_templatebasename$args[0] ), $args[0] );

        if ( 
is_wp_error$imported_items ) ) {
            
\WP_CLI::error$imported_items->get_error_message() );
        }

        
\WP_CLI::successcount$imported_items ) . ' item(s) has been imported.' );
    }
}