PluginProbe
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! / 2.2.2
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! v2.2.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 +19 -119 3.6.62.2.2 View file →
@@ -8,9 +8,8 @@
8 8 use Elementor\Core\Settings\Page\Model;
9 9
10 10 use Elementor\Plugin as ElementorPlugin;
11 11 use Elementor\TemplateLibrary\Source_Local as ElementorLocal;
12 -use Templately\Core\Importer\Utils\Utils;
13 12
14 13 class Elementor extends ElementorLocal {
15 14 /**
16 15 * Get template data.
@@ -21,45 +20,13 @@
21 20 *
22 21 * @return array Remote Template data.
23 22 */
24 23 public function get_data( array $args ) {
25 - Utils::add_gd_editor_filter();
26 24 ElementorPlugin::$instance->editor->set_edit_mode( true );
27 25
28 26 $args['content'] = $this->replace_elements_ids( $args['content'] );
29 27 $args['content'] = $this->process_export_import_content( $args['content'], 'on_import' );
30 28
31 - $args['content'] = $this->iterate_data(
32 - $args['content'], function( $element_data ) {
33 - // A widget with null/missing widgetType causes get_widget_types(null) to return ALL
34 - // registered widgets as an array. The subsequent get_default_args() call then crashes
35 - // with "Call to a member function get_default_args() on array". Guard early.
36 - if ( 'widget' === ( $element_data['elType'] ?? '' ) && ! isset( $element_data['widgetType'] ) ) {
37 - return null;
38 - }
39 -
40 - try {
41 - $element = ElementorPlugin::$instance->elements_manager->create_element_instance( $element_data );
42 - } catch ( \Throwable $e ) {
43 - return null;
44 - }
45 -
46 - // If the widget/element doesn't exist, e.g. a deactivated plugin's widget
47 - if ( ! $element ) {
48 - return null;
49 - }
50 -
51 - return $element_data;
52 - }
53 - );
54 -
55 - if (!isset($args['page_settings'])) {
56 - $args['page_settings'] = array();
57 - }
58 - if(!isset($args['page_settings']["template"])){
59 - $args['page_settings']["template"] = "elementor_header_footer";
60 - }
61 -
62 29 // $post_id = false; // FIXME: need to check later on.
63 30 // $document = ElementorPlugin::$instance->documents->get( $post_id );
64 31 // if ( $document ) {
65 32 // $args['content'] = $document->get_elements_raw_data( $args['content'], true );
@@ -77,42 +44,22 @@
77 44 if ( ! is_array( $content ) ) {
78 45 return new WP_Error( 'file_error', 'Invalid File' );
79 46 }
80 47
81 - // type is already resolved by Platform::resolve_library_type() before reaching here.
82 - // Validate it exists; fall back to 'page_single' if somehow unregistered.
83 - $type = $data['type'] ?? 'page_single';
84 - $registered_types = templately()->theme_builder::$templates_manager->get_template_types();
85 - if ( ! isset( $registered_types[ $type ] ) ) {
86 - $type = 'page_single';
87 - }
48 + $page_settings = $this->page_settings( $data );
88 49
89 - $factory = new \Templately\Builder\Factory\TemplateFactory( 'elementor' );
90 -
91 - $template = $factory->create( $type, [
92 - 'post_title' => $data['title'],
93 - 'post_status' => 'publish',
94 - 'post_type' => 'templately_library',
50 + $template_id = $this->save_item( [
51 + 'content' => $content,
52 + 'title' => $data['title'],
53 + 'type' => $data['type'],
54 + 'page_settings' => $page_settings,
95 55 ] );
96 56
97 - if ( is_wp_error( $template ) ) {
98 - return $template;
57 + if ( is_wp_error( $template_id ) ) {
58 + return $template_id;
99 59 }
100 60
101 - $template->import( array_merge( $data, [
102 - 'import_settings' => [
103 - 'title' => $data['title'],
104 - 'type' => $type,
105 - ]
106 - ] ) );
107 -
108 - $post_id = $template->get_main_id();
109 -
110 - return [
111 - 'template_id' => $post_id,
112 - 'edit_link' => get_edit_post_link( $post_id, 'internal' ),
113 - 'url' => get_permalink( $post_id ),
114 - ];
61 + return $this->get_item( $template_id );
115 62 }
116 63
117 64 public function create_page( $template_data ){
118 65 $page_settings = $this->page_settings( $template_data );
@@ -124,13 +71,10 @@
124 71 ];
125 72
126 73 $template_data = wp_parse_args( $template_data, $defaults );
127 74
128 - // Elementor has no 'block' document type; map it to 'section' (saved section).
129 - $doc_type = ( 'block' === $template_data['type'] ) ? 'section' : $template_data['type'];
130 -
131 75 $document = ElementorPlugin::$instance->documents->create(
132 - $doc_type,
76 + $template_data['type'],
133 77 [
134 78 'post_title' => $template_data['post_title'],
135 79 'post_status' => $template_data['status'],
136 80 'post_type' => 'page',
@@ -160,66 +104,22 @@
160 104 */
161 105 private function page_settings( $template_data ) {
162 106 $page_settings = [];
163 107
164 - if (!isset($template_data['page_settings'])) {
165 - $template_data['page_settings'] = array();
166 - }
108 + if ( ! empty( $template_data['page_settings'] ) ) {
109 + $page = new Model( [
110 + 'id' => 0,
111 + 'settings' => $template_data['page_settings'],
112 + ] );
167 113
168 - if(!isset($template_data['page_settings']["template"])){
169 - $template_data['page_settings']["template"] = "elementor_header_footer";
170 - }
114 + $page_settings_data = $this->process_element_export_import_content( $page, 'on_import' );
171 115
172 - $page = new Model([
173 - 'id' => 0,
174 - 'settings' => $template_data['page_settings'],
175 - ]);
176 -
177 - $page_settings_data = $this->process_element_export_import_content($page, 'on_import');
178 -
179 - if (!empty($page_settings_data['settings'])) {
180 - $page_settings = $page_settings_data['settings'];
116 + if ( ! empty( $page_settings_data['settings'] ) ) {
117 + $page_settings = $page_settings_data['settings'];
118 + }
181 119 }
182 120
183 121 return $page_settings;
184 - }
185 -
186 - /**
187 - * Iterate data.
188 - *
189 - * Accept any type of Elementor data and a callback function. The callback
190 - * function runs recursively for each element and his child elements.
191 - *
192 - * @since 1.0.0
193 - * @access public
194 - *
195 - * @param array $data_container Any type of elementor data.
196 - * @param callable $callback A function to iterate data by.
197 - * @param array $args Array of args pointers for passing parameters in & out of the callback
198 - *
199 - * @return mixed Iterated data.
200 - */
201 - public function iterate_data( $data_container, $callback, $args = [] ) {
202 - if ( isset( $data_container['elType'] ) ) {
203 - if ( ! empty( $data_container['elements'] ) ) {
204 - $data_container['elements'] = $this->iterate_data( $data_container['elements'], $callback, $args );
205 - }
206 -
207 - return call_user_func( $callback, $data_container, $args );
208 - }
209 -
210 - foreach ( $data_container as $element_key => $element_value ) {
211 - $element_data = $this->iterate_data( $data_container[ $element_key ], $callback, $args );
212 -
213 - if ( null === $element_data ) {
214 - unset($data_container[ $element_key ]);
215 - continue;
216 - }
217 -
218 - $data_container[ $element_key ] = $element_data;
219 - }
220 -
221 - return array_values($data_container);
222 122 }
223 123
224 124 }
225 125