: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
et_core_nonce_verified_previously();
return isset( $_POST['timestamp'] ) && ! empty( $_POST['timestamp'] ) ? sanitize_text_field( $_POST['timestamp'] ) : current_time( 'timestamp' );
* Returns Global Presets used for a given shortcode only
* @param array $shortcode_object - The multidimensional array representing a page structure
* @param array $used_global_presets
* @return array - The list of the Global Presets
protected function get_used_global_presets( $shortcode_object, $used_global_presets = array() ) {
$global_presets_manager = ET_Builder_Global_Presets_Settings::instance();
foreach ( $shortcode_object as $module ) {
$module_type = $global_presets_manager->maybe_convert_module_type( $module['type'], $module['attrs'] );
$preset_id = $global_presets_manager->get_module_preset_id( $module_type, $module['attrs'] );
$preset = $global_presets_manager->get_module_preset( $module_type, $preset_id );
if ( $preset_id !== 'default' && count( (array) $preset ) !== 0 && count( (array) $preset->settings ) !== 0 ) {
if ( ! isset( $used_global_presets[ $module_type ] ) ) {
$used_global_presets[ $module_type ] = (object) array(
'presets' => (object) array(),
if ( ! isset( $used_global_presets[ $module_type ]->presets->$preset_id ) ) {
$used_global_presets[ $module_type ]->presets->$preset_id = (object) array(
'version' => $preset->version,
'settings' => $preset->settings,
if ( ! isset( $used_global_presets[ $module_type ]->default ) ) {
$used_global_presets[ $module_type ]->default = $global_presets_manager->get_module_default_preset_id( $module_type );
if ( is_array( $module['content'] ) ) {
$used_global_presets = array_merge( $used_global_presets, $this->get_used_global_presets( $module['content'], $used_global_presets ) );
return $used_global_presets;
public function assets() {
$time = '<span>1</span>';
wp_enqueue_style( 'et-core-portability', ET_CORE_URL . 'admin/css/portability.css', array(
wp_enqueue_script( 'et-core-portability', ET_CORE_URL . 'admin/js/portability.js', array(
wp_localize_script( 'et-core-portability', 'etCorePortability', array(
'import' => wp_create_nonce( 'et_core_portability_import' ),
'export' => wp_create_nonce( 'et_core_portability_export' ),
'cancel' => wp_create_nonce( 'et_core_portability_cancel' ),
'postMaxSize' => $this->to_megabytes( @ini_get( 'post_max_size' ) ),
'uploadMaxSize' => $this->to_megabytes( @ini_get( 'upload_max_filesize' ) ),
'browserSupport' => esc_html__( 'The browser version you are currently using is outdated. Please update to the newest version.', ET_CORE_TEXTDOMAIN ),
'memoryExhausted' => esc_html__( 'You reached your server memory limit. Please try increasing your PHP memory limit.', ET_CORE_TEXTDOMAIN ),
'maxSizeExceeded' => esc_html__( 'This file cannot be imported. It may be caused by file_uploads being disabled in your php.ini. It may also be caused by post_max_size or/and upload_max_filesize being smaller than file selected. Please increase it or transfer more substantial data at the time.', ET_CORE_TEXTDOMAIN ),
'invalideFile' => esc_html__( 'Invalid File format. You should be uploading a JSON file.', ET_CORE_TEXTDOMAIN ),
'importContextFail' => esc_html__( 'This file should not be imported in this context.', ET_CORE_TEXTDOMAIN ),
'noItemsSelected' => esc_html__( 'Please select at least one item to export or disable the "Only export selected items" option', ET_CORE_TEXTDOMAIN ),
'importing' => sprintf( esc_html__( 'Import estimated time remaining: %smin', ET_CORE_TEXTDOMAIN ), $time ),
'exporting' => sprintf( esc_html__( 'Export estimated time remaining: %smin', ET_CORE_TEXTDOMAIN ), $time ),
'backuping' => sprintf( esc_html__( 'Backup estimated time remaining: %smin', ET_CORE_TEXTDOMAIN ), $time ),
public function modal() {
$export_url = add_query_arg( array(
'et_core_portability' => true,
'context' => $this->instance->context,
'name' => $this->instance->name,
'nonce' => wp_create_nonce( 'et_core_portability_export' ),
<div class="et-core-modal-overlay et-core-form" data-et-core-portability="<?php echo esc_attr( $this->instance->context ); ?>">
<div class="et-core-modal">
<div class="et-core-modal-header">
<h3 class="et-core-modal-title"><?php esc_html_e( 'Portability', ET_CORE_TEXTDOMAIN ); ?></h3><a href="#" class="et-core-modal-close" data-et-core-modal="close"></a>
<div data-et-core-tabs class="et-core-modal-tabs-enabled">
<ul class="et-core-tabs">
<li><a href="#et-core-portability-export"><?php esc_html_e( 'Export', ET_CORE_TEXTDOMAIN ); ?></a></li>
<li><a href="#et-core-portability-import"><?php esc_html_e( 'Import', ET_CORE_TEXTDOMAIN ); ?></a></li>
<div id="et-core-portability-export">
<div class="et-core-modal-content">
<?php printf( esc_html__( 'Exporting your %s will create a JSON file that can be imported into a different website.', ET_CORE_TEXTDOMAIN ), esc_html( $this->instance->name ) ); ?>
<h3><?php esc_html_e( 'Export File Name', ET_CORE_TEXTDOMAIN ); ?></h3>
<form class="et-core-portability-export-form">
<input type="text" name="" value="<?php echo esc_attr( $this->instance->name ); ?>">
<?php if ( 'post_type' === $this->instance->type ) : ?>
<div class="et-core-clearfix"></div>
<label><input type="checkbox" name="et-core-portability-posts"/><?php esc_html_e( 'Only export selected items', ET_CORE_TEXTDOMAIN ); ?></label>
<a class="et-core-modal-action" href="#" data-et-core-portability-export="<?php echo esc_url( $export_url ); ?>"><?php printf( esc_html__( 'Export %s', ET_CORE_TEXTDOMAIN ), esc_html( $this->instance->name ) ); ?></a>
<a class="et-core-modal-action et-core-button-danger" href="#" data-et-core-portability-cancel><?php esc_html_e( 'Cancel Export', ET_CORE_TEXTDOMAIN ); ?></a>
<div id="et-core-portability-import">
<div class="et-core-modal-content">
<?php if ( 'post' === $this->instance->type ) : ?>
<?php printf( esc_html__( 'Importing a previously-exported %s file will overwrite all content currently on this page.', ET_CORE_TEXTDOMAIN ), esc_html( $this->instance->name ) ); ?>
<?php elseif ( 'post_type' === $this->instance->type ) : ?>
<?php printf( esc_html__( 'Select a previously-exported Divi Builder Layouts file to begin importing items. Large collections of image-heavy exports may take several minutes to upload.', ET_CORE_TEXTDOMAIN ), esc_html( $this->instance->name ) ); ?>
<?php printf( esc_html__( 'Importing a previously-exported %s file will overwrite all current data. Please proceed with caution!', ET_CORE_TEXTDOMAIN ), esc_html( $this->instance->name ) ); ?>
<h3><?php esc_html_e( 'Select File To Import', ET_CORE_TEXTDOMAIN ); ?></h3>
<form class="et-core-portability-import-form">
<span class="et-core-portability-import-placeholder"><?php esc_html_e( 'No File Selected', ET_CORE_TEXTDOMAIN ); ?></span>
<button class="et-core-button"><?php esc_html_e( 'Choose File', ET_CORE_TEXTDOMAIN ); ?></button>
<div class="et-core-clearfix"></div>
<?php if ( 'post_type' !== $this->instance->type ) : ?>
<label><input type="checkbox" name="et-core-portability-import-backup" /><?php esc_html_e( 'Download backup before importing', ET_CORE_TEXTDOMAIN ); ?></label>
<?php if ( 'post_type' === $this->instance->type ) : ?>
<label><input type="checkbox" name="et-core-portability-import-include-global-presets" /><?php esc_html_e( 'Import Presets', ET_CORE_TEXTDOMAIN ); ?></label>
<a class="et-core-modal-action et-core-portability-import" href="#"><?php printf( esc_html__( 'Import %s', ET_CORE_TEXTDOMAIN ), esc_html( $this->instance->name ) ); ?></a>
<a class="et-core-modal-action et-core-button-danger" href="#" data-et-core-portability-cancel><?php esc_html_e( 'Cancel Import', ET_CORE_TEXTDOMAIN ); ?></a>
if ( ! function_exists( 'et_core_portability_register' ) ) :
* This function should be called in an 'admin_init' action callback.
* @param string $context A unique ID used to register the portability arguments.
* Array of arguments used to register the portability.
* @type string $name The name used in the various text string.
* @type bool $view Whether the assets and content should load or not.
* Example: `isset( $_GET['page'] ) && $_GET['page'] == 'example'`.
* @type string $db The option_name from the wp_option table used to export and import data.
* @type array $include Optional. Array of all the options scritcly included. Options ids must be set
* @type array $exclude Optional. Array of excluded options. Options ids must be set as the array keys.
function et_core_portability_register( $context, $args ) {
$data = apply_filters( "et_core_portability_args_{$context}", (object) array_merge( $defaults, (array) $args ) );
et_core_cache_set( $context, $data, 'et_core_portability' );
// Stop here if not allowed.
if ( function_exists( 'et_pb_is_allowed' ) && ! et_pb_is_allowed( array( 'portability', "{$data->context}_portability" ) ) ) {
// Set view to false if not allowed.
et_core_cache_set( $context, $data, 'et_core_portability' );
et_core_portability_load( $context );
if ( ! function_exists( 'et_core_portability_load' ) ) :
* Load Portability class.
* @param string $context A unique ID used to register the portability arguments.
* @return ET_Core_Portability
function et_core_portability_load( $context ) {
return new ET_Core_Portability( $context );
if ( ! function_exists( 'et_core_portability_link' ) ) :
* HTML link to trigger the portability modal.
* @param string $context The context used to register the portability.
* @param string|array $attributes Optional. Query string or array of attributes. Default empty.
function et_core_portability_link( $context, $attributes = array() ) {
$instance = et_core_cache_get( $context, 'et_core_portability' );
if ( ! $capability = et_core_portability_cap( $context ) ) {
if ( ! current_user_can( $capability ) || ! ( isset( $instance->view ) && $instance->view ) ) {
'title' => esc_attr__( 'Import & Export', ET_CORE_TEXTDOMAIN ),
$attributes = array_merge( $defaults, $attributes );
$attributes['href'] = '#';
$context = esc_attr( $context );
$attributes['data-et-core-modal'] = "[data-et-core-portability='{$context}']";
foreach ( $attributes as $attribute => $value ) {
$string .= esc_attr( $attribute ) . '="' . esc_attr( $value ) . '" ';
'<a %1$s><span>%2$s</span></a>',
esc_html( $attributes['title'] )
if ( ! function_exists( 'et_core_portability_ajax_import' ) ) :
* Ajax portability Import.
function et_core_portability_ajax_import() {
if ( ! isset( $_POST['context'] ) ) {
$context = sanitize_text_field( $_POST['context'] );
$post_id = isset( $_POST['post'] ) ? (int) $_POST['post'] : 0;
$replace = isset( $_POST['replace'] ) ? '1' === $_POST['replace'] : false;
if ( ! $capability = et_core_portability_cap( $context ) ) {
if ( ! et_core_security_check_passed( $capability, 'et_core_portability_import', 'nonce' ) ) {
$portability = et_core_portability_load( $context );
if ( ! $result = $portability->import() ) {
} else if ( is_array( $result ) && isset( $result['message'] ) ) {
wp_send_json_error( $result );
if ( $replace && $post_id > 0 && current_user_can( 'edit_post', $post_id ) ) {
'post_content' => $result['postContent'],
wp_send_json_success( $result );
add_action( 'wp_ajax_et_core_portability_import', 'et_core_portability_ajax_import' );
if ( ! function_exists( 'et_core_portability_ajax_export' ) ) :
* Ajax portability Export.
function et_core_portability_ajax_export() {
if ( ! isset( $_POST['context'] ) ) {
$context = sanitize_text_field( $_POST['context'] );
if ( ! $capability = et_core_portability_cap( $context ) ) {
if ( ! et_core_security_check_passed( $capability, 'et_core_portability_export', 'nonce' ) ) {
et_core_portability_load( $context )->export();
add_action( 'wp_ajax_et_core_portability_export', 'et_core_portability_ajax_export' );
if ( ! function_exists( 'et_core_portability_ajax_cancel' ) ) :
* Cancel portability action.
function et_core_portability_ajax_cancel() {
if ( ! isset( $_POST['context'] ) ) {
$context = sanitize_text_field( $_POST['context'] );
if ( ! $capability = et_core_portability_cap( $context ) ) {
if ( ! et_core_security_check_passed( $capability, 'et_core_portability_cancel' ) ) {
et_core_portability_load( $context )->delete_temp_files( true );
add_action( 'wp_ajax_et_core_portability_cancel', 'et_core_portability_ajax_cancel' );
if ( ! function_exists( 'et_core_portability_export' ) ) :
function et_core_portability_export() {
if ( ! isset( $_GET['et_core_portability'], $_GET['timestamp'] ) ) {
if ( ! et_core_security_check_passed( 'edit_posts' ) ) {
wp_die( esc_html__( 'The export process failed. Please refresh the page and try again.', ET_CORE_TEXTDOMAIN ) );
et_core_portability_load( sanitize_text_field( $_GET['timestamp'] ) )->download_export();
add_action( 'admin_init', 'et_core_portability_export', 20 );
if ( ! function_exists( 'et_core_portability_cap' ) ):
* Returns the required WordPress Capability for a Portability context.
* @param string $context The Portability context
function et_core_portability_cap( $context ) {
$options_contexts = array(
if ( in_array( $context, $options_contexts, true ) ) {
$capability = 'edit_theme_options';
} else if ( in_array( $context, $post_contexts, true ) ) {
$capability = 'edit_posts';