app->is_current() ) {
return [];
}
return $this->get_config_data();
}
public function get_summary_titles() {
$summary_titles = [];
$document_types = Plugin::$instance->documents->get_document_types();
foreach ( $document_types as $name => $document_type ) {
$summary_titles['templates'][ $name ] = [
'single' => $document_type::get_title(),
'plural' => $document_type::get_plural_title(),
];
}
$post_types = get_post_types_by_support( 'elementor' );
$post_types[] = 'nav_menu_item';
foreach ( $post_types as $post_type ) {
if ( Source_Local::CPT === $post_type ) {
continue;
}
$post_type_object = get_post_type_object( $post_type );
$summary_titles['content'][ $post_type ] = [
'single' => $post_type_object->labels->singular_name,
'plural' => $post_type_object->label,
];
}
$custom_post_types = $this->get_registered_cpt_names();
if ( ! empty( $custom_post_types ) ) {
foreach ( $custom_post_types as $custom_post_type ) {
$custom_post_types_object = get_post_type_object( $custom_post_type );
//cpt data appears in two arrays:
//1. content object: in order to show the export summary when completed in getLabel function
$summary_titles['content'][ $custom_post_type ] = [
'single' => $custom_post_types_object->labels->singular_name,
'plural' => $custom_post_types_object->label,
];
//2. customPostTypes object: in order to actually export the data
$summary_titles['content']['customPostTypes'][ $custom_post_type ] = [
'single' => $custom_post_types_object->labels->singular_name,
'plural' => $custom_post_types_object->label,
];
}
}
$active_kit = Plugin::$instance->kits_manager->get_active_kit();
foreach ( $active_kit->get_tabs() as $key => $tab ) {
$summary_titles['site-settings'][ $key ] = $tab->get_title();
}
return $summary_titles;
}
/**
* Retrieve custom post type names.
*
* @since 3.6.0
* @access public
*
* @return array custom post type names.
*/
public function get_registered_cpt_names() {
$post_types = get_post_types( [
'public' => true,
'can_export' => true,
] );
unset(
$post_types['attachment'],
$post_types['page'],
$post_types['post'],
$post_types[ Landing_Pages_Module::CPT ],
$post_types[ Source_Local::CPT ]
);
$custom_post_types = [];
foreach ( $post_types as $post_type ) {
array_push( $custom_post_types, $post_type );
}
return $custom_post_types;
}
private function import_stage_1() {
// PHPCS - Already validated in caller function.
if ( ! empty( $_POST['e_import_file'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
if (
! isset( $_POST['e_kit_library_nonce'] ) ||
! wp_verify_nonce( $_POST['e_kit_library_nonce'], 'kit-library-import' )
) {
throw new \Error( esc_html__( 'Invalid kit library nonce', 'elementor' ) );
}
$file_url = $_POST['e_import_file'];
if ( ! filter_var( $file_url, FILTER_VALIDATE_URL ) || 0 !== strpos( $file_url, 'http' ) ) {
throw new \Error( esc_html__( 'Invalid URL', 'elementor' ) );
}
$remote_zip_request = wp_remote_get( $file_url );
if ( is_wp_error( $remote_zip_request ) ) {
throw new \Error( $remote_zip_request->get_error_message() );
}
if ( 200 !== $remote_zip_request['response']['code'] ) {
throw new \Error( $remote_zip_request['response']['message'] );
}
$file_name = Plugin::$instance->uploads_manager->create_temp_file( $remote_zip_request['body'], 'kit.zip' );
} else {
// PHPCS - Already validated in caller function.
$file_name = $_FILES['e_import_file']['tmp_name']; // phpcs:ignore WordPress.Security.NonceVerification.Missing
}
$extraction_result = Plugin::$instance->uploads_manager->extract_and_validate_zip( $file_name, [ 'json', 'xml' ] );
if ( ! empty( $file_url ) ) {
Plugin::$instance->uploads_manager->remove_file_or_dir( dirname( $file_name ) );
}
$session_dir = $extraction_result['extraction_directory'];
$manifest_file_content = Utils::file_get_contents( $session_dir . 'manifest.json', true );
if ( ! $manifest_file_content ) {
throw new \Error( self::MANIFEST_ERROR_KEY );
}
$manifest_data = json_decode( $manifest_file_content, true );
// In case that the manifest content is not a valid JSON or empty.
if ( ! $manifest_data ) {
throw new \Error( self::MANIFEST_ERROR_KEY );
}
if ( isset( $manifest_data['plugins'] ) && ! current_user_can( 'install_plugins' ) ) {
throw new \Error( static::PERMISSIONS_ERROR_KEY );
}
$manifest_data = $this->import->adapt_manifest_structure( $manifest_data );
$result = [
'session' => $session_dir,
'manifest' => $manifest_data,
];
$result = apply_filters( 'elementor/import/stage_1/result', $result );
return $result;
}
private function import_stage_2( $settings_directory ) {
set_time_limit( 0 );
$result = $this->import->run();
Plugin::$instance->uploads_manager->remove_file_or_dir( $settings_directory );
return $result;
}
private function on_admin_init() {
if ( ! isset( $_POST['action'] ) || self::IMPORT_TRIGGER_KEY !== $_POST['action'] || ! wp_verify_nonce( $_POST['_nonce'], Ajax::NONCE_KEY ) ) {
return;
}
$import_settings = json_decode( stripslashes( $_POST['data'] ), true );
// Set the Request's state as an Elementor upload request, in order to support unfiltered file uploads.
Plugin::$instance->uploads_manager->set_elementor_upload_state( true );
try {
$this->import = new Import( $import_settings );
if ( 1 === $import_settings['stage'] ) {
$result = $this->import_stage_1();
} elseif ( 2 === $import_settings['stage'] ) {
$result = $this->import_stage_2( $import_settings['session'] );
// Adding the most updated data of the summaryTitles, in case that the data was changed during the process by new installed plugins.
$result['configData'] = $this->get_config_data();
}
wp_send_json_success( $result );
} catch ( \Error $error ) {
wp_send_json_error( $error->getMessage() );
}
}
private function on_init() {
if ( ! isset( $_POST['action'] ) || self::EXPORT_TRIGGER_KEY !== $_POST['action'] || ! wp_verify_nonce( $_POST['_nonce'], Ajax::NONCE_KEY ) ) {
return;
}
$export_settings = json_decode( stripslashes( $_POST['data'] ), true );
try {
$this->export = new Export( self::merge_properties( [], $export_settings, [ 'include', 'kitInfo', 'plugins', 'selectedCustomPostTypes' ] ) );
$export_result = $this->export->run();
$file_name = $export_result['file_name'];
$file = Utils::file_get_contents( $file_name );
Plugin::$instance->uploads_manager->remove_file_or_dir( dirname( $file_name ) );
wp_send_json_success( [
'manifest' => $export_result['manifest'],
'file' => base64_encode( $file ),
] );
} catch ( \Error $error ) {
wp_send_json_error( $error->getMessage() );
}
}
private function render_import_export_tab_content() {
$intro_text_link = sprintf( '%s', esc_html__( 'Learn more', 'elementor' ) );
$intro_text = sprintf(
/* translators: 1: New line break, 2: Learn More link. */
__( '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' ),
'
',
$intro_text_link
);
$content_data = [
'export' => [
'title' => esc_html__( 'Export a Template Kit', 'elementor' ),
'button' => [
'url' => Plugin::$instance->app->get_base_url() . '#/export',
'text' => esc_html__( 'Start Export', 'elementor' ),
],
'description' => esc_html__( 'Bundle your whole site - or just some of its elements - to be used for another website.', 'elementor' ),
'link' => [
'url' => 'https://go.elementor.com/wp-dash-import-export-export-flow/',
'text' => esc_html__( 'Learn More', 'elementor' ),
],
],
'import' => [
'title' => esc_html__( 'Import a Template Kit', 'elementor' ),
'button' => [
'url' => Plugin::$instance->app->get_base_url() . '#/import',
'text' => esc_html__( 'Start Import', 'elementor' ),
],
'description' => esc_html__( 'Apply the design and settings of another site to this one.', 'elementor' ),
'link' => [
'url' => 'https://go.elementor.com/wp-dash-import-export-import-flow/',
'text' => esc_html__( 'Learn More', 'elementor' ),
],
],
];
$home_page_editor_url = $this->get_elementor_editor_home_page_url();
$editor_page_link = $home_page_editor_url ? $home_page_editor_url : $this->get_recently_edited_elementor_editor_page_url();
$info_text = esc_html__( 'Even after you import and apply a Template Kit, you can undo it by restoring a previous version of your site.', 'elementor' ) . '
';
$info_text .= sprintf( '%2$s', $editor_page_link . '#e:run:panel/global/open&e:route:panel/history/revisions', esc_html__( 'Open Site Settings > History > Revisions.', 'elementor' ) );
?>