PluginProbe
Elementor Website Builder – more than just a page builder / 3.0.2
Elementor Website Builder – more than just a page builder v3.0.2
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.0.2, at modules/wp-cli/command.php

148 lines 3.5 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 * Replace old URLs with new URLs in all Elementor pages.
64 *
65 * ## EXAMPLES
66 *
67 * 1. wp elementor replace-urls <old> <new>
68 * - This will replace all <old> URLs with the <new> URL.
69 *
70 * @access public
71 * @alias replace-urls
72 */
73
74 public function replace_urls( $args, $assoc_args ) {
75 if ( empty( $args[0] ) ) {
76 \WP_CLI::error( 'Please set the `old` URL' );
77 }
78
79 if ( empty( $args[1] ) ) {
80 \WP_CLI::error( 'Please set the `new` URL' );
81 }
82
83 try {
84 $results = Utils::replace_urls( $args[0], $args[1] );
85 \WP_CLI::success( $results );
86 } catch ( \Exception $e ) {
87 \WP_CLI::error( $e->getMessage() );
88 }
89 }
90
91 /**
92 * Sync Elementor Library.
93 *
94 * ## EXAMPLES
95 *
96 * 1. wp elementor sync-library
97 * - This will sync the library with Elementor cloud library.
98 *
99 * @since 2.1.0
100 * @access public
101 * @alias sync-library
102 */
103 public function sync_library( $args, $assoc_args ) {
104 // TODO:
105 // \WP_CLI::warning( 'command is deprecated since 2.8.0 Please use: wp elementor library sync' );
106
107 $data = Api::get_library_data( true );
108
109 if ( empty( $data ) ) {
110 \WP_CLI::error( 'Cannot sync library.' );
111 }
112
113 \WP_CLI::success( 'Library has been synced.' );
114 }
115
116 /**
117 * Import template files to the Library.
118 *
119 * ## EXAMPLES
120 *
121 * 1. wp elementor import-library <file-path>
122 * - This will import a file or a zip of multiple files to the library.
123 *
124 * @since 2.1.0
125 * @access public
126 * @alias import-library
127 */
128 public function import_library( $args, $assoc_args ) {
129 // TODO:
130 // \WP_CLI::warning( 'command is deprecated since 2.8.0 Please use: wp elementor library import' );
131
132 if ( empty( $args[0] ) ) {
133 \WP_CLI::error( 'Please set file path.' );
134 }
135
136 /** @var Source_Local $source */
137 $source = Plugin::$instance->templates_manager->get_source( 'local' );
138
139 $imported_items = $source->import_template( basename( $args[0] ), $args[0] );
140
141 if ( is_wp_error( $imported_items ) ) {
142 \WP_CLI::error( $imported_items->get_error_message() );
143 }
144
145 \WP_CLI::success( count( $imported_items ) . ' item(s) has been imported.' );
146 }
147 }
148