PluginProbe
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! / 3.7.2
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! v3.7.2
3.7.5 3.7.4 3.7.3 3.7.2 1-final 3.7.1 3.7.0 3.6.8 3.6.7 3.6.6 3.6.5 3.6.4 3.6.3 3.6.2 3.6.1 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.1 3.1.10 All 111 releases
← All changes | includes/Core/Importer/Elementor.php +52 -14 3.6.43.7.2 View file →
@@ -24,16 +24,33 @@
24 24 public function get_data( array $args ) {
25 25 Utils::add_gd_editor_filter();
26 26 ElementorPlugin::$instance->editor->set_edit_mode( true );
27 27
28 + // Ensure the Pro-promotion child-type fix is active for every import path (not just FSI),
29 + // otherwise saving a template that uses an unavailable Elementor Pro widget (e.g.
30 + // nested-carousel) fatals while Elementor resolves its nested children. See
31 + // \Templately\Core\Platform\Elementor::filter_child_type().
32 + \Templately\Core\Platform\Elementor::register_child_type_filter();
33 +
28 34 $args['content'] = $this->replace_elements_ids( $args['content'] );
29 35 $args['content'] = $this->process_export_import_content( $args['content'], 'on_import' );
30 36
31 37 $args['content'] = $this->iterate_data(
32 38 $args['content'], function( $element_data ) {
33 - $element = ElementorPlugin::$instance->elements_manager->create_element_instance( $element_data );
39 + // A widget with null/missing widgetType causes get_widget_types(null) to return ALL
40 + // registered widgets as an array. The subsequent get_default_args() call then crashes
41 + // with "Call to a member function get_default_args() on array". Guard early.
42 + if ( 'widget' === ( $element_data['elType'] ?? '' ) && ! isset( $element_data['widgetType'] ) ) {
43 + return null;
44 + }
34 45
35 - // If the widget/element isn't exist, like a plugin that creates a widget but deactivated
46 + try {
47 + $element = ElementorPlugin::$instance->elements_manager->create_element_instance( $element_data );
48 + } catch ( \Throwable $e ) {
49 + return null;
50 + }
51 +
52 + // If the widget/element doesn't exist, e.g. a deactivated plugin's widget
36 53 if ( ! $element ) {
37 54 return null;
38 55 }
39 56
@@ -66,24 +83,42 @@
66 83 if ( ! is_array( $content ) ) {
67 84 return new WP_Error( 'file_error', 'Invalid File' );
68 85 }
69 86
70 - $page_settings = $this->page_settings( $data );
87 + // type is already resolved by Platform::resolve_library_type() before reaching here.
88 + // Validate it exists; fall back to 'page_single' if somehow unregistered.
89 + $type = $data['type'] ?? 'page_single';
90 + $registered_types = templately()->theme_builder::$templates_manager->get_template_types();
91 + if ( ! isset( $registered_types[ $type ] ) ) {
92 + $type = 'page_single';
93 + }
71 94
72 - // TODO: type check for (theme builder)
95 + $factory = new \Templately\Builder\Factory\TemplateFactory( 'elementor' );
73 96
74 - $template_id = $this->save_item( [
75 - 'content' => $content,
76 - 'title' => $data['title'],
77 - 'type' => $data['type'],
78 - 'page_settings' => $page_settings,
97 + $template = $factory->create( $type, [
98 + 'post_title' => $data['title'],
99 + 'post_status' => 'publish',
100 + 'post_type' => 'templately_library',
79 101 ] );
80 102
81 - if ( is_wp_error( $template_id ) ) {
82 - return $template_id;
103 + if ( is_wp_error( $template ) ) {
104 + return $template;
83 105 }
84 106
85 - return $this->get_item( $template_id );
107 + $template->import( array_merge( $data, [
108 + 'import_settings' => [
109 + 'title' => $data['title'],
110 + 'type' => $type,
111 + ]
112 + ] ) );
113 +
114 + $post_id = $template->get_main_id();
115 +
116 + return [
117 + 'template_id' => $post_id,
118 + 'edit_link' => get_edit_post_link( $post_id, 'internal' ),
119 + 'url' => get_permalink( $post_id ),
120 + ];
86 121 }
87 122
88 123 public function create_page( $template_data ){
89 124 $page_settings = $this->page_settings( $template_data );
@@ -94,11 +129,14 @@
94 129 'status' => current_user_can( 'publish_posts' ) ? 'publish' : 'pending',
95 130 ];
96 131
97 132 $template_data = wp_parse_args( $template_data, $defaults );
98 - $type = $template_data['type'] == 'block' ? 'section' : $template_data['type'];
133 +
134 + // Elementor has no 'block' document type; map it to 'section' (saved section).
135 + $doc_type = ( 'block' === $template_data['type'] ) ? 'section' : $template_data['type'];
136 +
99 137 $document = ElementorPlugin::$instance->documents->create(
100 - $type,
138 + $doc_type,
101 139 [
102 140 'post_title' => $template_data['post_title'],
103 141 'post_status' => $template_data['status'],
104 142 'post_type' => 'page',