PluginProbe ʕ •ᴥ•ʔ
Elementor Website Builder – more than just a page builder / 3.18.0-beta1
Elementor Website Builder – more than just a page builder v3.18.0-beta1
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 4.0.6 4.0.5 4.0.4 4.0.3 3.22.0-dev1 4.0.0-beta3 3.22.0-dev2 4.0.0-beta4 3.22.0-dev3 4.0.0-beta5 3.22.0-dev4 4.0.0-dev1 3.22.0-dev5 4.0.0-dev2 3.22.0-dev6 4.0.0-dev3 3.22.1 4.0.0-dev4 3.22.2 4.0.0-dev5 3.22.3 4.0.1 3.23.0 4.0.2 3.23.0-beta1 3.23.0-beta2 3.23.0-beta3 3.23.0-beta4 3.23.0-beta5 3.23.0-beta6 3.23.0-dev1 3.23.0-dev2 3.23.0-dev3 3.23.0-dev4 3.23.0-dev5 3.23.0-dev6 3.23.1 3.23.2 3.23.3 3.23.4 3.24.0 3.24.0-beta1 3.24.0-beta2 3.24.0-beta3 3.24.0-dev1 3.24.0-dev2 3.24.0-dev3 3.24.1 3.24.2 3.24.3 3.24.4 3.24.5 3.24.6 3.24.7 3.24.8 3.25.0 3.25.0-beta1 3.25.0-beta2 3.25.0-beta3 3.25.0-dev1 3.25.0-dev2 3.25.0-dev3 3.25.1 3.25.10 3.25.11 3.25.2 3.25.3 3.25.4 3.25.5 3.25.6 3.25.7 3.25.8 3.25.9 3.26.0 3.26.0-beta1 3.26.0-beta2 3.26.0-beta3 3.26.0-beta4 3.26.0-beta5 3.26.0-dev1 3.26.0-dev2 3.26.0-dev3 3.26.0-dev4 3.26.0-dev5 3.26.1 3.26.2 3.26.3 3.26.4 3.26.5 3.27.0 3.27.0-beta1 3.27.0-beta2 3.27.0-dev1 3.27.0-dev2 3.27.1 3.27.2 3.27.3 3.27.4 3.27.5 3.27.6 3.27.7 3.28.0 3.28.0-beta1 3.28.0-beta2 3.28.0-beta3 3.28.0-dev1 3.28.0-dev2 3.28.0-dev3 3.28.1 3.28.2 3.28.3 3.28.4 3.29.0 3.29.0-beta1 trunk 3.29.0-beta2 3.0.0 3.29.0-beta3 3.0.1 3.29.0-beta4 3.0.10 3.29.0-dev1 3.0.11 3.29.0-dev2 3.0.12 3.29.0-dev3 3.0.13 3.29.0-dev4 3.0.14 3.29.1 3.0.15 3.29.2 3.0.16 3.3.0 3.0.2 3.3.1 3.0.3 3.30.0 3.0.4 3.30.0-beta1 3.0.5 3.30.0-beta2 3.0.6 3.30.0-beta3 3.0.7 3.30.0-dev1 3.0.8 3.30.0-dev2 3.0.8.1 3.30.0-dev3 3.0.9 3.30.1 3.1.0 3.30.2 3.1.0-beta1 3.30.3 3.1.0-beta2 3.30.4 3.1.0-beta3 3.31.0 3.1.0-beta4 3.31.0-beta1 3.1.0-dev1 3.31.0-beta2 3.1.0-dev2 3.31.0-dev1 3.1.0-dev3 3.31.0-dev2 3.1.1 3.31.1 3.1.2 3.31.2 3.1.3 3.31.3 3.1.4 3.31.4 3.10.0 3.31.5 3.10.0-dev1 3.32.0 3.10.1 3.32.0-beta1 3.10.2 3.32.0-beta2 3.11.0 3.32.0-beta3 3.11.0-beta1 3.32.0-dev1 3.11.0-beta2 3.32.0-dev2 3.11.0-beta3 3.32.0-dev3 3.11.0-dev1 3.32.1 3.11.0-dev2 3.32.2 3.11.0-dev3 3.32.3 3.11.1 3.32.4 3.11.2 3.32.5 3.11.3 3.33.0 3.11.4 3.33.0-beta1 3.11.5 3.33.0-beta2 3.12.0 3.33.0-beta3 3.12.1 3.33.0-beta4 3.12.2 3.33.0-dev1 3.13.0 3.33.0-dev2 3.13.0-beta1 3.33.0-dev3 3.13.0-beta2 3.33.0-dev4 3.13.0-beta3 3.33.1 3.13.0-dev3 3.33.2 3.13.0-dev4 3.33.3 3.13.1 3.33.4 3.13.2 3.33.5 3.13.3 3.33.6 3.13.4 3.34.0 3.14.0 3.34.0-beta1 3.14.0-beta1 3.34.0-beta2 3.14.0-beta2 3.34.0-beta3 3.14.0-beta3 3.34.0-dev1 3.14.0-beta4 3.34.0-dev2 3.14.0-beta5 3.34.1 3.14.1 3.34.2 3.15.0 3.34.3 3.15.1 3.34.4 3.15.2 3.35.0 3.15.3 3.35.0-beta1 3.16.0 3.35.0-beta2 3.16.0-beta3 3.35.0-beta3 3.16.0-beta4 3.35.0-beta4 3.16.0-dev1 3.35.0-dev1 3.16.0-dev2 3.35.0-dev2 3.16.1 3.35.0-dev3 3.16.2 3.35.0-dev4 3.16.3 3.35.1 3.16.4 3.35.2 3.16.5 3.35.3 3.16.6 3.35.4 3.17.0 3.35.5 3.17.0-dev2 3.35.6 3.17.0-dev3 3.35.7 3.17.0-dev4 3.35.8 3.17.1 3.35.9 3.17.2 3.4.0 3.17.3 3.4.0-dev7 3.18.0 3.4.0-dev8 3.18.0-beta1 3.4.0-dev9 3.18.0-beta2 3.4.1 3.18.0-beta3 3.4.2 3.18.0-beta4 3.4.3 3.18.0-dev1 3.4.4 3.18.1 3.4.5 3.18.2 3.4.6 3.18.3 3.4.7 3.19.0 3.4.8 3.19.0-beta1 3.5.0 3.19.0-beta2 3.5.0-beta1 3.19.0-beta3 3.5.0-beta2 3.19.0-beta4 3.5.0-beta3 3.19.0-beta5 3.5.0-beta4 3.19.0-beta6 3.5.0-beta5 3.19.0-dev1 3.5.0-beta7 3.19.0-dev2 3.5.0-beta8 3.19.0-dev3 3.5.0-dev8 3.19.0-dev4 3.5.0-dev9 3.19.0-dev5 3.5.1 3.19.0-dev6 3.5.2 3.19.1 3.5.3 3.19.2 3.5.4 3.19.3 3.5.5 3.19.4 3.5.6 3.2.0 3.6.0 3.2.1 3.6.0-beta1 3.2.2 3.6.0-beta2 3.2.3 3.6.0-beta3 3.2.4 3.6.0-beta4 3.2.5 3.6.0-beta5 3.20.0 3.6.0-dev1 3.20.0-beta1 3.6.0-dev10 3.20.0-beta2 3.6.1 3.20.0-beta3 3.6.2 3.20.0-beta4 3.6.3 3.20.0-dev1 3.6.4 3.20.0-dev2 3.6.5 3.20.0-dev3 3.6.6 3.20.0-dev4 3.6.7 3.20.1 3.6.8 3.20.2 3.7.0 3.20.3 3.7.0-beta1 3.20.4 3.7.0-beta2 3.21.0 3.7.0-beta3 3.21.0-beta1 3.7.0-beta4 3.21.0-beta2 3.7.0-dev1 3.21.0-beta3 3.7.1 3.21.0-dev1 3.7.2 3.21.0-dev2 3.7.3 3.21.0-dev3 3.7.4 3.21.1 3.7.5 3.21.2 3.7.6 3.21.3 3.7.7 3.21.4 3.7.8 3.21.5 3.8.0 3.21.6 3.8.0-beta1 3.21.7 3.8.0-beta2 3.21.8 3.8.0-beta3 3.22.0 3.8.1 3.22.0-beta1 3.9.0 3.22.0-beta2 3.9.1 3.22.0-beta3 3.9.2 3.22.0-beta4 4.0.0 3.22.0-beta5 4.0.0-beta1 3.22.0-beta6 4.0.0-beta2
elementor / modules / wp-cli / library.php
elementor / modules / wp-cli Last commit date
cli-logger.php 3 years ago command.php 3 years ago library.php 3 years ago module.php 3 years ago update.php 3 years ago
library.php
289 lines
1 <?php
2 namespace Elementor\Modules\WpCli;
3
4 use Elementor\Api;
5 use Elementor\Plugin;
6 use Elementor\TemplateLibrary\Source_Local;
7
8 if ( ! defined( 'ABSPATH' ) ) {
9 exit; // Exit if accessed directly
10 }
11
12 /**
13 * Elementor Page Builder cli tools.
14 */
15 class Library extends \WP_CLI_Command {
16
17 /**
18 * Sync Elementor Library.
19 *
20 * [--network]
21 * Sync library in all the sites in the network.
22 *
23 * [--force]
24 * Force sync even if it's looks like that the library is already up to date.
25 *
26 * ## EXAMPLES
27 *
28 * 1. wp elementor library sync
29 * - This will sync the library with Elementor cloud library.
30 *
31 * 2. wp elementor library sync --force
32 * - This will sync the library with Elementor cloud even if it's looks like that the library is already up to date.
33 *
34 * 3. wp elementor library sync --network
35 * - This will sync the library with Elementor cloud library for each site in the network if needed.
36 *
37 * @since 2.8.0
38 * @access public
39 */
40 public function sync( $args, $assoc_args ) {
41 $network = isset( $assoc_args['network'] ) && is_multisite();
42
43 if ( $network ) {
44 $blog_ids = get_sites( [
45 'fields' => 'ids',
46 'number' => 0,
47 ] );
48
49 foreach ( $blog_ids as $blog_id ) {
50 switch_to_blog( $blog_id );
51
52 \WP_CLI::line( 'Site #' . $blog_id . ' - ' . get_option( 'blogname' ) );
53
54 $this->do_sync( isset( $assoc_args['force'] ) );
55
56 \WP_CLI::success( 'Done! - ' . get_option( 'home' ) );
57
58 restore_current_blog();
59 }
60 } else {
61 $this->do_sync( isset( $assoc_args['force'] ) );
62 \WP_CLI::success( 'Done!' );
63 }
64 }
65
66 /**
67 * Import template files to the Library.
68 *
69 * [--returnType]
70 * Forms of output. Possible values are 'ids', 'info'.
71 * if this parameter won't be specified, the import info will be output.
72 *
73 * ## EXAMPLES
74 *
75 * 1. wp elementor library import <file-path>
76 * - This will import a file or a zip of multiple files to the library.
77 * - file-path can be a path or url.
78 *
79 * 2. wp elementor library import <file-path> --returnType=info,ids
80 *
81 * @param $args
82 * @param $assoc_args
83 *
84 * @since 2.8.0
85 * @access public
86 */
87 public function import( $args, $assoc_args ) {
88 if ( empty( $args[0] ) ) {
89 \WP_CLI::error( 'Please set file path.' );
90 }
91
92 $file = $args[0];
93 $imported_items_ids = [];
94 $return_type = \WP_CLI\Utils\get_flag_value( $assoc_args, 'returnType', 'info' );
95
96 /** @var Source_Local $source */
97 $source = Plugin::$instance->templates_manager->get_source( 'local' );
98
99 if ( filter_var( $file, FILTER_VALIDATE_URL ) ) {
100 $tmp_path = download_url( $file );
101 if ( is_wp_error( $tmp_path ) ) {
102 \WP_CLI::error( $tmp_path->get_error_message() );
103 }
104 $file = $tmp_path;
105 }
106
107 $imported_items = $source->import_template( basename( $file ), $file );
108
109 if ( is_wp_error( $imported_items ) ) {
110 \WP_CLI::error( $imported_items->get_error_message() );
111 }
112
113 foreach ( $imported_items as $item ) {
114 $imported_items_ids[] = $item['template_id'];
115 }
116 $imported_items_ids = implode( ',', $imported_items_ids );
117
118 if ( 'ids' === $return_type ) {
119 \WP_CLI::line( $imported_items_ids );
120 } else {
121 \WP_CLI::success( count( $imported_items ) . ' item(s) has been imported.' );
122 }
123
124 if ( isset( $tmp_path ) ) {
125 // Remove the temporary file, now that we're done with it.
126 Plugin::$instance->uploads_manager->remove_file_or_dir( $file );
127 }
128 }
129
130 /**
131 * Import all template files from a directory.
132 *
133 * ## EXAMPLES
134 *
135 * 1. wp elementor library import-dir <file-path>
136 * - This will import all JSON files from <file-path>
137 *
138 * @param $args
139 *
140 * @since 3.4.7
141 * @access public
142 * @alias import-dir
143 */
144 public function import_dir( $args ) {
145 if ( empty( $args[0] ) ) {
146 \WP_CLI::error( 'Please set dir path.' );
147 }
148
149 $dir = $args[0];
150
151 if ( ! file_exists( $dir ) ) {
152 \WP_CLI::error( "Dir `{$dir}` not found." );
153 }
154
155 $files = glob( $dir . '/*.json' );
156
157 if ( empty( $files ) ) {
158 \WP_CLI::error( 'Files not found.' );
159 }
160
161 /** @var Source_Local $source */
162 $source = Plugin::$instance->templates_manager->get_source( 'local' );
163
164 $succeed = [];
165 $errors = [];
166
167 foreach ( $files as $file ) {
168 $basename = basename( $file );
169
170 if ( ! file_exists( $file ) ) {
171 $errors[ $basename ] = $file . ' file not found.';
172 continue;
173 }
174
175 $imported_items = $source->import_template( $basename, $file );
176
177 if ( is_wp_error( $imported_items ) ) {
178 $errors[ $basename ] = $imported_items->get_error_message();
179 } else {
180 $succeed[ $basename ] = true;
181 }
182 }
183
184 $succeed_message = count( $succeed ) . ' item(s) has been imported.';
185
186 if ( ! empty( $errors ) ) {
187 $error_message = var_export( $errors, 1 );
188 if ( ! empty( $succeed ) ) {
189 $error_message = $succeed_message . ' ' . count( $errors ) . ' has errors: ' . $error_message;
190 }
191 \WP_CLI::error( $error_message );
192 }
193
194 \WP_CLI::success( $succeed_message );
195 }
196
197 /**
198 * Connect site to Elementor Library.
199 * (Network is not supported)
200 *
201 * --user
202 * The user to connect <id|login|email>
203 *
204 * --token
205 * A connect token from Elementor Account Dashboard.
206 *
207 * ## EXAMPLES
208 *
209 * 1. wp elementor library connect --user=admin --token=<connect-cli-token>
210 * - This will connect the admin to Elementor library.
211 *
212 * @param $args
213 * @param $assoc_args
214 *
215 * @since 2.8.0
216 * @access public
217 */
218 public function connect( $args, $assoc_args ) {
219 if ( ! get_current_user_id() ) {
220 \WP_CLI::error( 'Please set user to connect (--user=<id|login|email>).' );
221 }
222
223 if ( empty( $assoc_args['token'] ) ) {
224 \WP_CLI::error( 'Please set connect token.' );
225 }
226
227 $_REQUEST['mode'] = 'cli';
228 $_REQUEST['token'] = $assoc_args['token'];
229
230 $app = $this->get_library_app();
231
232 $app->set_auth_mode( 'cli' );
233
234 $app->action_authorize();
235
236 $app->action_get_token();
237 }
238
239 /**
240 * Disconnect site from Elementor Library.
241 *
242 * --user
243 * The user to disconnect <id|login|email>
244 *
245 * ## EXAMPLES
246 *
247 * 1. wp elementor library disconnect --user=admin
248 * - This will disconnect the admin from Elementor library.
249 *
250 * @param $args
251 * @param $assoc_args
252 *
253 * @since 2.8.0
254 * @access public
255 */
256 public function disconnect() {
257 if ( ! get_current_user_id() ) {
258 \WP_CLI::error( 'Please set user to connect (--user=<id|login|email>).' );
259 }
260
261 $_REQUEST['mode'] = 'cli';
262
263 $this->get_library_app()->action_disconnect();
264 }
265
266 private function do_sync() {
267 $data = Api::get_library_data( true );
268
269 if ( empty( $data ) ) {
270 \WP_CLI::error( 'Cannot sync library.' );
271 }
272 }
273
274 /**
275 * @return \Elementor\Core\Common\Modules\Connect\Apps\Library
276 */
277 private function get_library_app() {
278 $connect = Plugin::$instance->common->get_component( 'connect' );
279 $app = $connect->get_app( 'library' );
280 // Before init.
281 if ( ! $app ) {
282 $connect->init();
283 $app = $connect->get_app( 'library' );
284 }
285
286 return $app;
287 }
288 }
289