Edit File by line
/home/zeestwma/richards.../wp-conte.../plugins/elemento.../app/modules/import-e...
File: utils.php
<?php
[0] Fix | Delete
[1] Fix | Delete
namespace Elementor\App\Modules\ImportExport;
[2] Fix | Delete
[3] Fix | Delete
use Elementor\Core\Utils\Str;
[4] Fix | Delete
use Elementor\Modules\LandingPages\Module as Landing_Pages_Module;
[5] Fix | Delete
use Elementor\Modules\FloatingButtons\Module as Floating_Buttons_Module;
[6] Fix | Delete
use Elementor\TemplateLibrary\Source_Local;
[7] Fix | Delete
use Elementor\Utils as ElementorUtils;
[8] Fix | Delete
[9] Fix | Delete
class Utils {
[10] Fix | Delete
[11] Fix | Delete
public static function read_json_file( $path ) {
[12] Fix | Delete
if ( ! Str::ends_with( $path, '.json' ) ) {
[13] Fix | Delete
$path .= '.json';
[14] Fix | Delete
}
[15] Fix | Delete
[16] Fix | Delete
$file_content = ElementorUtils::file_get_contents( $path, true );
[17] Fix | Delete
[18] Fix | Delete
return $file_content ? json_decode( $file_content, true ) : [];
[19] Fix | Delete
}
[20] Fix | Delete
[21] Fix | Delete
public static function map_old_new_post_ids( array $imported_data ) {
[22] Fix | Delete
$result = [];
[23] Fix | Delete
[24] Fix | Delete
$result += $imported_data['templates']['succeed'] ?? [];
[25] Fix | Delete
[26] Fix | Delete
if ( isset( $imported_data['content'] ) ) {
[27] Fix | Delete
foreach ( $imported_data['content'] as $post_type ) {
[28] Fix | Delete
$result += $post_type['succeed'] ?? [];
[29] Fix | Delete
}
[30] Fix | Delete
}
[31] Fix | Delete
[32] Fix | Delete
if ( isset( $imported_data['wp-content'] ) ) {
[33] Fix | Delete
foreach ( $imported_data['wp-content'] as $post_type ) {
[34] Fix | Delete
$result += $post_type['succeed'] ?? [];
[35] Fix | Delete
}
[36] Fix | Delete
}
[37] Fix | Delete
[38] Fix | Delete
return $result;
[39] Fix | Delete
}
[40] Fix | Delete
[41] Fix | Delete
public static function map_old_new_term_ids( array $imported_data ) {
[42] Fix | Delete
$result = [];
[43] Fix | Delete
[44] Fix | Delete
if ( ! isset( $imported_data['taxonomies'] ) ) {
[45] Fix | Delete
return $result;
[46] Fix | Delete
}
[47] Fix | Delete
[48] Fix | Delete
foreach ( $imported_data['taxonomies'] as $post_type_taxonomies ) {
[49] Fix | Delete
foreach ( $post_type_taxonomies as $taxonomy ) {
[50] Fix | Delete
foreach ( $taxonomy as $term ) {
[51] Fix | Delete
$result[ $term['old_id'] ] = $term['new_id'];
[52] Fix | Delete
}
[53] Fix | Delete
}
[54] Fix | Delete
}
[55] Fix | Delete
[56] Fix | Delete
return $result;
[57] Fix | Delete
}
[58] Fix | Delete
[59] Fix | Delete
public static function get_elementor_post_types() {
[60] Fix | Delete
$elementor_post_types = get_post_types_by_support( 'elementor' );
[61] Fix | Delete
[62] Fix | Delete
return array_filter( $elementor_post_types, function ( $value ) {
[63] Fix | Delete
// Templates are handled in a separate process.
[64] Fix | Delete
return 'elementor_library' !== $value;
[65] Fix | Delete
} );
[66] Fix | Delete
}
[67] Fix | Delete
[68] Fix | Delete
public static function get_builtin_wp_post_types() {
[69] Fix | Delete
return [ 'post', 'page', 'nav_menu_item' ];
[70] Fix | Delete
}
[71] Fix | Delete
[72] Fix | Delete
public static function get_registered_cpt_names() {
[73] Fix | Delete
$post_types = get_post_types( [
[74] Fix | Delete
'public' => true,
[75] Fix | Delete
'can_export' => true,
[76] Fix | Delete
'_builtin' => false,
[77] Fix | Delete
] );
[78] Fix | Delete
[79] Fix | Delete
unset(
[80] Fix | Delete
$post_types[ Landing_Pages_Module::CPT ],
[81] Fix | Delete
$post_types[ Source_Local::CPT ],
[82] Fix | Delete
$post_types[ Floating_Buttons_Module::CPT_FLOATING_BUTTONS ]
[83] Fix | Delete
);
[84] Fix | Delete
[85] Fix | Delete
return array_keys( $post_types );
[86] Fix | Delete
}
[87] Fix | Delete
[88] Fix | Delete
/**
[89] Fix | Delete
* Transform a string name to title format.
[90] Fix | Delete
*
[91] Fix | Delete
* @param $name
[92] Fix | Delete
*
[93] Fix | Delete
* @return string
[94] Fix | Delete
*/
[95] Fix | Delete
public static function transform_name_to_title( $name ): string {
[96] Fix | Delete
if ( empty( $name ) ) {
[97] Fix | Delete
return '';
[98] Fix | Delete
}
[99] Fix | Delete
[100] Fix | Delete
$title = str_replace( [ '-', '_' ], ' ', $name );
[101] Fix | Delete
[102] Fix | Delete
return ucwords( $title );
[103] Fix | Delete
}
[104] Fix | Delete
[105] Fix | Delete
public static function get_import_sessions( $should_run_cleanup = false ) {
[106] Fix | Delete
$import_sessions = get_option( Module::OPTION_KEY_ELEMENTOR_IMPORT_SESSIONS, [] );
[107] Fix | Delete
[108] Fix | Delete
if ( $should_run_cleanup ) {
[109] Fix | Delete
foreach ( $import_sessions as $session_id => $import_session ) {
[110] Fix | Delete
if ( ! isset( $import_session['runners'] ) && isset( $import_session['instance_data'] ) ) {
[111] Fix | Delete
$import_sessions[ $session_id ]['runners'] = $import_session['instance_data']['runners_import_metadata'] ?? [];
[112] Fix | Delete
[113] Fix | Delete
unset( $import_sessions[ $session_id ]['instance_data'] );
[114] Fix | Delete
}
[115] Fix | Delete
}
[116] Fix | Delete
[117] Fix | Delete
update_option( Module::OPTION_KEY_ELEMENTOR_IMPORT_SESSIONS, $import_sessions );
[118] Fix | Delete
}
[119] Fix | Delete
[120] Fix | Delete
return $import_sessions;
[121] Fix | Delete
}
[122] Fix | Delete
[123] Fix | Delete
public static function update_space_between_widgets_values( $space_between_widgets ) {
[124] Fix | Delete
$setting_exist = isset( $space_between_widgets['size'] );
[125] Fix | Delete
$already_processed = isset( $space_between_widgets['column'] );
[126] Fix | Delete
[127] Fix | Delete
if ( ! $setting_exist || $already_processed ) {
[128] Fix | Delete
return $space_between_widgets;
[129] Fix | Delete
}
[130] Fix | Delete
[131] Fix | Delete
$size = strval( $space_between_widgets['size'] );
[132] Fix | Delete
$space_between_widgets['column'] = $size;
[133] Fix | Delete
$space_between_widgets['row'] = $size;
[134] Fix | Delete
$space_between_widgets['isLinked'] = true;
[135] Fix | Delete
[136] Fix | Delete
return $space_between_widgets;
[137] Fix | Delete
}
[138] Fix | Delete
}
[139] Fix | Delete
[140] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function