| @@ -5,9 +5,9 @@ | ||
| 5 | 5 | use Elementor\Plugin; |
| 6 | 6 | use Elementor\TemplateLibrary\Source_Local; |
| 7 | 7 | |
| 8 | 8 | if ( ! defined( 'ABSPATH' ) ) { |
| 9 | - exit; // Exit if accessed directly. | |
| 9 | + exit; // Exit if accessed directly | |
| 10 | 10 | } |
| 11 | 11 | |
| 12 | 12 | /** |
| 13 | 13 | * Elementor Page Builder cli tools. |
| @@ -65,20 +65,13 @@ | ||
| 65 | 65 | |
| 66 | 66 | /** |
| 67 | 67 | * Import template files to the Library. |
| 68 | 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 | 69 | * ## EXAMPLES |
| 74 | 70 | * |
| 75 | 71 | * 1. wp elementor library import <file-path> |
| 76 | 72 | * - This will import a file or a zip of multiple files to the library. |
| 77 | - * - file-path can be a path or url. | |
| 78 | 73 | * |
| 79 | - * 2. wp elementor library import <file-path> --returnType=info,ids | |
| 80 | - * | |
| 81 | 74 | * @param $args |
| 82 | 75 | * @param $assoc_args |
| 83 | 76 | * |
| 84 | 77 | * @since 2.8.0 |
| @@ -83,28 +76,18 @@ | ||
| 83 | 76 | * |
| 84 | 77 | * @since 2.8.0 |
| 85 | 78 | * @access public |
| 86 | 79 | */ |
| 87 | - public function import( $args, $assoc_args ) { | |
| 80 | + public function import( $args ) { | |
| 88 | 81 | if ( empty( $args[0] ) ) { |
| 89 | 82 | \WP_CLI::error( 'Please set file path.' ); |
| 90 | 83 | } |
| 91 | 84 | |
| 92 | 85 | $file = $args[0]; |
| 93 | - $imported_items_ids = []; | |
| 94 | - $return_type = \WP_CLI\Utils\get_flag_value( $assoc_args, 'returnType', 'info' ); | |
| 95 | 86 | |
| 96 | 87 | /** @var Source_Local $source */ |
| 97 | 88 | $source = Plugin::$instance->templates_manager->get_source( 'local' ); |
| 98 | 89 | |
| 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 | 90 | $imported_items = $source->import_template( basename( $file ), $file ); |
| 108 | 91 | |
| 109 | 92 | if ( is_wp_error( $imported_items ) ) { |
| 110 | 93 | \WP_CLI::error( $imported_items->get_error_message() ); |
| @@ -109,24 +92,11 @@ | ||
| 109 | 92 | if ( is_wp_error( $imported_items ) ) { |
| 110 | 93 | \WP_CLI::error( $imported_items->get_error_message() ); |
| 111 | 94 | } |
| 112 | 95 | |
| 113 | - foreach ( $imported_items as $item ) { | |
| 114 | - $imported_items_ids[] = $item['template_id']; | |
| 115 | - } | |
| 116 | - $imported_items_ids = implode( ',', $imported_items_ids ); | |
| 96 | + \WP_CLI::success( count( $imported_items ) . ' item(s) has been imported.' ); | |
| 97 | + } | |
| 117 | 98 | |
| 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 | 99 | |
| 130 | 100 | /** |
| 131 | 101 | * Import all template files from a directory. |
| 132 | 102 | * |