| Server IP : 38.190.208.107 / Your IP : 216.73.216.74 Web Server : nginx/1.28.1 System : Linux ht2026040333114 6.1.0-10-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.37-1 (2023-07-03) x86_64 User : root ( 0) PHP Version : 8.2.28 Disable Function : passthru,exec,system,putenv,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv,eval,assert,passthru,system,exec,shell_exec,popen,proc_open MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /www/wwwroot/wp.5/wp-content/themes/woodmart/inc/modules/layouts/admin/ |
Upload File : |
<?php
/**
* Import class file.
*
* @package woodmart
*/
namespace XTS\Modules\Layouts;
use Elementor\Plugin;
use XTS\Admin\Modules\Import\Helpers;
use XTS\Admin\Modules\Import\XML;
/**
* Import class.
*/
class Import {
/**
* Construct.
*/
public function __construct() {}
/**
* Imports an XML file for a predefined content and processes the imported data.
*
* @param string $layout_type The type of the predefined content to import.
* @param string $predefined_name The name of the predefined content to import.
*
* @return int|false The ID of the newly created post on success, or false on failure.
*/
public static function import_xml( $layout_type, $predefined_name ) {
if ( ! self::validate_layout_type( $layout_type ) ) {
$error = new \WP_Error( 'invalid_layout_type', 'Invalid layout type provided.' );
wp_die( esc_html( $error->get_error_message() ) );
}
$predefined_name = sanitize_file_name( (string) $predefined_name );
if ( '' === $predefined_name ) {
wp_die( esc_html( __( 'Invalid predefined layout name.', 'woodmart' ) ) );
}
$builder = 'external' === woodmart_get_opt( 'current_builder', 'external' ) && ! str_contains( $layout_type, 'loop_item' ) ? woodmart_get_current_page_builder() : 'gutenberg';
$version = 'layout-' . $layout_type . '-' . $predefined_name;
$file_path = WOODMART_THEMEROOT . '/inc/modules/layouts/admin/predefined/' . $layout_type . '/' . $predefined_name . '/';
if ( 'wpb' === $builder ) {
$file_path .= 'content.xml';
} elseif ( 'elementor' === $builder ) {
$file_path .= 'content-elementor.xml';
} else {
$file_path .= 'content-gutenberg.xml';
}
add_filter( 'wp_import_post_data_processed', array( __CLASS__, 'remove_import_id' ), 10 );
add_filter( 'image_sideload_extensions', array( __CLASS__, 'allowed_image_sideload_extensions' ) );
Helpers::get_instance()->set_page_builder( $builder );
new XML( $version, 'woodmart_layout', $file_path );
remove_filter( 'wp_import_post_data_processed', array( __CLASS__, 'remove_import_id' ) );
remove_filter( 'image_sideload_extensions', array( __CLASS__, 'allowed_image_sideload_extensions' ) );
$import_data = Helpers::get_instance()->get_imported_data( $version );
if ( ! empty( $import_data['woodmart_layout'] ) ) {
delete_option( 'wd_imported_data_' . $version );
if ( 'elementor' === $builder && woodmart_is_elementor_installed() ) {
Plugin::$instance->files_manager->clear_cache();
}
return current( $import_data['woodmart_layout'] )['new'];
}
return false;
}
/**
* Validate layout type.
*
* @param string $type Layout type.
*
* @return bool
*/
private static function validate_layout_type( $type ) {
$valid_types = array(
'blog_archive',
'cart',
'checkout_content',
'checkout_form',
'my_account_auth',
'my_account_lost_password',
'my_account_page',
'portfolio_archive',
'shop_archive',
'single_portfolio',
'single_post',
'single_product',
'thank_you_page',
'product_loop_item',
);
return in_array( $type, $valid_types, true );
}
/**
* Allow image sideload extensions.
*
* @param array $allowed_extensions Allowed extensions.
* @return array
*/
public static function allowed_image_sideload_extensions( $allowed_extensions ) {
$allowed_extensions[] = 'svg';
return $allowed_extensions;
}
/**
* Force auto-increment IDs for floating blocks and attachments.
*
* @param array $postdata Post data.
*
* @return array
*/
public static function remove_import_id( $postdata ) {
unset( $postdata['import_id'] );
return $postdata;
}
}