Edit File by line
/home/zeestwma/richards.../wp-conte.../plugins/elemento.../app/modules/import-e...
File: module.php
<?php
[0] Fix | Delete
namespace Elementor\App\Modules\ImportExport;
[1] Fix | Delete
[2] Fix | Delete
use Elementor\App\Modules\ImportExport\Processes\Export;
[3] Fix | Delete
use Elementor\App\Modules\ImportExport\Processes\Import;
[4] Fix | Delete
use Elementor\App\Modules\ImportExport\Processes\Revert;
[5] Fix | Delete
use Elementor\Core\Base\Module as BaseModule;
[6] Fix | Delete
use Elementor\Core\Common\Modules\Ajax\Module as Ajax;
[7] Fix | Delete
use Elementor\Core\Files\Uploads_Manager;
[8] Fix | Delete
use Elementor\Modules\System_Info\Reporters\Server;
[9] Fix | Delete
use Elementor\Plugin;
[10] Fix | Delete
use Elementor\Tools;
[11] Fix | Delete
use Elementor\Utils as ElementorUtils;
[12] Fix | Delete
use Elementor\App\Modules\ImportExport\Utils as ImportExportUtils;
[13] Fix | Delete
[14] Fix | Delete
if ( ! defined( 'ABSPATH' ) ) {
[15] Fix | Delete
exit; // Exit if accessed directly.
[16] Fix | Delete
}
[17] Fix | Delete
[18] Fix | Delete
/**
[19] Fix | Delete
* Import Export Module
[20] Fix | Delete
*
[21] Fix | Delete
* Responsible for initializing Elementor App functionality
[22] Fix | Delete
*/
[23] Fix | Delete
class Module extends BaseModule {
[24] Fix | Delete
const FORMAT_VERSION = '2.0';
[25] Fix | Delete
[26] Fix | Delete
const EXPORT_TRIGGER_KEY = 'elementor_export_kit';
[27] Fix | Delete
[28] Fix | Delete
const UPLOAD_TRIGGER_KEY = 'elementor_upload_kit';
[29] Fix | Delete
[30] Fix | Delete
const IMPORT_TRIGGER_KEY = 'elementor_import_kit';
[31] Fix | Delete
[32] Fix | Delete
const IMPORT_RUNNER_TRIGGER_KEY = 'elementor_import_kit__runner';
[33] Fix | Delete
[34] Fix | Delete
const REFERRER_KIT_LIBRARY = 'kit-library';
[35] Fix | Delete
[36] Fix | Delete
const REFERRER_LOCAL = 'local';
[37] Fix | Delete
[38] Fix | Delete
const REFERRER_CLOUD = 'cloud';
[39] Fix | Delete
[40] Fix | Delete
const PLUGIN_PERMISSIONS_ERROR_KEY = 'plugin-installation-permissions-error';
[41] Fix | Delete
[42] Fix | Delete
const KIT_LIBRARY_ERROR_KEY = 'invalid-kit-library-zip-error';
[43] Fix | Delete
[44] Fix | Delete
const NO_WRITE_PERMISSIONS_KEY = 'no-write-permissions';
[45] Fix | Delete
[46] Fix | Delete
const THIRD_PARTY_ERROR = 'third-party-error';
[47] Fix | Delete
[48] Fix | Delete
const DOMDOCUMENT_MISSING = 'domdocument-missing';
[49] Fix | Delete
[50] Fix | Delete
const OPTION_KEY_ELEMENTOR_IMPORT_SESSIONS = 'elementor_import_sessions';
[51] Fix | Delete
[52] Fix | Delete
const OPTION_KEY_ELEMENTOR_REVERT_SESSIONS = 'elementor_revert_sessions';
[53] Fix | Delete
[54] Fix | Delete
const META_KEY_ELEMENTOR_IMPORT_SESSION_ID = '_elementor_import_session_id';
[55] Fix | Delete
[56] Fix | Delete
const META_KEY_ELEMENTOR_EDIT_MODE = '_elementor_edit_mode';
[57] Fix | Delete
const IMPORT_PLUGINS_ACTION = 'import-plugins';
[58] Fix | Delete
const EXPORT_SOURCE_CLOUD = 'cloud';
[59] Fix | Delete
const EXPORT_SOURCE_FILE = 'file';
[60] Fix | Delete
[61] Fix | Delete
/**
[62] Fix | Delete
* Assigning the export process to a property, so we can use the process from outside the class.
[63] Fix | Delete
*
[64] Fix | Delete
* @var Export
[65] Fix | Delete
*/
[66] Fix | Delete
public $export;
[67] Fix | Delete
[68] Fix | Delete
/**
[69] Fix | Delete
* Assigning the import process to a property, so we can use the process from outside the class.
[70] Fix | Delete
*
[71] Fix | Delete
* @var Import
[72] Fix | Delete
*/
[73] Fix | Delete
public $import;
[74] Fix | Delete
[75] Fix | Delete
/**
[76] Fix | Delete
* Assigning the revert process to a property, so we can use the process from outside the class.
[77] Fix | Delete
*
[78] Fix | Delete
* @var Revert
[79] Fix | Delete
*/
[80] Fix | Delete
public $revert;
[81] Fix | Delete
[82] Fix | Delete
/**
[83] Fix | Delete
* Get name.
[84] Fix | Delete
*
[85] Fix | Delete
* @access public
[86] Fix | Delete
*
[87] Fix | Delete
* @return string
[88] Fix | Delete
*/
[89] Fix | Delete
public function get_name() {
[90] Fix | Delete
return 'import-export';
[91] Fix | Delete
}
[92] Fix | Delete
[93] Fix | Delete
public function __construct() {
[94] Fix | Delete
$this->register_actions();
[95] Fix | Delete
[96] Fix | Delete
if ( ElementorUtils::is_wp_cli() ) {
[97] Fix | Delete
\WP_CLI::add_command( 'elementor kit', WP_CLI::class );
[98] Fix | Delete
}
[99] Fix | Delete
[100] Fix | Delete
( new Usage() )->register();
[101] Fix | Delete
[102] Fix | Delete
$this->revert = new Revert();
[103] Fix | Delete
}
[104] Fix | Delete
[105] Fix | Delete
public function get_init_settings() {
[106] Fix | Delete
if ( ! Plugin::$instance->app->is_current() ) {
[107] Fix | Delete
return [];
[108] Fix | Delete
}
[109] Fix | Delete
[110] Fix | Delete
return $this->get_config_data();
[111] Fix | Delete
}
[112] Fix | Delete
[113] Fix | Delete
/**
[114] Fix | Delete
* Register the import/export tab in elementor tools.
[115] Fix | Delete
*/
[116] Fix | Delete
public function register_settings_tab( Tools $tools ) {
[117] Fix | Delete
$tools->add_tab( 'import-export-kit', [
[118] Fix | Delete
'label' => esc_html__( 'Website Templates', 'elementor' ),
[119] Fix | Delete
'sections' => [
[120] Fix | Delete
'intro' => [
[121] Fix | Delete
'label' => esc_html__( 'Website Templates', 'elementor' ),
[122] Fix | Delete
'callback' => function() {
[123] Fix | Delete
$this->render_import_export_tab_content();
[124] Fix | Delete
},
[125] Fix | Delete
'fields' => [],
[126] Fix | Delete
],
[127] Fix | Delete
],
[128] Fix | Delete
] );
[129] Fix | Delete
}
[130] Fix | Delete
[131] Fix | Delete
/**
[132] Fix | Delete
* Render the import/export tab content.
[133] Fix | Delete
*/
[134] Fix | Delete
private function render_import_export_tab_content() {
[135] Fix | Delete
$content_data = [
[136] Fix | Delete
'export' => [
[137] Fix | Delete
'title' => esc_html__( 'Export this website', 'elementor' ),
[138] Fix | Delete
'button' => [
[139] Fix | Delete
'url' => Plugin::$instance->app->get_base_url() . '#/export',
[140] Fix | Delete
'text' => esc_html__( 'Export', 'elementor' ),
[141] Fix | Delete
],
[142] Fix | Delete
'description' => esc_html__( 'You can download this website as a .zip file, or upload it to the library.', 'elementor' ),
[143] Fix | Delete
],
[144] Fix | Delete
'import' => [
[145] Fix | Delete
'title' => esc_html__( 'Import website templates', 'elementor' ),
[146] Fix | Delete
'button' => [
[147] Fix | Delete
'url' => Plugin::$instance->app->get_base_url() . '#/import',
[148] Fix | Delete
'text' => esc_html__( 'Import', 'elementor' ),
[149] Fix | Delete
],
[150] Fix | Delete
'description' => esc_html__( 'You can import design and settings from a .zip file or choose from the library.', 'elementor' ),
[151] Fix | Delete
],
[152] Fix | Delete
];
[153] Fix | Delete
[154] Fix | Delete
if ( Plugin::$instance->experiments->is_feature_active( 'cloud-library' ) ) {
[155] Fix | Delete
$content_data['import']['button_secondary'] = [
[156] Fix | Delete
'url' => Plugin::$instance->app->get_base_url() . '#/kit-library/cloud',
[157] Fix | Delete
'text' => esc_html__( 'Import from library', 'elementor' ),
[158] Fix | Delete
];
[159] Fix | Delete
}
[160] Fix | Delete
[161] Fix | Delete
$last_imported_kit = $this->revert->get_last_import_session();
[162] Fix | Delete
$penultimate_imported_kit = $this->revert->get_penultimate_import_session();
[163] Fix | Delete
[164] Fix | Delete
$user_date_format = get_option( 'date_format' );
[165] Fix | Delete
$user_time_format = get_option( 'time_format' );
[166] Fix | Delete
$date_format = $user_date_format . ' ' . $user_time_format;
[167] Fix | Delete
[168] Fix | Delete
$should_show_revert_section = $this->should_show_revert_section( $last_imported_kit );
[169] Fix | Delete
[170] Fix | Delete
if ( $should_show_revert_section ) {
[171] Fix | Delete
if ( ! empty( $penultimate_imported_kit ) ) {
[172] Fix | Delete
$revert_text = sprintf(
[173] Fix | Delete
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' ),
[174] Fix | Delete
! empty( $last_imported_kit['kit_title'] ) ? $last_imported_kit['kit_title'] : esc_html__( 'imported kit', 'elementor' ),
[175] Fix | Delete
gmdate( $date_format, $last_imported_kit['start_timestamp'] ),
[176] Fix | Delete
'<br>',
[177] Fix | Delete
! empty( $penultimate_imported_kit['kit_title'] ) ? $penultimate_imported_kit['kit_title'] : esc_html__( 'imported kit', 'elementor' ),
[178] Fix | Delete
gmdate( $date_format, $penultimate_imported_kit['start_timestamp'] )
[179] Fix | Delete
);
[180] Fix | Delete
} else {
[181] Fix | Delete
$revert_text = sprintf(
[182] Fix | Delete
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' ),
[183] Fix | Delete
! empty( $last_imported_kit['kit_title'] ) ? $last_imported_kit['kit_title'] : esc_html__( 'imported kit', 'elementor' ),
[184] Fix | Delete
gmdate( $date_format, $last_imported_kit['start_timestamp'] ),
[185] Fix | Delete
'<br>'
[186] Fix | Delete
);
[187] Fix | Delete
}
[188] Fix | Delete
}
[189] Fix | Delete
?>
[190] Fix | Delete
[191] Fix | Delete
<div class="tab-import-export-kit__content">
[192] Fix | Delete
<p class="tab-import-export-kit__info">
[193] Fix | Delete
<?php
[194] Fix | Delete
printf(
[195] Fix | Delete
'%1$s <a href="https://go.elementor.com/wp-dash-import-export-general/" target="_blank">%2$s</a>',
[196] Fix | Delete
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' ),
[197] Fix | Delete
esc_html__( 'Learn more', 'elementor' ),
[198] Fix | Delete
);
[199] Fix | Delete
?>
[200] Fix | Delete
</p>
[201] Fix | Delete
[202] Fix | Delete
<div class="tab-import-export-kit__wrapper">
[203] Fix | Delete
<?php foreach ( $content_data as $data ) {
[204] Fix | Delete
$this->print_item_content( $data );
[205] Fix | Delete
} ?>
[206] Fix | Delete
</div>
[207] Fix | Delete
[208] Fix | Delete
<?php
[209] Fix | Delete
if ( $should_show_revert_section ) {
[210] Fix | Delete
[211] Fix | Delete
$link_attributes = [
[212] Fix | Delete
'href' => $this->get_revert_href(),
[213] Fix | Delete
'id' => 'elementor-import-export__revert_kit',
[214] Fix | Delete
'class' => 'button',
[215] Fix | Delete
];
[216] Fix | Delete
?>
[217] Fix | Delete
<div class="tab-import-export-kit__revert">
[218] Fix | Delete
<h2>
[219] Fix | Delete
<?php echo esc_html__( 'Remove the most recent Website Template', 'elementor' ); ?>
[220] Fix | Delete
</h2>
[221] Fix | Delete
<p class="tab-import-export-kit__info">
[222] Fix | Delete
<?php ElementorUtils::print_unescaped_internal_string( $revert_text ); ?>
[223] Fix | Delete
</p>
[224] Fix | Delete
<?php $this->render_last_kit_thumbnail( $last_imported_kit ); ?>
[225] Fix | Delete
<a <?php ElementorUtils::print_html_attributes( $link_attributes ); ?> >
[226] Fix | Delete
<?php echo esc_html__( 'Remove Website Template', 'elementor' ); ?>
[227] Fix | Delete
</a>
[228] Fix | Delete
</div>
[229] Fix | Delete
<?php } ?>
[230] Fix | Delete
</div>
[231] Fix | Delete
<?php
[232] Fix | Delete
}
[233] Fix | Delete
[234] Fix | Delete
private function print_item_content( $data ) {
[235] Fix | Delete
$is_cloud_kits_feature_active = Plugin::$instance->experiments->is_feature_active( 'cloud-library' );
[236] Fix | Delete
[237] Fix | Delete
if ( $is_cloud_kits_feature_active ) { ?>
[238] Fix | Delete
<div class="tab-import-export-kit__container">
[239] Fix | Delete
<div class="tab-import-export-kit__box">
[240] Fix | Delete
<h2><?php ElementorUtils::print_unescaped_internal_string( $data['title'] ); ?></h2>
[241] Fix | Delete
</div>
[242] Fix | Delete
<p class="description"><?php ElementorUtils::print_unescaped_internal_string( $data['description'] ); ?></p>
[243] Fix | Delete
[244] Fix | Delete
<?php if ( ! empty( $data['link'] ) ) : ?>
[245] Fix | Delete
<a href="<?php ElementorUtils::print_unescaped_internal_string( $data['link']['url'] ); ?>" target="_blank"><?php ElementorUtils::print_unescaped_internal_string( $data['link']['text'] ); ?></a>
[246] Fix | Delete
<?php endif; ?>
[247] Fix | Delete
<div class="tab-import-export-kit__box action-buttons">
[248] Fix | Delete
<?php if ( ! empty( $data['button_secondary'] ) ) : ?>
[249] Fix | Delete
<a href="<?php ElementorUtils::print_unescaped_internal_string( $data['button_secondary']['url'] ); ?>" class="elementor-button e-btn-txt e-btn-txt-border">
[250] Fix | Delete
<?php ElementorUtils::print_unescaped_internal_string( $data['button_secondary']['text'] ); ?>
[251] Fix | Delete
</a>
[252] Fix | Delete
<?php endif; ?>
[253] Fix | Delete
<a href="<?php ElementorUtils::print_unescaped_internal_string( $data['button']['url'] ); ?>" class="elementor-button e-primary">
[254] Fix | Delete
<?php ElementorUtils::print_unescaped_internal_string( $data['button']['text'] ); ?>
[255] Fix | Delete
</a>
[256] Fix | Delete
</div>
[257] Fix | Delete
</div>
[258] Fix | Delete
<?php } else { ?>
[259] Fix | Delete
<div class="tab-import-export-kit__container">
[260] Fix | Delete
<div class="tab-import-export-kit__box">
[261] Fix | Delete
<h2><?php ElementorUtils::print_unescaped_internal_string( $data['title'] ); ?></h2>
[262] Fix | Delete
<a href="<?php ElementorUtils::print_unescaped_internal_string( $data['button']['url'] ); ?>" class="elementor-button e-primary">
[263] Fix | Delete
<?php ElementorUtils::print_unescaped_internal_string( $data['button']['text'] ); ?>
[264] Fix | Delete
</a>
[265] Fix | Delete
</div>
[266] Fix | Delete
<p><?php ElementorUtils::print_unescaped_internal_string( $data['description'] ); ?></p>
[267] Fix | Delete
<a href="<?php ElementorUtils::print_unescaped_internal_string( $data['link']['url'] ); ?>" target="_blank"><?php ElementorUtils::print_unescaped_internal_string( $data['link']['text'] ); ?></a>
[268] Fix | Delete
</div>
[269] Fix | Delete
<?php }
[270] Fix | Delete
}
[271] Fix | Delete
[272] Fix | Delete
private function get_revert_href(): string {
[273] Fix | Delete
$admin_post_url = admin_url( 'admin-post.php?action=elementor_revert_kit' );
[274] Fix | Delete
$nonced_admin_post_url = wp_nonce_url( $admin_post_url, 'elementor_revert_kit' );
[275] Fix | Delete
return $this->maybe_add_referrer_param( $nonced_admin_post_url );
[276] Fix | Delete
}
[277] Fix | Delete
[278] Fix | Delete
/**
[279] Fix | Delete
* Checks if referred by a kit and adds the referrer ID to the href
[280] Fix | Delete
*
[281] Fix | Delete
* @param string $href
[282] Fix | Delete
*
[283] Fix | Delete
* @return string
[284] Fix | Delete
*/
[285] Fix | Delete
private function maybe_add_referrer_param( string $href ): string {
[286] Fix | Delete
$param_name = 'referrer_kit';
[287] Fix | Delete
[288] Fix | Delete
if ( empty( $_GET[ $param_name ] ) ) {
[289] Fix | Delete
return $href;
[290] Fix | Delete
}
[291] Fix | Delete
[292] Fix | Delete
return add_query_arg( $param_name, sanitize_key( $_GET[ $param_name ] ), $href );
[293] Fix | Delete
}
[294] Fix | Delete
[295] Fix | Delete
/**
[296] Fix | Delete
* Render the last kit thumbnail if exists
[297] Fix | Delete
*
[298] Fix | Delete
* @param $last_imported_kit
[299] Fix | Delete
*
[300] Fix | Delete
* @return void
[301] Fix | Delete
*/
[302] Fix | Delete
private function render_last_kit_thumbnail( $last_imported_kit ) {
[303] Fix | Delete
if ( empty( $last_imported_kit['kit_thumbnail'] ) ) {
[304] Fix | Delete
return;
[305] Fix | Delete
}
[306] Fix | Delete
[307] Fix | Delete
?>
[308] Fix | Delete
<div class="tab-import-export-kit__kit-item-row">
[309] Fix | Delete
<article class="tab-import-export-kit__kit-item">
[310] Fix | Delete
<header>
[311] Fix | Delete
<h3>
[312] Fix | Delete
<?php echo esc_html( $last_imported_kit['kit_title'] ); ?>
[313] Fix | Delete
</h3>
[314] Fix | Delete
</header>
[315] Fix | Delete
<img
[316] Fix | Delete
src="<?php echo esc_url( $last_imported_kit['kit_thumbnail'] ); ?>"
[317] Fix | Delete
alt="<?php echo esc_attr( $last_imported_kit['kit_title'] ); ?>"
[318] Fix | Delete
loading="lazy"
[319] Fix | Delete
>
[320] Fix | Delete
</article>
[321] Fix | Delete
</div>
[322] Fix | Delete
<?php
[323] Fix | Delete
}
[324] Fix | Delete
[325] Fix | Delete
/**
[326] Fix | Delete
* Upload a kit zip file and get the kit data.
[327] Fix | Delete
*
[328] Fix | Delete
* Assigning the Import process to the 'import' property,
[329] Fix | Delete
* so it will be available to use in different places such as: WP_Cli, Pro, etc.
[330] Fix | Delete
*
[331] Fix | Delete
* @param string $file Path to the file.
[332] Fix | Delete
* @param string $referrer Referrer of the file 'local' or 'kit-library'.
[333] Fix | Delete
* @param string $kit_id
[334] Fix | Delete
* @return array
[335] Fix | Delete
* @throws \Exception
[336] Fix | Delete
*/
[337] Fix | Delete
public function upload_kit( $file, $referrer, $kit_id = null ) {
[338] Fix | Delete
$this->ensure_writing_permissions();
[339] Fix | Delete
[340] Fix | Delete
$this->import = new Import( $file, [
[341] Fix | Delete
'referrer' => $referrer,
[342] Fix | Delete
'id' => $kit_id,
[343] Fix | Delete
] );
[344] Fix | Delete
[345] Fix | Delete
return [
[346] Fix | Delete
'session' => $this->import->get_session_id(),
[347] Fix | Delete
'manifest' => $this->import->get_manifest(),
[348] Fix | Delete
'conflicts' => $this->import->get_settings_conflicts(),
[349] Fix | Delete
];
[350] Fix | Delete
}
[351] Fix | Delete
[352] Fix | Delete
/**
[353] Fix | Delete
* Import a kit by session_id.
[354] Fix | Delete
* Upload and import a kit by kit zip file.
[355] Fix | Delete
*
[356] Fix | Delete
* If the split_to_chunks flag is true, the process won't start
[357] Fix | Delete
* It will initialize the import process and return the session_id and the runners.
[358] Fix | Delete
*
[359] Fix | Delete
* Assigning the Import process to the 'import' property,
[360] Fix | Delete
* so it will be available to use in different places such as: WP_Cli, Pro, etc.
[361] Fix | Delete
*
[362] Fix | Delete
* @param string $path Path to the file or session_id.
[363] Fix | Delete
* @param array $settings Settings the import use to determine which content to import.
[364] Fix | Delete
* (e.g: include, selected_plugins, selected_cpt, selected_override_conditions, etc.)
[365] Fix | Delete
* @param bool $split_to_chunks Determine if the import process should be split into chunks.
[366] Fix | Delete
* @return array
[367] Fix | Delete
* @throws \Exception
[368] Fix | Delete
*/
[369] Fix | Delete
public function import_kit( string $path, array $settings, bool $split_to_chunks = false ): array {
[370] Fix | Delete
$this->ensure_writing_permissions();
[371] Fix | Delete
$this->ensure_DOMDocument_exists();
[372] Fix | Delete
[373] Fix | Delete
$this->import = new Import( $path, $settings );
[374] Fix | Delete
$this->import->register_default_runners();
[375] Fix | Delete
[376] Fix | Delete
remove_filter( 'elementor/document/save/data', [ Plugin::$instance->modules_manager->get_modules( 'content-sanitizer' ), 'sanitize_content' ] );
[377] Fix | Delete
do_action( 'elementor/import-export/import-kit', $this->import );
[378] Fix | Delete
[379] Fix | Delete
if ( $split_to_chunks ) {
[380] Fix | Delete
$this->import->init_import_session( true );
[381] Fix | Delete
[382] Fix | Delete
return [
[383] Fix | Delete
'session' => $this->import->get_session_id(),
[384] Fix | Delete
'runners' => $this->import->get_runners_name(),
[385] Fix | Delete
];
[386] Fix | Delete
}
[387] Fix | Delete
[388] Fix | Delete
return $this->import->run();
[389] Fix | Delete
}
[390] Fix | Delete
[391] Fix | Delete
/**
[392] Fix | Delete
* Resuming import process by re-creating the import instance and running the specific runner.
[393] Fix | Delete
*
[394] Fix | Delete
* @param string $session_id The id off the import session.
[395] Fix | Delete
* @param string $runner_name The specific runner that we want to run.
[396] Fix | Delete
*
[397] Fix | Delete
* @return array Two types of response.
[398] Fix | Delete
* 1. The status and the runner name.
[399] Fix | Delete
* 2. The imported data. (Only if the runner is the last one in the import process)
[400] Fix | Delete
* @throws \Exception
[401] Fix | Delete
*/
[402] Fix | Delete
public function import_kit_by_runner( string $session_id, string $runner_name ): array {
[403] Fix | Delete
// Check session_id
[404] Fix | Delete
$this->import = Import::from_session( $session_id );
[405] Fix | Delete
$runners = $this->import->get_runners_name();
[406] Fix | Delete
[407] Fix | Delete
$run = $this->import->run_runner( $runner_name );
[408] Fix | Delete
[409] Fix | Delete
if ( end( $runners ) === $run['runner'] ) {
[410] Fix | Delete
return $this->import->get_imported_data();
[411] Fix | Delete
}
[412] Fix | Delete
[413] Fix | Delete
return $run;
[414] Fix | Delete
}
[415] Fix | Delete
[416] Fix | Delete
/**
[417] Fix | Delete
* Export a kit.
[418] Fix | Delete
*
[419] Fix | Delete
* Assigning the Export process to the 'export' property,
[420] Fix | Delete
* so it will be available to use in different places such as: WP_Cli, Pro, etc.
[421] Fix | Delete
*
[422] Fix | Delete
* @param array $settings Settings the export use to determine which content to export.
[423] Fix | Delete
* (e.g: include, kit_info, selected_plugins, selected_cpt, etc.)
[424] Fix | Delete
* @return array
[425] Fix | Delete
* @throws \Exception
[426] Fix | Delete
*/
[427] Fix | Delete
public function export_kit( array $settings ) {
[428] Fix | Delete
$this->ensure_writing_permissions();
[429] Fix | Delete
[430] Fix | Delete
$this->export = new Export( $settings );
[431] Fix | Delete
$this->export->register_default_runners();
[432] Fix | Delete
[433] Fix | Delete
do_action( 'elementor/import-export/export-kit', $this->export );
[434] Fix | Delete
[435] Fix | Delete
return $this->export->run();
[436] Fix | Delete
}
[437] Fix | Delete
[438] Fix | Delete
/**
[439] Fix | Delete
* Handle revert kit ajax request.
[440] Fix | Delete
*/
[441] Fix | Delete
public function revert_last_imported_kit() {
[442] Fix | Delete
$this->revert = new Revert();
[443] Fix | Delete
$this->revert->register_default_runners();
[444] Fix | Delete
[445] Fix | Delete
do_action( 'elementor/import-export/revert-kit', $this->revert );
[446] Fix | Delete
[447] Fix | Delete
$this->revert->run();
[448] Fix | Delete
}
[449] Fix | Delete
[450] Fix | Delete
[451] Fix | Delete
/**
[452] Fix | Delete
* Handle revert last imported kit ajax request.
[453] Fix | Delete
*/
[454] Fix | Delete
public function handle_revert_last_imported_kit() {
[455] Fix | Delete
check_admin_referer( 'elementor_revert_kit' );
[456] Fix | Delete
[457] Fix | Delete
$this->revert_last_imported_kit();
[458] Fix | Delete
[459] Fix | Delete
wp_safe_redirect( admin_url( 'admin.php?page=' . Tools::PAGE_ID . '#tab-import-export-kit' ) );
[460] Fix | Delete
die;
[461] Fix | Delete
}
[462] Fix | Delete
[463] Fix | Delete
/**
[464] Fix | Delete
* Register appropriate actions.
[465] Fix | Delete
*/
[466] Fix | Delete
private function register_actions() {
[467] Fix | Delete
add_action( 'admin_init', function() {
[468] Fix | Delete
if ( wp_doing_ajax() &&
[469] Fix | Delete
isset( $_POST['action'] ) &&
[470] Fix | Delete
wp_verify_nonce( ElementorUtils::get_super_global_value( $_POST, '_nonce' ), Ajax::NONCE_KEY ) &&
[471] Fix | Delete
current_user_can( 'manage_options' )
[472] Fix | Delete
) {
[473] Fix | Delete
$this->maybe_handle_ajax();
[474] Fix | Delete
}
[475] Fix | Delete
} );
[476] Fix | Delete
[477] Fix | Delete
add_action( 'admin_post_elementor_revert_kit', [ $this, 'handle_revert_last_imported_kit' ] );
[478] Fix | Delete
[479] Fix | Delete
add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_scripts' ] );
[480] Fix | Delete
[481] Fix | Delete
$page_id = Tools::PAGE_ID;
[482] Fix | Delete
[483] Fix | Delete
add_action( "elementor/admin/after_create_settings/{$page_id}", [ $this, 'register_settings_tab' ] );
[484] Fix | Delete
[485] Fix | Delete
// TODO 18/04/2023 : This needs to be moved to the runner itself after https://elementor.atlassian.net/browse/HTS-434 is done.
[486] Fix | Delete
if ( self::IMPORT_PLUGINS_ACTION === ElementorUtils::get_super_global_value( $_SERVER, 'HTTP_X_ELEMENTOR_ACTION' ) ) {
[487] Fix | Delete
add_filter( 'woocommerce_create_pages', [ $this, 'empty_pages' ], 10, 0 );
[488] Fix | Delete
}
[489] Fix | Delete
// TODO ^^^
[490] Fix | Delete
[491] Fix | Delete
add_filter( 'elementor/import/kit/result', function( $result ) {
[492] Fix | Delete
if ( ! empty( $result['file_url'] ) ) {
[493] Fix | Delete
return [
[494] Fix | Delete
'file_name' => $this->get_remote_kit_zip( $result['file_url'] ),
[495] Fix | Delete
'referrer' => static::REFERRER_KIT_LIBRARY,
[496] Fix | Delete
'file_url' => $result['file_url'],
[497] Fix | Delete
];
[498] Fix | Delete
}
[499] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function