| @@ -11,12 +11,11 @@ | ||
| 11 | 11 | use Elementor\Plugin; |
| 12 | 12 | use Elementor\Tools; |
| 13 | 13 | use Elementor\Utils as ElementorUtils; |
| 14 | 14 | use Elementor\App\Modules\ImportExport\Utils as ImportExportUtils; |
| 15 | -use Elementor\Modules\CloudKitLibrary\Module as CloudKitLibrary; | |
| 16 | 15 | |
| 17 | 16 | if ( ! defined( 'ABSPATH' ) ) { |
| 18 | - exit; // Exit if accessed directly. | |
| 17 | + exit; // Exit if accessed directly | |
| 19 | 18 | } |
| 20 | 19 | |
| 21 | 20 | /** |
| 22 | 21 | * Import Export Module |
| @@ -31,26 +30,16 @@ | ||
| 31 | 30 | const UPLOAD_TRIGGER_KEY = 'elementor_upload_kit'; |
| 32 | 31 | |
| 33 | 32 | const IMPORT_TRIGGER_KEY = 'elementor_import_kit'; |
| 34 | 33 | |
| 35 | - const IMPORT_RUNNER_TRIGGER_KEY = 'elementor_import_kit__runner'; | |
| 36 | - | |
| 37 | 34 | const REFERRER_KIT_LIBRARY = 'kit-library'; |
| 38 | 35 | |
| 39 | 36 | const REFERRER_LOCAL = 'local'; |
| 40 | 37 | |
| 41 | - const REFERRER_CLOUD = 'cloud'; | |
| 38 | + const PERMISSIONS_ERROR_KEY = 'plugin-installation-permissions-error'; | |
| 42 | 39 | |
| 43 | - const PLUGIN_PERMISSIONS_ERROR_KEY = 'plugin-installation-permissions-error'; | |
| 44 | - | |
| 45 | - const KIT_LIBRARY_ERROR_KEY = 'invalid-kit-library-zip-error'; | |
| 46 | - | |
| 47 | 40 | const NO_WRITE_PERMISSIONS_KEY = 'no-write-permissions'; |
| 48 | 41 | |
| 49 | - const THIRD_PARTY_ERROR = 'third-party-error'; | |
| 50 | - | |
| 51 | - const DOMDOCUMENT_MISSING = 'domdocument-missing'; | |
| 52 | - | |
| 53 | 42 | const OPTION_KEY_ELEMENTOR_IMPORT_SESSIONS = 'elementor_import_sessions'; |
| 54 | 43 | |
| 55 | 44 | const OPTION_KEY_ELEMENTOR_REVERT_SESSIONS = 'elementor_revert_sessions'; |
| 56 | 45 | |
| @@ -56,11 +45,8 @@ | ||
| 56 | 45 | |
| 57 | 46 | const META_KEY_ELEMENTOR_IMPORT_SESSION_ID = '_elementor_import_session_id'; |
| 58 | 47 | |
| 59 | 48 | const META_KEY_ELEMENTOR_EDIT_MODE = '_elementor_edit_mode'; |
| 60 | - const IMPORT_PLUGINS_ACTION = 'import-plugins'; | |
| 61 | - const EXPORT_SOURCE_CLOUD = 'cloud'; | |
| 62 | - const EXPORT_SOURCE_FILE = 'file'; | |
| 63 | 49 | |
| 64 | 50 | /** |
| 65 | 51 | * Assigning the export process to a property, so we can use the process from outside the class. |
| 66 | 52 | * |
| @@ -100,10 +86,8 @@ | ||
| 100 | 86 | \WP_CLI::add_command( 'elementor kit', WP_CLI::class ); |
| 101 | 87 | } |
| 102 | 88 | |
| 103 | 89 | ( new Usage() )->register(); |
| 104 | - | |
| 105 | - $this->revert = new Revert(); | |
| 106 | 90 | } |
| 107 | 91 | |
| 108 | 92 | public function get_init_settings() { |
| 109 | 93 | if ( ! Plugin::$instance->app->is_current() ) { |
| @@ -117,12 +101,12 @@ | ||
| 117 | 101 | * Register the import/export tab in elementor tools. |
| 118 | 102 | */ |
| 119 | 103 | public function register_settings_tab( Tools $tools ) { |
| 120 | 104 | $tools->add_tab( 'import-export-kit', [ |
| 121 | - 'label' => esc_html__( 'Website Templates', 'elementor' ), | |
| 105 | + 'label' => esc_html__( 'Import / Export Kit', 'elementor' ), | |
| 122 | 106 | 'sections' => [ |
| 123 | 107 | 'intro' => [ |
| 124 | - 'label' => esc_html__( 'Website Templates', 'elementor' ), | |
| 108 | + 'label' => esc_html__( 'Template Kits', 'elementor' ), | |
| 125 | 109 | 'callback' => function() { |
| 126 | 110 | $this->render_import_export_tab_content(); |
| 127 | 111 | }, |
| 128 | 112 | 'fields' => [], |
| @@ -134,39 +118,45 @@ | ||
| 134 | 118 | /** |
| 135 | 119 | * Render the import/export tab content. |
| 136 | 120 | */ |
| 137 | 121 | private function render_import_export_tab_content() { |
| 138 | - $is_cloud_kits_available = CloudKitLibrary::get_app()->check_eligibility()['is_eligible']; | |
| 122 | + $intro_text_link = sprintf( '<a href="https://go.elementor.com/wp-dash-import-export-general/" target="_blank">%s</a>', esc_html__( 'Learn more', 'elementor' ) ); | |
| 139 | 123 | |
| 124 | + $intro_text = sprintf( | |
| 125 | + /* translators: 1: New line break, 2: Learn More link. */ | |
| 126 | + __( 'Design sites faster with a template kit that contains some or all components of a complete site, like templates, content & site settings.%1$sYou can import a kit and apply it to your site, or export the elements from this site to be used anywhere else. %2$s', 'elementor' ), | |
| 127 | + '<br>', | |
| 128 | + $intro_text_link | |
| 129 | + ); | |
| 130 | + | |
| 140 | 131 | $content_data = [ |
| 141 | 132 | 'export' => [ |
| 142 | - 'title' => esc_html__( 'Export this website', 'elementor' ), | |
| 133 | + 'title' => esc_html__( 'Export a Template Kit', 'elementor' ), | |
| 143 | 134 | 'button' => [ |
| 144 | 135 | 'url' => Plugin::$instance->app->get_base_url() . '#/export', |
| 145 | - 'text' => esc_html__( 'Export', 'elementor' ), | |
| 146 | - 'id' => 'elementor-import-export__export', | |
| 136 | + 'text' => esc_html__( 'Start Export', 'elementor' ), | |
| 147 | 137 | ], |
| 148 | - 'description' => esc_html__( 'You can download this website as a .zip file, or upload it to the library.', 'elementor' ), | |
| 138 | + 'description' => esc_html__( 'Bundle your whole site - or just some of its elements - to be used for another website.', 'elementor' ), | |
| 139 | + 'link' => [ | |
| 140 | + 'url' => 'https://go.elementor.com/wp-dash-import-export-export-flow/', | |
| 141 | + 'text' => esc_html__( 'Learn More', 'elementor' ), | |
| 142 | + ], | |
| 149 | 143 | ], |
| 150 | 144 | 'import' => [ |
| 151 | - 'title' => esc_html__( 'Import website templates', 'elementor' ), | |
| 145 | + 'title' => esc_html__( 'Import a Template Kit', 'elementor' ), | |
| 152 | 146 | 'button' => [ |
| 153 | 147 | 'url' => Plugin::$instance->app->get_base_url() . '#/import', |
| 154 | - 'text' => esc_html__( 'Import', 'elementor' ), | |
| 155 | - 'id' => 'elementor-import-export__import', | |
| 148 | + 'text' => esc_html__( 'Start Import', 'elementor' ), | |
| 156 | 149 | ], |
| 157 | - 'description' => esc_html__( 'You can import design and settings from a .zip file or choose from the library.', 'elementor' ), | |
| 150 | + 'description' => esc_html__( 'Apply the design and settings of another site to this one.', 'elementor' ), | |
| 151 | + 'link' => [ | |
| 152 | + 'url' => 'https://go.elementor.com/wp-dash-import-export-import-flow/', | |
| 153 | + 'text' => esc_html__( 'Learn More', 'elementor' ), | |
| 154 | + ], | |
| 158 | 155 | ], |
| 159 | 156 | ]; |
| 160 | 157 | |
| 161 | - if ( $is_cloud_kits_available ) { | |
| 162 | - $content_data['import']['button_secondary'] = [ | |
| 163 | - 'url' => Plugin::$instance->app->get_base_url() . '#/kit-library/cloud', | |
| 164 | - 'text' => esc_html__( 'Import from library', 'elementor' ), | |
| 165 | - 'id' => 'elementor-import-export__import_from_library', | |
| 166 | - ]; | |
| 167 | - } | |
| 168 | - | |
| 158 | + $this->revert = new Revert(); | |
| 169 | 159 | $last_imported_kit = $this->revert->get_last_import_session(); |
| 170 | 160 | $penultimate_imported_kit = $this->revert->get_penultimate_import_session(); |
| 171 | 161 | |
| 172 | 162 | $user_date_format = get_option( 'date_format' ); |
| @@ -177,21 +167,19 @@ | ||
| 177 | 167 | |
| 178 | 168 | if ( $should_show_revert_section ) { |
| 179 | 169 | if ( ! empty( $penultimate_imported_kit ) ) { |
| 180 | 170 | $revert_text = sprintf( |
| 181 | - /* translators: 1: Last imported kit title, 2: Last imported kit date, 3: Line break <br>, 4: Penultimate imported kit title, 5: Penultimate imported kit date. */ | |
| 182 | 171 | esc_html__( 'Remove all the content and site settings that came with "%1$s" on %2$s %3$s and revert to the site setting that came with "%4$s" on %5$s.', 'elementor' ), |
| 183 | - ! empty( $last_imported_kit['kit_title'] ) ? $last_imported_kit['kit_title'] : esc_html__( 'imported kit', 'elementor' ), | |
| 172 | + ! empty( $last_imported_kit['kit_name'] ) ? $last_imported_kit['kit_name'] : esc_html__( 'imported kit', 'elementor' ), | |
| 184 | 173 | gmdate( $date_format, $last_imported_kit['start_timestamp'] ), |
| 185 | 174 | '<br>', |
| 186 | - ! empty( $penultimate_imported_kit['kit_title'] ) ? $penultimate_imported_kit['kit_title'] : esc_html__( 'imported kit', 'elementor' ), | |
| 175 | + ! empty( $penultimate_imported_kit['kit_name'] ) ? $penultimate_imported_kit['kit_name'] : esc_html__( 'imported kit', 'elementor' ), | |
| 187 | 176 | gmdate( $date_format, $penultimate_imported_kit['start_timestamp'] ) |
| 188 | 177 | ); |
| 189 | 178 | } else { |
| 190 | 179 | $revert_text = sprintf( |
| 191 | - /* translators: 1: Last imported kit title, 2: Last imported kit date, 3: Line break <br>. */ | |
| 192 | 180 | esc_html__( 'Remove all the content and site settings that came with "%1$s" on %2$s.%3$s Your original site settings will be restored.', 'elementor' ), |
| 193 | - ! empty( $last_imported_kit['kit_title'] ) ? $last_imported_kit['kit_title'] : esc_html__( 'imported kit', 'elementor' ), | |
| 181 | + ! empty( $last_imported_kit['kit_name'] ) ? $last_imported_kit['kit_name'] : esc_html__( 'imported kit', 'elementor' ), | |
| 194 | 182 | gmdate( $date_format, $last_imported_kit['start_timestamp'] ), |
| 195 | 183 | '<br>' |
| 196 | 184 | ); |
| 197 | 185 | } |
| @@ -198,29 +186,29 @@ | ||
| 198 | 186 | } |
| 199 | 187 | ?> |
| 200 | 188 | |
| 201 | 189 | <div class="tab-import-export-kit__content"> |
| 202 | - <p class="tab-import-export-kit__info"> | |
| 203 | - <?php | |
| 204 | - printf( | |
| 205 | - '%1$s <a href="https://go.elementor.com/wp-dash-import-export-general/" target="_blank">%2$s</a>', | |
| 206 | - esc_html__( 'Here’s where you can export this website as a .zip file, upload it to the cloud, or start the process of applying an existing template to your site.', 'elementor' ), | |
| 207 | - esc_html__( 'Learn more', 'elementor' ), | |
| 208 | - ); | |
| 209 | - ?> | |
| 210 | - </p> | |
| 190 | + <p class="tab-import-export-kit__info"><?php ElementorUtils::print_unescaped_internal_string( $intro_text ); ?></p> | |
| 211 | 191 | |
| 212 | 192 | <div class="tab-import-export-kit__wrapper"> |
| 213 | - <?php foreach ( $content_data as $data ) { | |
| 214 | - $this->print_item_content( $data ); | |
| 215 | - } ?> | |
| 193 | + <?php foreach ( $content_data as $data ) { ?> | |
| 194 | + <div class="tab-import-export-kit__container"> | |
| 195 | + <div class="tab-import-export-kit__box"> | |
| 196 | + <h2><?php ElementorUtils::print_unescaped_internal_string( $data['title'] ); ?></h2> | |
| 197 | + <a href="<?php ElementorUtils::print_unescaped_internal_string( $data['button']['url'] ); ?>" class="elementor-button elementor-button-success"> | |
| 198 | + <?php ElementorUtils::print_unescaped_internal_string( $data['button']['text'] ); ?> | |
| 199 | + </a> | |
| 200 | + </div> | |
| 201 | + <p><?php ElementorUtils::print_unescaped_internal_string( $data['description'] ); ?></p> | |
| 202 | + <a href="<?php ElementorUtils::print_unescaped_internal_string( $data['link']['url'] ); ?>" target="_blank"><?php ElementorUtils::print_unescaped_internal_string( $data['link']['text'] ); ?></a> | |
| 203 | + </div> | |
| 204 | + <?php } ?> | |
| 216 | 205 | </div> |
| 217 | 206 | |
| 218 | 207 | <?php |
| 219 | 208 | if ( $should_show_revert_section ) { |
| 220 | - | |
| 221 | 209 | $link_attributes = [ |
| 222 | - 'href' => $this->get_revert_href(), | |
| 210 | + 'href' => wp_nonce_url( admin_url( 'admin-post.php?action=elementor_revert_kit' ), 'elementor_revert_kit' ), | |
| 223 | 211 | 'id' => 'elementor-import-export__revert_kit', |
| 224 | 212 | 'class' => 'button', |
| 225 | 213 | ]; |
| 226 | 214 | ?> |
| @@ -225,16 +213,15 @@ | ||
| 225 | 213 | ]; |
| 226 | 214 | ?> |
| 227 | 215 | <div class="tab-import-export-kit__revert"> |
| 228 | 216 | <h2> |
| 229 | - <?php echo esc_html__( 'Remove the most recent Website Template', 'elementor' ); ?> | |
| 217 | + <?php ElementorUtils::print_unescaped_internal_string( esc_html__( 'Remove the most recent Kit', 'elementor' ) ); ?> | |
| 230 | 218 | </h2> |
| 231 | 219 | <p class="tab-import-export-kit__info"> |
| 232 | 220 | <?php ElementorUtils::print_unescaped_internal_string( $revert_text ); ?> |
| 233 | 221 | </p> |
| 234 | - <?php $this->render_last_kit_thumbnail( $last_imported_kit ); ?> | |
| 235 | 222 | <a <?php ElementorUtils::print_html_attributes( $link_attributes ); ?> > |
| 236 | - <?php echo esc_html__( 'Remove Website Template', 'elementor' ); ?> | |
| 223 | + <?php ElementorUtils::print_unescaped_internal_string( esc_html__( 'Remove Kit', 'elementor' ) ); ?> | |
| 237 | 224 | </a> |
| 238 | 225 | </div> |
| 239 | 226 | <?php } ?> |
| 240 | 227 | </div> |
| @@ -240,87 +227,9 @@ | ||
| 240 | 227 | </div> |
| 241 | 228 | <?php |
| 242 | 229 | } |
| 243 | 230 | |
| 244 | - private function print_item_content( $data ) { | |
| 245 | - ?> | |
| 246 | - <div class="tab-import-export-kit__container"> | |
| 247 | - <div class="tab-import-export-kit__box"> | |
| 248 | - <h2><?php ElementorUtils::print_unescaped_internal_string( $data['title'] ); ?></h2> | |
| 249 | - </div> | |
| 250 | - <p class="description"><?php ElementorUtils::print_unescaped_internal_string( $data['description'] ); ?></p> | |
| 251 | - | |
| 252 | - <?php if ( ! empty( $data['link'] ) ) : ?> | |
| 253 | - <a href="<?php ElementorUtils::print_unescaped_internal_string( $data['link']['url'] ); ?>" target="_blank"><?php ElementorUtils::print_unescaped_internal_string( $data['link']['text'] ); ?></a> | |
| 254 | - <?php endif; ?> | |
| 255 | - <div class="tab-import-export-kit__box action-buttons"> | |
| 256 | - <?php if ( ! empty( $data['button_secondary'] ) ) : ?> | |
| 257 | - <a href="<?php ElementorUtils::print_unescaped_internal_string( $data['button_secondary']['url'] ); ?>" class="elementor-button e-btn-txt e-btn-txt-border"> | |
| 258 | - <?php ElementorUtils::print_unescaped_internal_string( $data['button_secondary']['text'] ); ?> | |
| 259 | - </a> | |
| 260 | - <?php endif; ?> | |
| 261 | - <a <?php ElementorUtils::print_html_attributes( [ 'id' => $data['button']['id'] ] ); ?> href="<?php ElementorUtils::print_unescaped_internal_string( $data['button']['url'] ); ?>" class="elementor-button e-primary"> | |
| 262 | - <?php ElementorUtils::print_unescaped_internal_string( $data['button']['text'] ); ?> | |
| 263 | - </a> | |
| 264 | - </div> | |
| 265 | - </div> | |
| 266 | - <?php | |
| 267 | - } | |
| 268 | - | |
| 269 | - private function get_revert_href(): string { | |
| 270 | - $admin_post_url = admin_url( 'admin-post.php?action=elementor_revert_kit' ); | |
| 271 | - $nonced_admin_post_url = wp_nonce_url( $admin_post_url, 'elementor_revert_kit' ); | |
| 272 | - return $this->maybe_add_referrer_param( $nonced_admin_post_url ); | |
| 273 | - } | |
| 274 | - | |
| 275 | 231 | /** |
| 276 | - * Checks if referred by a kit and adds the referrer ID to the href | |
| 277 | - * | |
| 278 | - * @param string $href | |
| 279 | - * | |
| 280 | - * @return string | |
| 281 | - */ | |
| 282 | - private function maybe_add_referrer_param( string $href ): string { | |
| 283 | - $param_name = 'referrer_kit'; | |
| 284 | - | |
| 285 | - if ( empty( $_GET[ $param_name ] ) ) { | |
| 286 | - return $href; | |
| 287 | - } | |
| 288 | - | |
| 289 | - return add_query_arg( $param_name, sanitize_key( $_GET[ $param_name ] ), $href ); | |
| 290 | - } | |
| 291 | - | |
| 292 | - /** | |
| 293 | - * Render the last kit thumbnail if exists | |
| 294 | - * | |
| 295 | - * @param $last_imported_kit | |
| 296 | - * | |
| 297 | - * @return void | |
| 298 | - */ | |
| 299 | - private function render_last_kit_thumbnail( $last_imported_kit ) { | |
| 300 | - if ( empty( $last_imported_kit['kit_thumbnail'] ) ) { | |
| 301 | - return; | |
| 302 | - } | |
| 303 | - | |
| 304 | - ?> | |
| 305 | - <div class="tab-import-export-kit__kit-item-row"> | |
| 306 | - <article class="tab-import-export-kit__kit-item"> | |
| 307 | - <header> | |
| 308 | - <h3> | |
| 309 | - <?php echo esc_html( $last_imported_kit['kit_title'] ); ?> | |
| 310 | - </h3> | |
| 311 | - </header> | |
| 312 | - <img | |
| 313 | - src="<?php echo esc_url( $last_imported_kit['kit_thumbnail'] ); ?>" | |
| 314 | - alt="<?php echo esc_attr( $last_imported_kit['kit_title'] ); ?>" | |
| 315 | - loading="lazy" | |
| 316 | - > | |
| 317 | - </article> | |
| 318 | - </div> | |
| 319 | - <?php | |
| 320 | - } | |
| 321 | - | |
| 322 | - /** | |
| 323 | 232 | * Upload a kit zip file and get the kit data. |
| 324 | 233 | * |
| 325 | 234 | * Assigning the Import process to the 'import' property, |
| 326 | 235 | * so it will be available to use in different places such as: WP_Cli, Pro, etc. |
| @@ -326,19 +235,15 @@ | ||
| 326 | 235 | * so it will be available to use in different places such as: WP_Cli, Pro, etc. |
| 327 | 236 | * |
| 328 | 237 | * @param string $file Path to the file. |
| 329 | 238 | * @param string $referrer Referrer of the file 'local' or 'kit-library'. |
| 330 | - * @param string $kit_id | |
| 331 | 239 | * @return array |
| 332 | - * @throws \Exception If export validation fails or processing errors occur. | |
| 240 | + * @throws \Exception | |
| 333 | 241 | */ |
| 334 | - public function upload_kit( $file, $referrer, $kit_id = null ) { | |
| 242 | + public function upload_kit( $file, $referrer ) { | |
| 335 | 243 | $this->ensure_writing_permissions(); |
| 336 | 244 | |
| 337 | - $this->import = new Import( $file, [ | |
| 338 | - 'referrer' => $referrer, | |
| 339 | - 'id' => $kit_id, | |
| 340 | - ] ); | |
| 245 | + $this->import = new Import( $file, [ 'referrer' => $referrer ] ); | |
| 341 | 246 | |
| 342 | 247 | return [ |
| 343 | 248 | 'session' => $this->import->get_session_id(), |
| 344 | 249 | 'manifest' => $this->import->get_manifest(), |
| @@ -349,69 +254,29 @@ | ||
| 349 | 254 | /** |
| 350 | 255 | * Import a kit by session_id. |
| 351 | 256 | * Upload and import a kit by kit zip file. |
| 352 | 257 | * |
| 353 | - * If the split_to_chunks flag is true, the process won't start | |
| 354 | - * It will initialize the import process and return the session_id and the runners. | |
| 355 | - * | |
| 356 | 258 | * Assigning the Import process to the 'import' property, |
| 357 | 259 | * so it will be available to use in different places such as: WP_Cli, Pro, etc. |
| 358 | 260 | * |
| 359 | 261 | * @param string $path Path to the file or session_id. |
| 360 | - * @param array $settings Settings the import use to determine which content to import. | |
| 361 | - * (e.g: include, selected_plugins, selected_cpt, selected_override_conditions, etc.) | |
| 362 | - * @param bool $split_to_chunks Determine if the import process should be split into chunks. | |
| 262 | + * @param array $settings Settings the import use to determine which content to import. | |
| 263 | + * (e.g: include, selected_plugins, selected_cpt, selected_override_conditions, etc.) | |
| 363 | 264 | * @return array |
| 364 | - * @throws \Exception If export configuration is invalid or processing fails. | |
| 265 | + * @throws \Exception | |
| 365 | 266 | */ |
| 366 | - public function import_kit( string $path, array $settings, bool $split_to_chunks = false ): array { | |
| 267 | + public function import_kit( $path, $settings ) { | |
| 367 | 268 | $this->ensure_writing_permissions(); |
| 368 | - $this->ensure_DOMDocument_exists(); | |
| 369 | 269 | |
| 370 | 270 | $this->import = new Import( $path, $settings ); |
| 371 | 271 | $this->import->register_default_runners(); |
| 372 | 272 | |
| 373 | - remove_filter( 'elementor/document/save/data', [ Plugin::$instance->modules_manager->get_modules( 'content-sanitizer' ), 'sanitize_content' ] ); | |
| 374 | 273 | do_action( 'elementor/import-export/import-kit', $this->import ); |
| 375 | 274 | |
| 376 | - if ( $split_to_chunks ) { | |
| 377 | - $this->import->init_import_session( true ); | |
| 378 | - | |
| 379 | - return [ | |
| 380 | - 'session' => $this->import->get_session_id(), | |
| 381 | - 'runners' => $this->import->get_runners_name(), | |
| 382 | - ]; | |
| 383 | - } | |
| 384 | - | |
| 385 | 275 | return $this->import->run(); |
| 386 | 276 | } |
| 387 | 277 | |
| 388 | 278 | /** |
| 389 | - * Resuming import process by re-creating the import instance and running the specific runner. | |
| 390 | - * | |
| 391 | - * @param string $session_id The id off the import session. | |
| 392 | - * @param string $runner_name The specific runner that we want to run. | |
| 393 | - * | |
| 394 | - * @return array Two types of response. | |
| 395 | - * 1. The status and the runner name. | |
| 396 | - * 2. The imported data. (Only if the runner is the last one in the import process) | |
| 397 | - * @throws \Exception If import configuration is invalid or processing fails. | |
| 398 | - */ | |
| 399 | - public function import_kit_by_runner( string $session_id, string $runner_name ): array { | |
| 400 | - // Check session_id | |
| 401 | - $this->import = Import::from_session( $session_id ); | |
| 402 | - $runners = $this->import->get_runners_name(); | |
| 403 | - | |
| 404 | - $run = $this->import->run_runner( $runner_name ); | |
| 405 | - | |
| 406 | - if ( end( $runners ) === $run['runner'] ) { | |
| 407 | - return $this->import->get_imported_data(); | |
| 408 | - } | |
| 409 | - | |
| 410 | - return $run; | |
| 411 | - } | |
| 412 | - | |
| 413 | - /** | |
| 414 | 279 | * Export a kit. |
| 415 | 280 | * |
| 416 | 281 | * Assigning the Export process to the 'export' property, |
| 417 | 282 | * so it will be available to use in different places such as: WP_Cli, Pro, etc. |
| @@ -418,11 +283,11 @@ | ||
| 418 | 283 | * |
| 419 | 284 | * @param array $settings Settings the export use to determine which content to export. |
| 420 | 285 | * (e.g: include, kit_info, selected_plugins, selected_cpt, etc.) |
| 421 | 286 | * @return array |
| 422 | - * @throws \Exception If import/export process fails or validation errors occur. | |
| 287 | + * @throws \Exception | |
| 423 | 288 | */ |
| 424 | - public function export_kit( array $settings ) { | |
| 289 | + public function export_kit( $settings ) { | |
| 425 | 290 | $this->ensure_writing_permissions(); |
| 426 | 291 | |
| 427 | 292 | $this->export = new Export( $settings ); |
| 428 | 293 | $this->export->register_default_runners(); |
| @@ -463,9 +328,10 @@ | ||
| 463 | 328 | private function register_actions() { |
| 464 | 329 | add_action( 'admin_init', function() { |
| 465 | 330 | if ( wp_doing_ajax() && |
| 466 | 331 | isset( $_POST['action'] ) && |
| 467 | - wp_verify_nonce( ElementorUtils::get_super_global_value( $_POST, '_nonce' ), Ajax::NONCE_KEY ) && | |
| 332 | + isset( $_POST['_nonce'] ) && | |
| 333 | + wp_verify_nonce( $_POST['_nonce'], Ajax::NONCE_KEY ) && | |
| 468 | 334 | current_user_can( 'manage_options' ) |
| 469 | 335 | ) { |
| 470 | 336 | $this->maybe_handle_ajax(); |
| 471 | 337 | } |
| @@ -474,44 +340,13 @@ | ||
| 474 | 340 | add_action( 'admin_post_elementor_revert_kit', [ $this, 'handle_revert_last_imported_kit' ] ); |
| 475 | 341 | |
| 476 | 342 | add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_scripts' ] ); |
| 477 | 343 | |
| 478 | - if ( ! Plugin::$instance->experiments->is_feature_active( 'import-export-customization' ) ) { | |
| 479 | - $page_id = Tools::PAGE_ID; | |
| 344 | + $page_id = Tools::PAGE_ID; | |
| 480 | 345 | |
| 481 | - add_action( "elementor/admin/after_create_settings/{$page_id}", [ $this, 'register_settings_tab' ] ); | |
| 482 | - } | |
| 483 | - | |
| 484 | - // TODO 18/04/2023 : This needs to be moved to the runner itself after https://elementor.atlassian.net/browse/HTS-434 is done. | |
| 485 | - if ( self::IMPORT_PLUGINS_ACTION === ElementorUtils::get_super_global_value( $_SERVER, 'HTTP_X_ELEMENTOR_ACTION' ) ) { | |
| 486 | - add_filter( 'woocommerce_create_pages', [ $this, 'empty_pages' ], 10, 0 ); | |
| 487 | - } | |
| 488 | - // TODO ^^^ | |
| 489 | - | |
| 490 | - add_filter( 'elementor/import/kit/result', function( $result ) { | |
| 491 | - if ( ! empty( $result['file_url'] ) ) { | |
| 492 | - return [ | |
| 493 | - 'file_name' => $this->get_remote_kit_zip( $result['file_url'] ), | |
| 494 | - 'referrer' => static::REFERRER_KIT_LIBRARY, | |
| 495 | - 'file_url' => $result['file_url'], | |
| 496 | - ]; | |
| 497 | - } | |
| 498 | - | |
| 499 | - return $result; | |
| 500 | - } ); | |
| 346 | + add_action( "elementor/admin/after_create_settings/{$page_id}", [ $this, 'register_settings_tab' ] ); | |
| 501 | 347 | } |
| 502 | 348 | |
| 503 | - /** | |
| 504 | - * Prevent the creation of the default WooCommerce pages (Cart, Checkout, etc.) | |
| 505 | - * | |
| 506 | - * TODO 18/04/2023 : This needs to be moved to the runner itself after https://elementor.atlassian.net/browse/HTS-434 is done. | |
| 507 | - * | |
| 508 | - * @return array | |
| 509 | - */ | |
| 510 | - public function empty_pages(): array { | |
| 511 | - return []; | |
| 512 | - } | |
| 513 | - | |
| 514 | 349 | private function ensure_writing_permissions() { |
| 515 | 350 | $server = new Server(); |
| 516 | 351 | |
| 517 | 352 | $paths_to_check = [ |
| @@ -523,14 +358,14 @@ | ||
| 523 | 358 | $permissions = $server->get_paths_permissions( $paths_to_check ); |
| 524 | 359 | |
| 525 | 360 | // WP Content dir has to be exists and writable. |
| 526 | 361 | if ( ! $permissions[ Server::KEY_PATH_WP_CONTENT_DIR ]['write'] ) { |
| 527 | - throw new \Error( self::NO_WRITE_PERMISSIONS_KEY ); // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped | |
| 362 | + throw new \Error( self::NO_WRITE_PERMISSIONS_KEY . 'in - ' . Server::KEY_PATH_WP_CONTENT_DIR ); | |
| 528 | 363 | } |
| 529 | 364 | |
| 530 | 365 | // WP Uploads dir has to be exists and writable. |
| 531 | 366 | if ( ! $permissions[ Server::KEY_PATH_UPLOADS_DIR ]['write'] ) { |
| 532 | - throw new \Error( self::NO_WRITE_PERMISSIONS_KEY ); // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped | |
| 367 | + throw new \Error( self::NO_WRITE_PERMISSIONS_KEY . 'in - ' . Server::KEY_PATH_UPLOADS_DIR ); | |
| 533 | 368 | } |
| 534 | 369 | |
| 535 | 370 | // Elementor uploads dir permissions is divided to 2 cases: |
| 536 | 371 | // 1. If the dir exists, it has to be writable. |
| @@ -535,18 +370,12 @@ | ||
| 535 | 370 | // Elementor uploads dir permissions is divided to 2 cases: |
| 536 | 371 | // 1. If the dir exists, it has to be writable. |
| 537 | 372 | // 2. If the dir doesn't exist, the parent dir has to be writable (wp uploads dir), so we can create it. |
| 538 | 373 | if ( $permissions[ Server::KEY_PATH_ELEMENTOR_UPLOADS_DIR ]['exists'] && ! $permissions[ Server::KEY_PATH_ELEMENTOR_UPLOADS_DIR ]['write'] ) { |
| 539 | - throw new \Error( self::NO_WRITE_PERMISSIONS_KEY ); // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped | |
| 374 | + throw new \Error( self::NO_WRITE_PERMISSIONS_KEY . 'in - ' . Server::KEY_PATH_ELEMENTOR_UPLOADS_DIR ); | |
| 540 | 375 | } |
| 541 | 376 | } |
| 542 | 377 | |
| 543 | - private function ensure_DOMDocument_exists() { | |
| 544 | - if ( ! class_exists( 'DOMDocument' ) ) { | |
| 545 | - throw new \Error( self::DOMDOCUMENT_MISSING ); // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped | |
| 546 | - } | |
| 547 | - } | |
| 548 | - | |
| 549 | 378 | /** |
| 550 | 379 | * Enqueue admin scripts |
| 551 | 380 | */ |
| 552 | 381 | public function enqueue_scripts() { |
| @@ -556,17 +385,8 @@ | ||
| 556 | 385 | [ 'elementor-common' ], |
| 557 | 386 | ELEMENTOR_VERSION, |
| 558 | 387 | true |
| 559 | 388 | ); |
| 560 | - | |
| 561 | - wp_localize_script( | |
| 562 | - 'elementor-import-export-admin', | |
| 563 | - 'elementorImportExport', | |
| 564 | - [ | |
| 565 | - 'lastImportedSession' => $this->revert->get_last_import_session(), | |
| 566 | - 'appUrl' => Plugin::$instance->app->get_base_url() . '#/kit-library', | |
| 567 | - ] | |
| 568 | - ); | |
| 569 | 389 | } |
| 570 | 390 | |
| 571 | 391 | /** |
| 572 | 392 | * Assign each ajax action to a method. |
| @@ -572,127 +392,81 @@ | ||
| 572 | 392 | * Assign each ajax action to a method. |
| 573 | 393 | */ |
| 574 | 394 | private function maybe_handle_ajax() { |
| 575 | 395 | // phpcs:ignore WordPress.Security.NonceVerification.Missing |
| 576 | - $action = ElementorUtils::get_super_global_value( $_POST, 'action' ); | |
| 396 | + switch ( $_POST['action'] ) { | |
| 397 | + case static::EXPORT_TRIGGER_KEY: | |
| 398 | + $this->handle_export_kit(); | |
| 399 | + break; | |
| 577 | 400 | |
| 578 | - try { | |
| 579 | - switch ( $action ) { | |
| 580 | - case static::EXPORT_TRIGGER_KEY: | |
| 581 | - $this->handle_export_kit(); | |
| 582 | - break; | |
| 401 | + case static::UPLOAD_TRIGGER_KEY: | |
| 402 | + $this->handle_upload_kit(); | |
| 403 | + break; | |
| 583 | 404 | |
| 584 | - case static::UPLOAD_TRIGGER_KEY: | |
| 585 | - $this->handle_upload_kit(); | |
| 586 | - break; | |
| 405 | + case static::IMPORT_TRIGGER_KEY: | |
| 406 | + $this->handle_import_kit(); | |
| 407 | + break; | |
| 587 | 408 | |
| 588 | - case static::IMPORT_TRIGGER_KEY: | |
| 589 | - $this->handle_import_kit(); | |
| 590 | - break; | |
| 591 | - | |
| 592 | - case static::IMPORT_RUNNER_TRIGGER_KEY: | |
| 593 | - $this->handle_import_kit__runner(); | |
| 594 | - break; | |
| 595 | - | |
| 596 | - default: | |
| 597 | - break; | |
| 598 | - } | |
| 599 | - } catch ( \Error $e ) { | |
| 600 | - if ( isset( $this->import ) ) { | |
| 601 | - $this->import->finalize_import_session_option(); | |
| 602 | - } | |
| 603 | - | |
| 604 | - Plugin::$instance->logger->get_logger()->error( $e->getMessage(), [ | |
| 605 | - 'meta' => [ | |
| 606 | - 'trace' => $e->getTraceAsString(), | |
| 607 | - ], | |
| 608 | - ] ); | |
| 609 | - | |
| 610 | - if ( isset( $this->import ) && $this->is_third_party_class( $e->getTrace()[0]['class'] ) ) { | |
| 611 | - wp_send_json_error( self::THIRD_PARTY_ERROR, 500 ); | |
| 612 | - } | |
| 613 | - | |
| 614 | - wp_send_json_error( $e->getMessage(), 500 ); | |
| 409 | + default: | |
| 410 | + break; | |
| 615 | 411 | } |
| 616 | 412 | } |
| 617 | 413 | |
| 618 | 414 | /** |
| 619 | 415 | * Handle upload kit ajax request. |
| 620 | - * | |
| 621 | - * @throws \Error If operation validation fails or processing errors occur. | |
| 622 | 416 | */ |
| 623 | 417 | private function handle_upload_kit() { |
| 624 | - // PHPCS - A URL that should contain special chars (auth headers information). | |
| 625 | - $file_url = isset( $_POST['e_import_file'] ) | |
| 626 | - // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized | |
| 627 | - ? wp_unslash( $_POST['e_import_file'] ) | |
| 628 | - : ''; | |
| 629 | - | |
| 630 | - // PHPCS - Already validated in caller function | |
| 631 | - $kit_id = ElementorUtils::get_super_global_value( $_POST, 'kit_id' ); // phpcs:ignore WordPress.Security.NonceVerification.Missing | |
| 632 | - $source = ElementorUtils::get_super_global_value( $_POST, 'source' ); // phpcs:ignore WordPress.Security.NonceVerification.Missing | |
| 633 | - | |
| 634 | - $is_import_from_library = ! empty( $file_url ); | |
| 635 | - | |
| 636 | - if ( $is_import_from_library ) { | |
| 418 | + // PHPCS - Already validated in caller function. | |
| 419 | + if ( ! empty( $_POST['e_import_file'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing | |
| 637 | 420 | if ( |
| 638 | - ! wp_verify_nonce( ElementorUtils::get_super_global_value( $_POST, 'e_kit_library_nonce' ), 'kit-library-import' ) | |
| 421 | + ! isset( $_POST['e_kit_library_nonce'] ) || | |
| 422 | + ! wp_verify_nonce( $_POST['e_kit_library_nonce'], 'kit-library-import' ) | |
| 639 | 423 | ) { |
| 640 | - throw new \Error( 'Invalid kit library nonce.' ); | |
| 424 | + throw new \Error( esc_html__( 'Invalid kit library nonce', 'elementor' ) ); | |
| 641 | 425 | } |
| 642 | 426 | |
| 427 | + $file_url = $_POST['e_import_file']; | |
| 428 | + | |
| 643 | 429 | if ( ! filter_var( $file_url, FILTER_VALIDATE_URL ) || 0 !== strpos( $file_url, 'http' ) ) { |
| 644 | - throw new \Error( static::KIT_LIBRARY_ERROR_KEY ); // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped | |
| 430 | + throw new \Error( esc_html__( 'Invalid URL', 'elementor' ) ); | |
| 645 | 431 | } |
| 646 | 432 | |
| 647 | - $import_result = apply_filters( 'elementor/import/kit/result', [ 'file_url' => $file_url ] ); | |
| 648 | - } elseif ( ! empty( $source ) ) { | |
| 649 | - $import_result = apply_filters( 'elementor/import/kit/result/' . $source, [ | |
| 650 | - 'kit_id' => $kit_id, | |
| 651 | - 'source' => $source, | |
| 652 | - ] ); | |
| 653 | - } else { | |
| 654 | - $import_result = [ | |
| 655 | - 'file_name' => ElementorUtils::get_super_global_value( $_FILES, 'e_import_file' )['tmp_name'], | |
| 656 | - 'referrer' => static::REFERRER_LOCAL, | |
| 657 | - ]; | |
| 658 | - } | |
| 433 | + $remote_zip_request = wp_remote_get( $file_url ); | |
| 659 | 434 | |
| 660 | - Plugin::$instance->logger->get_logger()->info( 'Uploading Kit: ', [ | |
| 661 | - 'meta' => [ | |
| 662 | - 'kit_id' => $kit_id, | |
| 663 | - 'referrer' => $import_result['referrer'], | |
| 664 | - ], | |
| 665 | - ] ); | |
| 435 | + if ( is_wp_error( $remote_zip_request ) ) { | |
| 436 | + throw new \Error( $remote_zip_request->get_error_message() ); | |
| 437 | + } | |
| 666 | 438 | |
| 667 | - if ( is_wp_error( $import_result ) ) { | |
| 668 | - wp_send_json_error( $import_result->get_error_message() ); | |
| 439 | + if ( 200 !== $remote_zip_request['response']['code'] ) { | |
| 440 | + throw new \Error( $remote_zip_request['response']['message'] ); | |
| 441 | + } | |
| 442 | + | |
| 443 | + $file_name = Plugin::$instance->uploads_manager->create_temp_file( $remote_zip_request['body'], 'kit.zip' ); | |
| 444 | + $referrer = static::REFERRER_KIT_LIBRARY; | |
| 445 | + } else { | |
| 446 | + // PHPCS - Already validated in caller function. | |
| 447 | + $file_name = $_FILES['e_import_file']['tmp_name']; // phpcs:ignore WordPress.Security.NonceVerification.Missing | |
| 448 | + $referrer = static::REFERRER_LOCAL; | |
| 669 | 449 | } |
| 670 | 450 | |
| 671 | - $uploaded_kit = $this->upload_kit( $import_result['file_name'], $import_result['referrer'], $kit_id ); | |
| 672 | - | |
| 451 | + $uploaded_kit = $this->upload_kit( $file_name, $referrer ); | |
| 673 | 452 | $session_dir = $uploaded_kit['session']; |
| 674 | 453 | $manifest = $uploaded_kit['manifest']; |
| 675 | 454 | $conflicts = $uploaded_kit['conflicts']; |
| 676 | 455 | |
| 677 | - if ( $is_import_from_library || ! empty( $source ) ) { | |
| 678 | - Plugin::$instance->uploads_manager->remove_file_or_dir( dirname( $import_result['file_name'] ) ); | |
| 456 | + if ( ! empty( $file_url ) ) { | |
| 457 | + Plugin::$instance->uploads_manager->remove_file_or_dir( dirname( $file_name ) ); | |
| 679 | 458 | } |
| 680 | 459 | |
| 681 | 460 | if ( isset( $manifest['plugins'] ) && ! current_user_can( 'install_plugins' ) ) { |
| 682 | - throw new \Error( static::PLUGIN_PERMISSIONS_ERROR_KEY ); // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped | |
| 461 | + throw new \Error( static::PERMISSIONS_ERROR_KEY ); | |
| 683 | 462 | } |
| 684 | 463 | |
| 685 | 464 | $result = [ |
| 686 | 465 | 'session' => $session_dir, |
| 687 | 466 | 'manifest' => $manifest, |
| 688 | - 'file_url' => $import_result['file_url'], | |
| 689 | 467 | ]; |
| 690 | 468 | |
| 691 | - if ( ! empty( $import_result['kit'] ) ) { | |
| 692 | - $result['uploaded_kit'] = $import_result['kit']; | |
| 693 | - } | |
| 694 | - | |
| 695 | 469 | if ( ! empty( $conflicts ) ) { |
| 696 | 470 | $result['conflicts'] = $conflicts; |
| 697 | 471 | } else { |
| 698 | 472 | // Moved into the IE process \Elementor\App\Modules\ImportExport\Processes\Import::get_default_settings_conflicts |
| @@ -702,113 +476,46 @@ | ||
| 702 | 476 | |
| 703 | 477 | wp_send_json_success( $result ); |
| 704 | 478 | } |
| 705 | 479 | |
| 706 | - protected function get_remote_kit_zip( $url ) { | |
| 707 | - $remote_zip_request = wp_safe_remote_get( $url ); | |
| 708 | - | |
| 709 | - if ( is_wp_error( $remote_zip_request ) ) { | |
| 710 | - Plugin::$instance->logger->get_logger()->error( $remote_zip_request->get_error_message() ); | |
| 711 | - throw new \Error( static::KIT_LIBRARY_ERROR_KEY ); // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped | |
| 712 | - } | |
| 713 | - | |
| 714 | - if ( 200 !== $remote_zip_request['response']['code'] ) { | |
| 715 | - Plugin::$instance->logger->get_logger()->error( $remote_zip_request['response']['message'] ); | |
| 716 | - throw new \Error( static::KIT_LIBRARY_ERROR_KEY ); // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped | |
| 717 | - } | |
| 718 | - | |
| 719 | - return Plugin::$instance->uploads_manager->create_temp_file( $remote_zip_request['body'], 'kit.zip' ); | |
| 720 | - } | |
| 721 | - | |
| 722 | 480 | /** |
| 723 | 481 | * Handle import kit ajax request. |
| 724 | 482 | */ |
| 725 | 483 | private function handle_import_kit() { |
| 726 | 484 | // PHPCS - Already validated in caller function |
| 727 | - $settings = json_decode( ElementorUtils::get_super_global_value( $_POST, 'data' ), true ); // phpcs:ignore WordPress.Security.NonceVerification.Missing | |
| 485 | + $settings = json_decode( stripslashes( $_POST['data'] ), true ); // phpcs:ignore WordPress.Security.NonceVerification.Missing | |
| 728 | 486 | $tmp_folder_id = $settings['session']; |
| 729 | 487 | |
| 730 | - $import = $this->import_kit( $tmp_folder_id, $settings, true ); | |
| 488 | + $import = $this->import_kit( $tmp_folder_id, $settings ); | |
| 731 | 489 | |
| 732 | 490 | // get_settings_config() added manually because the frontend Ajax request doesn't trigger the get_init_settings(). |
| 733 | 491 | $import['configData'] = $this->get_config_data(); |
| 734 | 492 | |
| 735 | - Plugin::$instance->logger->get_logger()->info( | |
| 736 | - sprintf( 'Selected import runners: %1$s', | |
| 737 | - implode( ', ', $import['runners'] ) | |
| 738 | - ) | |
| 739 | - ); | |
| 740 | - | |
| 741 | 493 | wp_send_json_success( $import ); |
| 742 | 494 | } |
| 743 | 495 | |
| 744 | 496 | /** |
| 745 | - * Handle ajax request for running specific runner in the import kit process. | |
| 746 | - */ | |
| 747 | - private function handle_import_kit__runner() { | |
| 748 | - // PHPCS - Already validated in caller function | |
| 749 | - $settings = json_decode( ElementorUtils::get_super_global_value( $_POST, 'data' ), true ); // phpcs:ignore WordPress.Security.NonceVerification.Missing | |
| 750 | - $session_id = $settings['session']; | |
| 751 | - $runner = $settings['runner']; | |
| 752 | - | |
| 753 | - $import = $this->import_kit_by_runner( $session_id, $runner ); | |
| 754 | - | |
| 755 | - // get_settings_config() added manually because the frontend Ajax request doesn't trigger the get_init_settings(). | |
| 756 | - $import['configData'] = $this->get_config_data(); | |
| 757 | - | |
| 758 | - if ( ! empty( $import['status'] ) ) { | |
| 759 | - Plugin::$instance->logger->get_logger()->info( | |
| 760 | - sprintf( 'Import runner completed: %1$s %2$s', | |
| 761 | - $import['runner'], | |
| 762 | - ( 'success' === $import['status'] ? '✓' : '✗' ) | |
| 763 | - ) | |
| 764 | - ); | |
| 765 | - } | |
| 766 | - | |
| 767 | - do_action( 'elementor/import-export/import-kit/runner/after-run', $import ); | |
| 768 | - | |
| 769 | - wp_send_json_success( $import ); | |
| 770 | - } | |
| 771 | - | |
| 772 | - /** | |
| 773 | 497 | * Handle export kit ajax request. |
| 774 | - * | |
| 775 | - * @throws \Error If cleanup process fails or file system errors occur. | |
| 776 | 498 | */ |
| 777 | 499 | private function handle_export_kit() { |
| 778 | 500 | // PHPCS - Already validated in caller function |
| 779 | - $settings = json_decode( ElementorUtils::get_super_global_value( $_POST, 'data' ), true ); // phpcs:ignore WordPress.Security.NonceVerification.Missing | |
| 780 | - $source = $settings['kitInfo']['source']; | |
| 781 | - | |
| 501 | + $settings = json_decode( stripslashes( $_POST['data'] ), true ); // phpcs:ignore WordPress.Security.NonceVerification.Missing | |
| 782 | 502 | $export = $this->export_kit( $settings ); |
| 783 | 503 | |
| 784 | 504 | $file_name = $export['file_name']; |
| 785 | - $file_size = filesize( $file_name ); | |
| 786 | 505 | $file = ElementorUtils::file_get_contents( $file_name ); |
| 787 | 506 | |
| 788 | 507 | if ( ! $file ) { |
| 789 | - throw new \Error( 'Could not read the exported file.' ); | |
| 508 | + throw new \Error( esc_html__( 'Could not read the exported file', 'elementor' ) ); | |
| 790 | 509 | } |
| 791 | 510 | |
| 792 | 511 | Plugin::$instance->uploads_manager->remove_file_or_dir( dirname( $file_name ) ); |
| 793 | 512 | |
| 794 | - $result = apply_filters( | |
| 795 | - 'elementor/export/kit/export-result', | |
| 796 | - [ | |
| 797 | - 'manifest' => $export['manifest'], | |
| 798 | - 'file' => base64_encode( $file ), | |
| 799 | - ], | |
| 800 | - $source, | |
| 801 | - $export, | |
| 802 | - $settings, | |
| 803 | - $file, | |
| 804 | - $file_size, | |
| 805 | - ); | |
| 513 | + $result = [ | |
| 514 | + 'manifest' => $export['manifest'], | |
| 515 | + 'file' => base64_encode( $file ), | |
| 516 | + ]; | |
| 806 | 517 | |
| 807 | - if ( is_wp_error( $result ) ) { | |
| 808 | - wp_send_json_error( $result ); | |
| 809 | - } | |
| 810 | - | |
| 811 | 518 | wp_send_json_success( $result ); |
| 812 | 519 | } |
| 813 | 520 | |
| 814 | 521 | /** |
| @@ -825,12 +532,8 @@ | ||
| 825 | 532 | 'elementorPostTypes' => ImportExportUtils::get_elementor_post_types(), |
| 826 | 533 | 'isUnfilteredFilesEnabled' => Uploads_Manager::are_unfiltered_uploads_enabled(), |
| 827 | 534 | 'elementorHomePageUrl' => $this->get_elementor_home_page_url(), |
| 828 | 535 | 'recentlyEditedElementorPageUrl' => $this->get_recently_edited_elementor_page_url(), |
| 829 | - 'tools_url' => Tools::get_url(), | |
| 830 | - 'importSessions' => Revert::get_import_sessions(), | |
| 831 | - 'lastImportedSession' => $this->revert->get_last_import_session(), | |
| 832 | - 'kitPreviewNonce' => wp_create_nonce( 'kit_thumbnail' ), | |
| 833 | 536 | ]; |
| 834 | 537 | } |
| 835 | 538 | |
| 836 | 539 | /** |
| @@ -855,10 +558,10 @@ | ||
| 855 | 558 | foreach ( $post_types as $post_type ) { |
| 856 | 559 | $post_type_object = get_post_type_object( $post_type ); |
| 857 | 560 | |
| 858 | 561 | $summary_titles['content'][ $post_type ] = [ |
| 859 | - 'single' => $post_type_object->labels->singular_name ?? '', | |
| 860 | - 'plural' => $post_type_object->label ?? '', | |
| 562 | + 'single' => $post_type_object->labels->singular_name, | |
| 563 | + 'plural' => $post_type_object->label, | |
| 861 | 564 | ]; |
| 862 | 565 | } |
| 863 | 566 | |
| 864 | 567 | $custom_post_types = ImportExportUtils::get_registered_cpt_names(); |
| @@ -868,16 +571,16 @@ | ||
| 868 | 571 | $custom_post_types_object = get_post_type_object( $custom_post_type ); |
| 869 | 572 | // CPT data appears in two arrays: |
| 870 | 573 | // 1. content object: in order to show the export summary when completed in getLabel function |
| 871 | 574 | $summary_titles['content'][ $custom_post_type ] = [ |
| 872 | - 'single' => $custom_post_types_object->labels->singular_name ?? '', | |
| 873 | - 'plural' => $custom_post_types_object->label ?? '', | |
| 575 | + 'single' => $custom_post_types_object->labels->singular_name, | |
| 576 | + 'plural' => $custom_post_types_object->label, | |
| 874 | 577 | ]; |
| 875 | 578 | |
| 876 | 579 | // 2. customPostTypes object: in order to actually export the data |
| 877 | 580 | $summary_titles['content']['customPostTypes'][ $custom_post_type ] = [ |
| 878 | - 'single' => $custom_post_types_object->labels->singular_name ?? '', | |
| 879 | - 'plural' => $custom_post_types_object->label ?? '', | |
| 581 | + 'single' => $custom_post_types_object->labels->singular_name, | |
| 582 | + 'plural' => $custom_post_types_object->label, | |
| 880 | 583 | ]; |
| 881 | 584 | } |
| 882 | 585 | } |
| 883 | 586 | |
| @@ -895,11 +598,11 @@ | ||
| 895 | 598 | return false; |
| 896 | 599 | } |
| 897 | 600 | |
| 898 | 601 | // TODO: BC - remove in the future |
| 899 | - // The 'templates' runner was in core and moved to the Pro plugin. (Part of it still exits in the Core for BC) | |
| 900 | - // The runner that is in the core version is missing the revert functionality, | |
| 901 | - // therefore we shouldn't display the revert section if the import process done with the core version. | |
| 602 | + // The 'templates' runner was in core and moved to the Pro plugin. (Part of it still exits in the Core for BC) | |
| 603 | + // The runner that is in the core version is missing the revert functionality, | |
| 604 | + // therefore we shouldn't display the revert section if the import process done with the core version. | |
| 902 | 605 | $is_import_templates_ran = isset( $last_imported_kit['runners']['templates'] ); |
| 903 | 606 | if ( $this->has_pro() && $is_import_templates_ran ) { |
| 904 | 607 | $has_imported_templates = ! empty( $last_imported_kit['runners']['templates'] ); |
| 905 | 608 | |
| @@ -972,28 +675,6 @@ | ||
| 972 | 675 | private function get_elementor_editor_page_url( $page_id ) { |
| 973 | 676 | $document = $this->get_elementor_document( $page_id ); |
| 974 | 677 | |
| 975 | 678 | return $document ? $document->get_edit_url() : ''; |
| 976 | - } | |
| 977 | - | |
| 978 | - /** | |
| 979 | - * @param string $class_name | |
| 980 | - * | |
| 981 | - * @return bool | |
| 982 | - */ | |
| 983 | - public function is_third_party_class( $class_name ) { | |
| 984 | - $allowed_classes = [ | |
| 985 | - 'Elementor\\', | |
| 986 | - 'ElementorPro\\', | |
| 987 | - 'WP_', | |
| 988 | - 'wp_', | |
| 989 | - ]; | |
| 990 | - | |
| 991 | - foreach ( $allowed_classes as $allowed_class ) { | |
| 992 | - if ( str_starts_with( $class_name, $allowed_class ) ) { | |
| 993 | - return false; | |
| 994 | - } | |
| 995 | - } | |
| 996 | - | |
| 997 | - return true; | |
| 998 | 679 | } |
| 999 | 680 | } |