PluginProbe
Elementor Website Builder – more than just a page builder / 3.1.0
Elementor Website Builder – more than just a page builder v3.1.0
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
elementor / modules / wp-cli / command.php

command.php in Elementor Website Builder – more than just a page builder 3.1.0, at modules/wp-cli/command.php

163 lines 3.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Elementor\Modules\WpCli;
3
4 use Elementor\Api;
5 use Elementor\Plugin;
6 use Elementor\TemplateLibrary\Source_Local;
7 use Elementor\Utils;
8
9 if ( ! defined( 'ABSPATH' ) ) {
10 exit; // Exit if accessed directly
11 }
12
13 /**
14 * Elementor Page Builder cli tools.
15 */
16 class Command extends \WP_CLI_Command {
17
18 /**
19 * Flush the Elementor Page Builder CSS Cache.
20 *
21 * [--network]
22 * Flush CSS Cache for all the sites in the network.
23 *
24 * ## EXAMPLES
25 *
26 * 1. wp elementor flush-css
27 * - This will flush the CSS files for elementor page builder.
28 *
29 * 2. wp elementor flush-css --network
30 * - This will flush the CSS files for elementor page builder for all the sites in the network.
31 *
32 * @since 2.1.0
33 * @access public
34 * @alias flush-css
35 */
36 public function flush_css( $args, $assoc_args ) {
37 $network = ! empty( $assoc_args['network'] ) && is_multisite();
38
39 if ( $network ) {
40 /** @var \WP_Site[] $blogs */
41 $blogs = get_sites();
42
43 foreach ( $blogs as $keys => $blog ) {
44 // Cast $blog as an array instead of object
45 $blog_id = $blog->blog_id;
46
47 switch_to_blog( $blog_id );
48
49 Plugin::$instance->files_manager->clear_cache();
50
51 \WP_CLI::success( 'Flushed the Elementor CSS Cache for site - ' . get_option( 'home' ) );
52
53 restore_current_blog();
54 }
55 } else {
56 Plugin::$instance->files_manager->clear_cache();
57
58 \WP_CLI::success( 'Flushed the Elementor CSS Cache' );
59 }
60 }
61
62 /**
63 * Print system info powered by Elementor
64 *
65 * ## EXAMPLES
66 *
67 * 1. wp elementor system-info
68 * - This will print the System Info in JSON format
69 *
70 * @since 3.0.11
71 * @access public
72 * @alias system-info
73 */
74 public function system_info() {
75 echo wp_json_encode( \Elementor\Tracker::get_tracking_data() );
76 }
77
78 /**
79 * Replace old URLs with new URLs in all Elementor pages.
80 *
81 * ## EXAMPLES
82 *
83 * 1. wp elementor replace-urls <old> <new>
84 * - This will replace all <old> URLs with the <new> URL.
85 *
86 * @access public
87 * @alias replace-urls
88 */
89 public function replace_urls( $args, $assoc_args ) {
90 if ( empty( $args[0] ) ) {
91 \WP_CLI::error( 'Please set the `old` URL' );
92 }
93
94 if ( empty( $args[1] ) ) {
95 \WP_CLI::error( 'Please set the `new` URL' );
96 }
97
98 try {
99 $results = Utils::replace_urls( $args[0], $args[1] );
100 \WP_CLI::success( $results );
101 } catch ( \Exception $e ) {
102 \WP_CLI::error( $e->getMessage() );
103 }
104 }
105
106 /**
107 * Sync Elementor Library.
108 *
109 * ## EXAMPLES
110 *
111 * 1. wp elementor sync-library
112 * - This will sync the library with Elementor cloud library.
113 *
114 * @since 2.1.0
115 * @access public
116 * @alias sync-library
117 */
118 public function sync_library( $args, $assoc_args ) {
119 // TODO:
120 // \WP_CLI::warning( 'command is deprecated since 2.8.0 Please use: wp elementor library sync' );
121
122 $data = Api::get_library_data( true );
123
124 if ( empty( $data ) ) {
125 \WP_CLI::error( 'Cannot sync library.' );
126 }
127
128 \WP_CLI::success( 'Library has been synced.' );
129 }
130
131 /**
132 * Import template files to the Library.
133 *
134 * ## EXAMPLES
135 *
136 * 1. wp elementor import-library <file-path>
137 * - This will import a file or a zip of multiple files to the library.
138 *
139 * @since 2.1.0
140 * @access public
141 * @alias import-library
142 */
143 public function import_library( $args, $assoc_args ) {
144 // TODO:
145 // \WP_CLI::warning( 'command is deprecated since 2.8.0 Please use: wp elementor library import' );
146
147 if ( empty( $args[0] ) ) {
148 \WP_CLI::error( 'Please set file path.' );
149 }
150
151 /** @var Source_Local $source */
152 $source = Plugin::$instance->templates_manager->get_source( 'local' );
153
154 $imported_items = $source->import_template( basename( $args[0] ), $args[0] );
155
156 if ( is_wp_error( $imported_items ) ) {
157 \WP_CLI::error( $imported_items->get_error_message() );
158 }
159
160 \WP_CLI::success( count( $imported_items ) . ' item(s) has been imported.' );
161 }
162 }
163