| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137 |
- <?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.
- *
- * ## 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.
- *
- * @alias flush-css
- */
- public function flush_css( $args, $assoc_args ) {
- $network = ! empty( $assoc_args['network'] ) && is_multisite();
- if ( $network ) {
- /** @var \WP_Site[] $blogs */
- $blogs = get_sites();
- foreach ( $blogs as $keys => $blog ) {
- // Cast $blog as an array instead of object
- $blog_id = $blog->blog_id;
- switch_to_blog( $blog_id );
- Plugin::$instance->files_manager->clear_cache();
- \WP_CLI::success( 'Flushed the Elementor CSS Cache for site - ' . get_option( 'home' ) );
- restore_current_blog();
- }
- } else {
- Plugin::$instance->files_manager->clear_cache();
- \WP_CLI::success( 'Flushed the Elementor CSS Cache' );
- }
- }
- /**
- * Replace old URLs with new URLs in all Elementor pages.
- *
- * ## EXAMPLES
- *
- * 1. wp elementor search-replace <old> <new>
- * - This will replace all <old> URLs with the <new> URL.
- *
- * @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 ) {
- \WP_CLI::error( $e->getMessage() );
- }
- }
- /**
- * Sync Elementor Library.
- *
- * ## EXAMPLES
- *
- * 1. wp elementor sync-library
- * - This will sync the library with Elementor cloud library.
- *
- * @alias sync-library
- */
- public function sync_library( $args, $assoc_args ) {
- $data = Api::get_library_data( true );
- 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.
- *
- * @alias import-library
- */
- public function import_library( $args, $assoc_args ) {
- if ( empty( $args[0] ) ) {
- \WP_CLI::error( 'Please set file path.' );
- }
- if ( ! is_readable( $args[0] ) ) {
- \WP_CLI::error( 'Cannot read file.' );
- }
- /** @var Source_Local $source */
- $source = Plugin::$instance->templates_manager->get_source( 'local' );
- $imported_items = $source->import_template( basename( $args[0] ), $args[0] );
- if ( empty( $imported_items ) ) {
- \WP_CLI::error( 'Cannot import.' );
- }
- \WP_CLI::success( count( $imported_items ) . ' item(s) has been imported.' );
- }
- }
|