PluginProbe
Elementor Website Builder – more than just a page builder / 3.11.5
Elementor Website Builder – more than just a page builder v3.11.5
4.3.0-beta2 4.3.0-beta1 4.2.4 4.2.3 4.2.2 4.2.1 4.2.0 4.1.5 4.2.0-beta2 4.2.0-dev2 4.2.0-beta1 4.1.4 4.1.3 4.1.2 4.1.1 4.1.0 4.1.0-beta3 4.1.0-dev3 4.0.9 4.1.0-beta2 4.1.0-dev2 4.0.8 4.1.0-beta1 4.1.0-dev1 4.0.7 All 451 releases
elementor / app / modules / import-export / utils.php

utils.php in Elementor Website Builder – more than just a page builder 3.11.5, at app/modules/import-export/utils.php

101 lines 2.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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 /**
85 * Transform a string name to title format.
86 *
87 * @param $name
88 *
89 * @return string
90 */
91 public static function transform_name_to_title( $name ): string {
92 if ( empty( $name ) ) {
93 return '';
94 }
95
96 $title = str_replace( [ '-', '_' ], ' ', $name );
97
98 return ucwords( $title );
99 }
100 }
101