| @@ -24,33 +24,16 @@ | ||
| 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 | - | |
| 34 | 28 | $args['content'] = $this->replace_elements_ids( $args['content'] ); |
| 35 | 29 | $args['content'] = $this->process_export_import_content( $args['content'], 'on_import' ); |
| 36 | 30 | |
| 37 | 31 | $args['content'] = $this->iterate_data( |
| 38 | 32 | $args['content'], function( $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 | - } | |
| 33 | + $element = ElementorPlugin::$instance->elements_manager->create_element_instance( $element_data ); | |
| 45 | 34 | |
| 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 | |
| 35 | + // If the widget/element isn't exist, like a plugin that creates a widget but deactivated | |
| 53 | 36 | if ( ! $element ) { |
| 54 | 37 | return null; |
| 55 | 38 | } |
| 56 | 39 | |
| @@ -83,42 +66,24 @@ | ||
| 83 | 66 | if ( ! is_array( $content ) ) { |
| 84 | 67 | return new WP_Error( 'file_error', 'Invalid File' ); |
| 85 | 68 | } |
| 86 | 69 | |
| 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 | - } | |
| 70 | + $page_settings = $this->page_settings( $data ); | |
| 94 | 71 | |
| 95 | - $factory = new \Templately\Builder\Factory\TemplateFactory( 'elementor' ); | |
| 72 | + // TODO: type check for (theme builder) | |
| 96 | 73 | |
| 97 | - $template = $factory->create( $type, [ | |
| 98 | - 'post_title' => $data['title'], | |
| 99 | - 'post_status' => 'publish', | |
| 100 | - 'post_type' => 'templately_library', | |
| 74 | + $template_id = $this->save_item( [ | |
| 75 | + 'content' => $content, | |
| 76 | + 'title' => $data['title'], | |
| 77 | + 'type' => $data['type'], | |
| 78 | + 'page_settings' => $page_settings, | |
| 101 | 79 | ] ); |
| 102 | 80 | |
| 103 | - if ( is_wp_error( $template ) ) { | |
| 104 | - return $template; | |
| 81 | + if ( is_wp_error( $template_id ) ) { | |
| 82 | + return $template_id; | |
| 105 | 83 | } |
| 106 | 84 | |
| 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 | - ]; | |
| 85 | + return $this->get_item( $template_id ); | |
| 121 | 86 | } |
| 122 | 87 | |
| 123 | 88 | public function create_page( $template_data ){ |
| 124 | 89 | $page_settings = $this->page_settings( $template_data ); |
| @@ -130,13 +95,10 @@ | ||
| 130 | 95 | ]; |
| 131 | 96 | |
| 132 | 97 | $template_data = wp_parse_args( $template_data, $defaults ); |
| 133 | 98 | |
| 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 | - | |
| 137 | 99 | $document = ElementorPlugin::$instance->documents->create( |
| 138 | - $doc_type, | |
| 100 | + $template_data['type'], | |
| 139 | 101 | [ |
| 140 | 102 | 'post_title' => $template_data['post_title'], |
| 141 | 103 | 'post_status' => $template_data['status'], |
| 142 | 104 | 'post_type' => 'page', |