| 1 |
<?php |
| 2 |
|
| 3 |
namespace Elementor\App\Modules\ImportExport; |
| 4 |
|
| 5 |
use Elementor\Core\Utils\Str; |
| 6 |
use Elementor\Modules\LandingPages\Module as Landing_Pages_Module; |
| 7 |
use Elementor\Modules\System_Info\Reporters\Server; |
| 8 |
use Elementor\TemplateLibrary\Source_Local; |
| 9 |
use Elementor\Utils as ElementorUtils; |
| 10 |
|
| 11 |
class Utils { |
| 12 |
|
| 13 |
public static function read_json_file( $path ) { |
| 14 |
if ( ! Str::ends_with( $path, '.json' ) ) { |
| 15 |
$path .= '.json'; |
| 16 |
} |
| 17 |
|
| 18 |
$file_content = ElementorUtils::file_get_contents( $path, true ); |
| 19 |
|
| 20 |
return $file_content ? json_decode( $file_content, true ) : []; |
| 21 |
} |
| 22 |
|
| 23 |
public static function map_old_new_post_ids( array $imported_data ) { |
| 24 |
$result = []; |
| 25 |
|
| 26 |
$result += $imported_data['templates']['succeed'] ?? []; |
| 27 |
|
| 28 |
if ( isset( $imported_data['content'] ) ) { |
| 29 |
foreach ( $imported_data['content'] as $post_type ) { |
| 30 |
$result += $post_type['succeed'] ?? []; |
| 31 |
} |
| 32 |
} |
| 33 |
|
| 34 |
if ( isset( $imported_data['wp-content'] ) ) { |
| 35 |
foreach ( $imported_data['wp-content'] as $post_type ) { |
| 36 |
$result += $post_type['succeed'] ?? []; |
| 37 |
} |
| 38 |
} |
| 39 |
|
| 40 |
return $result; |
| 41 |
} |
| 42 |
|
| 43 |
public static function map_old_new_term_ids( array $imported_data ) { |
| 44 |
$result = []; |
| 45 |
|
| 46 |
if ( ! isset( $imported_data['taxonomies'] ) ) { |
| 47 |
return $result; |
| 48 |
} |
| 49 |
|
| 50 |
foreach ( $imported_data['taxonomies'] as $post_type_taxonomies ) { |
| 51 |
foreach ( $post_type_taxonomies as $taxonomy ) { |
| 52 |
foreach ( $taxonomy as $term ) { |
| 53 |
$result[ $term['old_id'] ] = $term['new_id']; |
| 54 |
} |
| 55 |
} |
| 56 |
} |
| 57 |
|
| 58 |
return $result; |
| 59 |
} |
| 60 |
|
| 61 |
public static function get_elementor_post_types() { |
| 62 |
return [ 'post', 'page', 'e-landing-page' ]; |
| 63 |
} |
| 64 |
|
| 65 |
public static function get_builtin_wp_post_types() { |
| 66 |
return [ 'post', 'page', 'nav_menu_item' ]; |
| 67 |
} |
| 68 |
|
| 69 |
public static function get_registered_cpt_names() { |
| 70 |
$post_types = get_post_types( [ |
| 71 |
'public' => true, |
| 72 |
'can_export' => true, |
| 73 |
'_builtin' => false, |
| 74 |
] ); |
| 75 |
|
| 76 |
unset( |
| 77 |
$post_types[ Landing_Pages_Module::CPT ], |
| 78 |
$post_types[ Source_Local::CPT ] |
| 79 |
); |
| 80 |
|
| 81 |
return array_keys( $post_types ); |
| 82 |
} |
| 83 |
} |
| 84 |
|