Edit File by line
/home/barbar84/www/wp-conte.../themes/Divi/core/componen...
File: Portability.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* Import and Export data.
[2] Fix | Delete
*
[3] Fix | Delete
* @package Core\Portability
[4] Fix | Delete
*/
[5] Fix | Delete
[6] Fix | Delete
/**
[7] Fix | Delete
* Handles the portability workflow.
[8] Fix | Delete
*
[9] Fix | Delete
* @package ET\Core\Portability
[10] Fix | Delete
*/
[11] Fix | Delete
class ET_Core_Portability {
[12] Fix | Delete
[13] Fix | Delete
/**
[14] Fix | Delete
* Current instance.
[15] Fix | Delete
*
[16] Fix | Delete
* @since 2.7.0
[17] Fix | Delete
*
[18] Fix | Delete
* @type object
[19] Fix | Delete
*/
[20] Fix | Delete
public $instance;
[21] Fix | Delete
[22] Fix | Delete
/**
[23] Fix | Delete
* @var ET_Core_Data_Utils
[24] Fix | Delete
*/
[25] Fix | Delete
protected static $_;
[26] Fix | Delete
[27] Fix | Delete
/**
[28] Fix | Delete
* Whether or not an import is in progress.
[29] Fix | Delete
*
[30] Fix | Delete
* @since 3.0.99
[31] Fix | Delete
*
[32] Fix | Delete
* @var bool
[33] Fix | Delete
*/
[34] Fix | Delete
protected static $_doing_import = false;
[35] Fix | Delete
[36] Fix | Delete
/**
[37] Fix | Delete
* Constructor.
[38] Fix | Delete
*
[39] Fix | Delete
* @param string $context Portability context previously registered.
[40] Fix | Delete
*/
[41] Fix | Delete
public function __construct( $context ) {
[42] Fix | Delete
$this->instance = et_core_cache_get( $context, 'et_core_portability' );
[43] Fix | Delete
[44] Fix | Delete
self::$_ = ET_Core_Data_Utils::instance();
[45] Fix | Delete
[46] Fix | Delete
if ( $this->instance && $this->instance->view ) {
[47] Fix | Delete
if ( et_core_is_fb_enabled() ) {
[48] Fix | Delete
$this->assets();
[49] Fix | Delete
} else {
[50] Fix | Delete
add_action( 'admin_footer', array( $this, 'modal' ) );
[51] Fix | Delete
add_action( 'customize_controls_print_footer_scripts', array( $this, 'modal' ) );
[52] Fix | Delete
add_action( 'admin_enqueue_scripts', array( $this, 'assets' ), 5 );
[53] Fix | Delete
}
[54] Fix | Delete
}
[55] Fix | Delete
}
[56] Fix | Delete
[57] Fix | Delete
public static function doing_import() {
[58] Fix | Delete
return self::$_doing_import;
[59] Fix | Delete
}
[60] Fix | Delete
[61] Fix | Delete
/**
[62] Fix | Delete
* Import a previously exported layout.
[63] Fix | Delete
*
[64] Fix | Delete
* @since 3.10 Return the result of the import instead of dieing.
[65] Fix | Delete
* @since 2.7.0
[66] Fix | Delete
*
[67] Fix | Delete
* @param string $file_context Accepts 'upload', 'sideload'. Default 'upload'.
[68] Fix | Delete
*
[69] Fix | Delete
* @return bool|array
[70] Fix | Delete
*/
[71] Fix | Delete
public function import( $file_context = 'upload' ) {
[72] Fix | Delete
global $shortname;
[73] Fix | Delete
[74] Fix | Delete
$this->prevent_failure();
[75] Fix | Delete
[76] Fix | Delete
self::$_doing_import = true;
[77] Fix | Delete
[78] Fix | Delete
$timestamp = $this->get_timestamp();
[79] Fix | Delete
$filesystem = $this->set_filesystem();
[80] Fix | Delete
$temp_file_id = sanitize_file_name( $timestamp );
[81] Fix | Delete
$temp_file = $this->has_temp_file( $temp_file_id, 'et_core_import' );
[82] Fix | Delete
$include_global_presets = isset( $_POST['include_global_presets'] ) ? wp_validate_boolean( $_POST['include_global_presets'] ) : false;
[83] Fix | Delete
$global_presets = '';
[84] Fix | Delete
[85] Fix | Delete
if ( $temp_file ) {
[86] Fix | Delete
$import = json_decode( $filesystem->get_contents( $temp_file ), true );
[87] Fix | Delete
} else {
[88] Fix | Delete
if ( ! isset( $_FILES['file']['name'] ) || ! et_()->ends_with( sanitize_file_name( $_FILES['file']['name'] ), '.json' ) ) {
[89] Fix | Delete
return array( 'message' => 'invalideFile' );
[90] Fix | Delete
}
[91] Fix | Delete
[92] Fix | Delete
if ( ! in_array( $file_context, array( 'upload', 'sideload' ) ) ) {
[93] Fix | Delete
$file_context = 'upload';
[94] Fix | Delete
}
[95] Fix | Delete
[96] Fix | Delete
$handle_file = "wp_handle_{$file_context}";
[97] Fix | Delete
$upload = $handle_file( $_FILES['file'], array(
[98] Fix | Delete
'test_size' => false,
[99] Fix | Delete
'test_type' => false,
[100] Fix | Delete
'test_form' => false,
[101] Fix | Delete
) );
[102] Fix | Delete
[103] Fix | Delete
/**
[104] Fix | Delete
* Fires before an uploaded Portability JSON file is processed.
[105] Fix | Delete
*
[106] Fix | Delete
* @since 3.0.99
[107] Fix | Delete
*
[108] Fix | Delete
* @param string $file The absolute path to the uploaded JSON file's temporary location.
[109] Fix | Delete
*/
[110] Fix | Delete
do_action( 'et_core_portability_import_file', $upload['file'] );
[111] Fix | Delete
[112] Fix | Delete
$temp_file = $this->temp_file( $temp_file_id, 'et_core_import', $upload['file'] );
[113] Fix | Delete
$import = json_decode( $filesystem->get_contents( $temp_file ), true );
[114] Fix | Delete
$import = $this->validate( $import );
[115] Fix | Delete
$import['data'] = $this->apply_query( $import['data'], 'set' );
[116] Fix | Delete
[117] Fix | Delete
if ( ! isset( $import['context'] ) || ( isset( $import['context'] ) && $import['context'] !== $this->instance->context ) ) {
[118] Fix | Delete
$this->delete_temp_files( 'et_core_import' );
[119] Fix | Delete
[120] Fix | Delete
return array( 'message' => 'importContextFail' );
[121] Fix | Delete
}
[122] Fix | Delete
[123] Fix | Delete
$filesystem->put_contents( $upload['file'], wp_json_encode( (array) $import ) );
[124] Fix | Delete
}
[125] Fix | Delete
[126] Fix | Delete
// Upload images and replace current urls.
[127] Fix | Delete
if ( isset( $import['images'] ) ) {
[128] Fix | Delete
$images = $this->maybe_paginate_images( (array) $import['images'], 'upload_images', $timestamp );
[129] Fix | Delete
$import['data'] = $this->replace_images_urls( $images, $import['data'] );
[130] Fix | Delete
}
[131] Fix | Delete
[132] Fix | Delete
$data = $import['data'];
[133] Fix | Delete
$success = array( 'timestamp' => $timestamp );
[134] Fix | Delete
[135] Fix | Delete
$this->delete_temp_files( 'et_core_import' );
[136] Fix | Delete
[137] Fix | Delete
if ( 'options' === $this->instance->type ) {
[138] Fix | Delete
// Reset all data besides excluded data.
[139] Fix | Delete
$current_data = $this->apply_query( get_option( $this->instance->target, array() ), 'unset' );
[140] Fix | Delete
[141] Fix | Delete
if ( isset( $data['wp_custom_css'] ) && function_exists( 'wp_update_custom_css_post' ) ) {
[142] Fix | Delete
wp_update_custom_css_post( $data['wp_custom_css'] );
[143] Fix | Delete
[144] Fix | Delete
if ( 'yes' === get_theme_mod( 'et_pb_css_synced', 'no' ) ) {
[145] Fix | Delete
// If synced, clear the legacy custom css value to avoid unwanted merging of old and new css.
[146] Fix | Delete
$data[ "{$shortname}_custom_css" ] = '';
[147] Fix | Delete
}
[148] Fix | Delete
}
[149] Fix | Delete
[150] Fix | Delete
// Merge remaining current data with new data and update options.
[151] Fix | Delete
update_option( $this->instance->target, array_merge( $current_data, $data ) );
[152] Fix | Delete
[153] Fix | Delete
set_theme_mod( 'et_pb_css_synced', 'no' );
[154] Fix | Delete
}
[155] Fix | Delete
[156] Fix | Delete
// Pass the post content and let js save the post.
[157] Fix | Delete
if ( 'post' === $this->instance->type ) {
[158] Fix | Delete
$success['postContent'] = reset( $data );
[159] Fix | Delete
do_shortcode( $success['postContent'] );
[160] Fix | Delete
$success['migrations'] = ET_Builder_Module_Settings_Migration::$migrated;
[161] Fix | Delete
$success['presets'] = isset( $import['presets'] ) && is_array( $import['presets'] ) ? $import['presets'] : (object) array();
[162] Fix | Delete
}
[163] Fix | Delete
[164] Fix | Delete
if ( 'post_type' === $this->instance->type ) {
[165] Fix | Delete
$preset_rewrite_map = array();
[166] Fix | Delete
if ( ! empty( $import['presets'] ) && $include_global_presets ) {
[167] Fix | Delete
$preset_rewrite_map = $this->prepare_to_import_layout_presets( $import['presets'] );
[168] Fix | Delete
$global_presets = $import['presets'];
[169] Fix | Delete
}
[170] Fix | Delete
[171] Fix | Delete
foreach ( $data as &$post ) {
[172] Fix | Delete
$shortcode_object = et_fb_process_shortcode( $post['post_content'] );
[173] Fix | Delete
[174] Fix | Delete
if ( ! empty( $import['presets'] ) ) {
[175] Fix | Delete
if ( $include_global_presets ) {
[176] Fix | Delete
$this->rewrite_module_preset_ids( $shortcode_object, $import['presets'], $preset_rewrite_map );
[177] Fix | Delete
} else {
[178] Fix | Delete
$this->apply_global_presets( $shortcode_object, $import['presets'] );
[179] Fix | Delete
}
[180] Fix | Delete
}
[181] Fix | Delete
[182] Fix | Delete
$post_content = et_fb_process_to_shortcode( $shortcode_object, array(), '', false );
[183] Fix | Delete
// Add slashes for post content to avoid unwanted unslashing (by wp_unslash) while post is inserting.
[184] Fix | Delete
$post['post_content'] = wp_slash( $post_content );
[185] Fix | Delete
[186] Fix | Delete
// Upload thumbnail image if exist.
[187] Fix | Delete
if ( ! empty( $post['post_meta'] ) && ! empty( $post['post_meta']['_thumbnail_id'] ) ) {
[188] Fix | Delete
$post_thumbnail_origin_id = (int) $post['post_meta']['_thumbnail_id'][0];
[189] Fix | Delete
[190] Fix | Delete
if ( ! empty( $import['thumbnails'] ) && ! empty( $import['thumbnails'][ $post_thumbnail_origin_id ] ) ) {
[191] Fix | Delete
$post_thumbnail_new = $this->upload_images( $import['thumbnails'][ $post_thumbnail_origin_id ] );
[192] Fix | Delete
$new_thumbnail_data = reset( $post_thumbnail_new );
[193] Fix | Delete
[194] Fix | Delete
// New thumbnail image was uploaded and it should be updated.
[195] Fix | Delete
if ( isset( $new_thumbnail_data['replacement_id'] ) ) {
[196] Fix | Delete
$new_thumbnail_id = $new_thumbnail_data['replacement_id'];
[197] Fix | Delete
$post['thumbnail'] = $new_thumbnail_id;
[198] Fix | Delete
[199] Fix | Delete
if ( ! function_exists( 'wp_crop_image' ) ) {
[200] Fix | Delete
include ABSPATH . 'wp-admin/includes/image.php';
[201] Fix | Delete
}
[202] Fix | Delete
[203] Fix | Delete
$thumbnail_path = get_attached_file( $new_thumbnail_id );
[204] Fix | Delete
[205] Fix | Delete
// Generate all the image sizes and update thumbnail metadata.
[206] Fix | Delete
$new_metadata = wp_generate_attachment_metadata( $new_thumbnail_id, $thumbnail_path );
[207] Fix | Delete
wp_update_attachment_metadata( $new_thumbnail_id, $new_metadata );
[208] Fix | Delete
}
[209] Fix | Delete
}
[210] Fix | Delete
}
[211] Fix | Delete
}
[212] Fix | Delete
[213] Fix | Delete
if ( ! $this->import_posts( $data ) ) {
[214] Fix | Delete
/**
[215] Fix | Delete
* Filters the error message when {@see ET_Core_Portability::import()} fails.
[216] Fix | Delete
*
[217] Fix | Delete
* @since 3.0.99
[218] Fix | Delete
*
[219] Fix | Delete
* @param mixed $error_message Default is `null`.
[220] Fix | Delete
*/
[221] Fix | Delete
if ( $error_message = apply_filters( 'et_core_portability_import_error_message', false ) ) {
[222] Fix | Delete
$error_message = array( 'message' => $error_message );
[223] Fix | Delete
}
[224] Fix | Delete
[225] Fix | Delete
return $error_message;
[226] Fix | Delete
}
[227] Fix | Delete
}
[228] Fix | Delete
[229] Fix | Delete
if ( ! empty( $global_presets ) ) {
[230] Fix | Delete
if ( ! $this->import_global_presets( $global_presets ) ) {
[231] Fix | Delete
if ( $error_message = apply_filters( 'et_core_portability_import_error_message', false ) ) {
[232] Fix | Delete
$error_message = array( 'message' => $error_message );
[233] Fix | Delete
}
[234] Fix | Delete
[235] Fix | Delete
return $error_message;
[236] Fix | Delete
}
[237] Fix | Delete
}
[238] Fix | Delete
[239] Fix | Delete
[240] Fix | Delete
return $success;
[241] Fix | Delete
}
[242] Fix | Delete
[243] Fix | Delete
/**
[244] Fix | Delete
* Initiate Export.
[245] Fix | Delete
*
[246] Fix | Delete
* @since 2.7.0
[247] Fix | Delete
*
[248] Fix | Delete
* @param bool $return
[249] Fix | Delete
*
[250] Fix | Delete
* @return null|array
[251] Fix | Delete
*/
[252] Fix | Delete
public function export( $return = false ) {
[253] Fix | Delete
$this->prevent_failure();
[254] Fix | Delete
et_core_nonce_verified_previously();
[255] Fix | Delete
[256] Fix | Delete
$timestamp = $this->get_timestamp();
[257] Fix | Delete
$filesystem = $this->set_filesystem();
[258] Fix | Delete
$temp_file_id = sanitize_file_name( $timestamp );
[259] Fix | Delete
$temp_file = $this->has_temp_file( $temp_file_id, 'et_core_export' );
[260] Fix | Delete
$apply_global_presets = isset( $_POST['apply_global_presets'] ) ? wp_validate_boolean( $_POST['apply_global_presets'] ) : false;
[261] Fix | Delete
$global_presets = '';
[262] Fix | Delete
$thumbnails = '';
[263] Fix | Delete
[264] Fix | Delete
if ( $temp_file ) {
[265] Fix | Delete
$file_data = json_decode( $filesystem->get_contents( $temp_file ) );
[266] Fix | Delete
$data = (array) $file_data->data;
[267] Fix | Delete
$global_presets = $file_data->presets;
[268] Fix | Delete
} else {
[269] Fix | Delete
$temp_file = $this->temp_file( $temp_file_id, 'et_core_export' );
[270] Fix | Delete
[271] Fix | Delete
if ( 'options' === $this->instance->type ) {
[272] Fix | Delete
$data = get_option( $this->instance->target, array() );
[273] Fix | Delete
[274] Fix | Delete
// Export the Customizer "Additional CSS" value as well.
[275] Fix | Delete
if ( function_exists( 'wp_get_custom_css' ) ) {
[276] Fix | Delete
$data[ 'wp_custom_css' ] = wp_get_custom_css();
[277] Fix | Delete
}
[278] Fix | Delete
}
[279] Fix | Delete
[280] Fix | Delete
if ( 'post' === $this->instance->type ) {
[281] Fix | Delete
if ( ! ( isset( $_POST['post'] ) || isset( $_POST['content'] ) ) ) {
[282] Fix | Delete
wp_send_json_error();
[283] Fix | Delete
}
[284] Fix | Delete
[285] Fix | Delete
$fields_validatation = array(
[286] Fix | Delete
'ID' => 'intval',
[287] Fix | Delete
// no post_content as the default case for no fields_validation will run it through perms based wp_kses_post, which is exactly what we want.
[288] Fix | Delete
);
[289] Fix | Delete
[290] Fix | Delete
$post_data = array(
[291] Fix | Delete
'post_content' => stripcslashes( $_POST['content'] ), // need to run this through stripcslashes() as thats what wp_kses_post() expects.
[292] Fix | Delete
'ID' => $_POST['post'],
[293] Fix | Delete
);
[294] Fix | Delete
[295] Fix | Delete
$post_data = $this->validate( $post_data, $fields_validatation );
[296] Fix | Delete
[297] Fix | Delete
$data = array( $post_data['ID'] => $post_data['post_content'] );
[298] Fix | Delete
[299] Fix | Delete
if ( isset( $_POST['global_presets'] ) ) {
[300] Fix | Delete
$global_presets = json_decode( stripslashes( $_POST['global_presets'] ) );
[301] Fix | Delete
}
[302] Fix | Delete
}
[303] Fix | Delete
[304] Fix | Delete
if ( 'post_type' === $this->instance->type ) {
[305] Fix | Delete
$data = $this->export_posts_query();
[306] Fix | Delete
}
[307] Fix | Delete
[308] Fix | Delete
$data = $this->apply_query( $data, 'set' );
[309] Fix | Delete
[310] Fix | Delete
if ( 'post_type' === $this->instance->type ) {
[311] Fix | Delete
$used_global_presets = array();
[312] Fix | Delete
$options = array(
[313] Fix | Delete
'apply_global_presets' => true,
[314] Fix | Delete
);
[315] Fix | Delete
[316] Fix | Delete
foreach ( $data as $post ) {
[317] Fix | Delete
$shortcode_object = et_fb_process_shortcode( $post->post_content );
[318] Fix | Delete
[319] Fix | Delete
if ( $apply_global_presets ) {
[320] Fix | Delete
$post->post_content = et_fb_process_to_shortcode( $shortcode_object, $options, '', false );
[321] Fix | Delete
} else {
[322] Fix | Delete
$used_global_presets = array_merge(
[323] Fix | Delete
$this->get_used_global_presets( $shortcode_object, $used_global_presets ),
[324] Fix | Delete
$used_global_presets
[325] Fix | Delete
);
[326] Fix | Delete
}
[327] Fix | Delete
}
[328] Fix | Delete
[329] Fix | Delete
if ( ! empty ( $used_global_presets ) ) {
[330] Fix | Delete
$global_presets = (object) $used_global_presets;
[331] Fix | Delete
}
[332] Fix | Delete
}
[333] Fix | Delete
[334] Fix | Delete
// put contents into file, this is temporary,
[335] Fix | Delete
// if images get paginated, this content will be brought back out
[336] Fix | Delete
// of a temp file in paginated request
[337] Fix | Delete
$file_data = array(
[338] Fix | Delete
'data' => $data,
[339] Fix | Delete
'presets' => $global_presets,
[340] Fix | Delete
);
[341] Fix | Delete
$filesystem->put_contents( $temp_file, wp_json_encode( $file_data ) );
[342] Fix | Delete
}
[343] Fix | Delete
[344] Fix | Delete
$thumbnails = $this->_get_thumbnail_images( $data );
[345] Fix | Delete
[346] Fix | Delete
$images = $this->get_data_images( $data );
[347] Fix | Delete
$data = array(
[348] Fix | Delete
'context' => $this->instance->context,
[349] Fix | Delete
'data' => $data,
[350] Fix | Delete
'presets' => $global_presets,
[351] Fix | Delete
'images' => $this->maybe_paginate_images( $images, 'encode_images', $timestamp ),
[352] Fix | Delete
'thumbnails' => $thumbnails,
[353] Fix | Delete
);
[354] Fix | Delete
[355] Fix | Delete
// Return exported content instead of printing it
[356] Fix | Delete
if ( $return ) {
[357] Fix | Delete
return $data;
[358] Fix | Delete
}
[359] Fix | Delete
[360] Fix | Delete
$filesystem->put_contents( $temp_file, wp_json_encode( (array) $data ) );
[361] Fix | Delete
[362] Fix | Delete
wp_send_json_success( array( 'timestamp' => $timestamp ) );
[363] Fix | Delete
}
[364] Fix | Delete
[365] Fix | Delete
/**
[366] Fix | Delete
* Serialize a single layout post in chunks.
[367] Fix | Delete
*
[368] Fix | Delete
* @since 4.0
[369] Fix | Delete
*
[370] Fix | Delete
* @param integer $id Unique ID to represent this layout serialization.
[371] Fix | Delete
* @param integer $post_id
[372] Fix | Delete
* @param string $content
[373] Fix | Delete
* @param array $theme_builder_meta
[374] Fix | Delete
* @param integer $chunk
[375] Fix | Delete
*
[376] Fix | Delete
* @return array
[377] Fix | Delete
*/
[378] Fix | Delete
public function serialize_layout( $id, $post_id, $content, $theme_builder_meta = array(), $chunk = 0 ) {
[379] Fix | Delete
$this->prevent_failure();
[380] Fix | Delete
[381] Fix | Delete
$fields_validatation = array(
[382] Fix | Delete
// No post_content as the default case for no fields_validation will run it through perms based wp_kses_post, which is exactly what we want.
[383] Fix | Delete
'ID' => 'intval',
[384] Fix | Delete
);
[385] Fix | Delete
[386] Fix | Delete
$post_data = array(
[387] Fix | Delete
// Need to run this through stripcslashes() as thats what wp_kses_post() expects.
[388] Fix | Delete
'post_content' => stripcslashes( $content ),
[389] Fix | Delete
'ID' => $post_id,
[390] Fix | Delete
);
[391] Fix | Delete
[392] Fix | Delete
$post_data = $this->validate( $post_data, $fields_validatation );
[393] Fix | Delete
$data = array( $post_data['ID'] => $post_data['post_content'] );
[394] Fix | Delete
$data = $this->apply_query( $data, 'set' );
[395] Fix | Delete
$images = $this->get_data_images( $data );
[396] Fix | Delete
$images = $this->chunk_images( $images, 'encode_images', $id, $chunk );
[397] Fix | Delete
$data = array(
[398] Fix | Delete
'context' => 'et_builder',
[399] Fix | Delete
'data' => $data,
[400] Fix | Delete
'images' => $images['images'],
[401] Fix | Delete
'post_title' => get_post_field( 'post_title', $post_id ),
[402] Fix | Delete
'post_type' => get_post_type( $post_id ),
[403] Fix | Delete
'theme_builder' => $theme_builder_meta,
[404] Fix | Delete
);
[405] Fix | Delete
$chunks = $images['chunks'];
[406] Fix | Delete
$ready = $images['ready'];
[407] Fix | Delete
[408] Fix | Delete
return array(
[409] Fix | Delete
'ready' => $ready,
[410] Fix | Delete
'chunks' => $chunks,
[411] Fix | Delete
'data' => $data,
[412] Fix | Delete
);
[413] Fix | Delete
}
[414] Fix | Delete
[415] Fix | Delete
/**
[416] Fix | Delete
* Serialize Theme Builder templates in chunks.
[417] Fix | Delete
*
[418] Fix | Delete
* @since 4.0
[419] Fix | Delete
*
[420] Fix | Delete
* @param integer $id Unique ID to represent this theme builder serialization process.
[421] Fix | Delete
* @param array $step
[422] Fix | Delete
* @param integer $steps
[423] Fix | Delete
* @param integer $step_index
[424] Fix | Delete
* @param integer $chunk
[425] Fix | Delete
*
[426] Fix | Delete
* @return array|false
[427] Fix | Delete
*/
[428] Fix | Delete
public function serialize_theme_builder( $id, $step, $steps, $step_index = 0, $chunk = 0 ) {
[429] Fix | Delete
if ( $step_index >= $steps ) {
[430] Fix | Delete
return false;
[431] Fix | Delete
}
[432] Fix | Delete
[433] Fix | Delete
$this->prevent_failure();
[434] Fix | Delete
[435] Fix | Delete
$temp_file_id = sanitize_file_name( 'et_theme_builder_' . $id );
[436] Fix | Delete
$temp_file = $this->has_temp_file( $temp_file_id, 'et_core_export' );
[437] Fix | Delete
[438] Fix | Delete
if ( $temp_file ) {
[439] Fix | Delete
$data = json_decode( $this->get_filesystem()->get_contents( $temp_file ), true );
[440] Fix | Delete
} else {
[441] Fix | Delete
$temp_file = $this->temp_file( $temp_file_id, 'et_core_export' );
[442] Fix | Delete
$data = array(
[443] Fix | Delete
'context' => 'et_theme_builder',
[444] Fix | Delete
'templates' => array(),
[445] Fix | Delete
'layouts' => array(),
[446] Fix | Delete
'presets' => array(),
[447] Fix | Delete
'has_default_template' => false,
[448] Fix | Delete
'has_global_layouts' => false,
[449] Fix | Delete
);
[450] Fix | Delete
}
[451] Fix | Delete
[452] Fix | Delete
$chunks = 1;
[453] Fix | Delete
[454] Fix | Delete
switch ( $step['type'] ) {
[455] Fix | Delete
case 'template':
[456] Fix | Delete
$header_id = $step['data']['layouts']['header']['id'];
[457] Fix | Delete
$body_id = $step['data']['layouts']['body']['id'];
[458] Fix | Delete
$footer_id = $step['data']['layouts']['footer']['id'];
[459] Fix | Delete
$is_default = $step['data']['default'];
[460] Fix | Delete
[461] Fix | Delete
if ( 0 !== $header_id && ! current_user_can( 'edit_post', $header_id ) ) {
[462] Fix | Delete
$step['data']['layouts']['header']['id'] = 0;
[463] Fix | Delete
}
[464] Fix | Delete
[465] Fix | Delete
if ( 0 !== $body_id && ! current_user_can( 'edit_post', $body_id ) ) {
[466] Fix | Delete
$step['data']['layouts']['body']['id'] = 0;
[467] Fix | Delete
}
[468] Fix | Delete
[469] Fix | Delete
if ( 0 !== $footer_id && ! current_user_can( 'edit_post', $footer_id ) ) {
[470] Fix | Delete
$step['data']['layouts']['footer']['id'] = 0;
[471] Fix | Delete
}
[472] Fix | Delete
[473] Fix | Delete
if ( $is_default ) {
[474] Fix | Delete
$data['has_default_template'] = true;
[475] Fix | Delete
}
[476] Fix | Delete
[477] Fix | Delete
$data['templates'][] = $step['data'];
[478] Fix | Delete
break;
[479] Fix | Delete
[480] Fix | Delete
case 'layout':
[481] Fix | Delete
$post_id = $step['data']['post_id'];
[482] Fix | Delete
$is_global = $step['data']['is_global'];
[483] Fix | Delete
[484] Fix | Delete
if ( ! current_user_can( 'edit_post', $post_id ) ) {
[485] Fix | Delete
break;
[486] Fix | Delete
}
[487] Fix | Delete
[488] Fix | Delete
if ( 0 === $chunk && isset( $data['layouts'][ $post_id ] ) ) {
[489] Fix | Delete
// The layout is already exported.
[490] Fix | Delete
break;
[491] Fix | Delete
}
[492] Fix | Delete
[493] Fix | Delete
if ( $is_global ) {
[494] Fix | Delete
$data['has_global_layouts'] = true;
[495] Fix | Delete
}
[496] Fix | Delete
[497] Fix | Delete
$step_data = $this->serialize_layout(
[498] Fix | Delete
$id,
[499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function