| @@ -240,9 +240,9 @@ | ||
| 240 | 240 | * @since 2.0.0 |
| 241 | 241 | * |
| 242 | 242 | * @return array|WP_Error array on success, WP_Error on failure. |
| 243 | 243 | */ |
| 244 | - public function create_page( $id, $title, $importer = null ) { | |
| 244 | + public function create_page( $id, $title, $importer = null, $settings = [] ) { | |
| 245 | 245 | $template_data = $importer->get_content( $id ); |
| 246 | 246 | |
| 247 | 247 | if ( is_wp_error( $template_data ) ) { |
| 248 | 248 | return $template_data; |
| @@ -247,8 +247,12 @@ | ||
| 247 | 247 | if ( is_wp_error( $template_data ) ) { |
| 248 | 248 | return $template_data; |
| 249 | 249 | } |
| 250 | 250 | |
| 251 | + if ( ! empty( $settings ) && ! empty( $template_data['content'] ) && is_array( $template_data['content'] ) ) { | |
| 252 | + $template_data['content'] = \Templately\Core\Importer\Utils\ElementorSettingsMerger::merge( $template_data['content'], $settings ); | |
| 253 | + } | |
| 254 | + | |
| 251 | 255 | $importer = new ElementorImporter; |
| 252 | 256 | $template_data = $importer->get_data( $template_data ); |
| 253 | 257 | |
| 254 | 258 | if ( ! empty( $title ) ) { |
| @@ -281,9 +285,9 @@ | ||
| 281 | 285 | 'visit' => get_permalink( $inserted_ID ) |
| 282 | 286 | ]; |
| 283 | 287 | } |
| 284 | 288 | |
| 285 | - public function import_in_library( $id, $importer = null ) { | |
| 289 | + public function import_in_library( $id, $importer = null, $settings = [] ) { | |
| 286 | 290 | $template_data = $importer->get_content( $id, 'elementor', 'remote' ); |
| 287 | 291 | |
| 288 | 292 | if ( is_wp_error( $template_data ) ) { |
| 289 | 293 | return $template_data; |
| @@ -288,8 +292,12 @@ | ||
| 288 | 292 | if ( is_wp_error( $template_data ) ) { |
| 289 | 293 | return $template_data; |
| 290 | 294 | } |
| 291 | 295 | |
| 296 | + if ( ! empty( $settings ) && ! empty( $template_data['content'] ) && is_array( $template_data['content'] ) ) { | |
| 297 | + $template_data['content'] = \Templately\Core\Importer\Utils\ElementorSettingsMerger::merge( $template_data['content'], $settings ); | |
| 298 | + } | |
| 299 | + | |
| 292 | 300 | $importer = new ElementorImporter; |
| 293 | 301 | $imported_template = $importer->import_in_library( $template_data ); |
| 294 | 302 | |
| 295 | 303 | if( is_wp_error( $imported_template ) ) { |
| @@ -328,6 +336,34 @@ | ||
| 328 | 336 | public function insert( $data ) { |
| 329 | 337 | $importer = new ElementorImporter(); |
| 330 | 338 | |
| 331 | 339 | return $importer->get_data( $data ); |
| 340 | + } | |
| 341 | + | |
| 342 | + /** | |
| 343 | + * Filter Child Type | |
| 344 | + * | |
| 345 | + * @param $child_type | |
| 346 | + * @param $element_data | |
| 347 | + * @param $element | |
| 348 | + * | |
| 349 | + * @return mixed | |
| 350 | + */ | |
| 351 | + public static function filter_child_type( $child_type, $element_data, $element ) { | |
| 352 | + // Fix for Elementor Pro Promotion Widget | |
| 353 | + if ( is_a( $element, 'Elementor\Modules\Promotions\Widgets\Pro_Widget_Promotion' ) || ( is_object( $element ) && 'pro-promotion' === $element->get_name() ) ) { | |
| 354 | + $el_types = array_keys( Plugin::$instance->elements_manager->get_element_types() ); | |
| 355 | + | |
| 356 | + if ( isset( $element_data['elType'] ) && in_array( $element_data['elType'], $el_types, true ) ) { | |
| 357 | + return Plugin::$instance->elements_manager->get_element_types( $element_data['elType'] ); | |
| 358 | + } | |
| 359 | + | |
| 360 | + if ( ! isset( $element_data['widgetType'] ) ) { | |
| 361 | + return null; | |
| 362 | + } | |
| 363 | + | |
| 364 | + return Plugin::$instance->widgets_manager->get_widget_types( $element_data['widgetType'] ); | |
| 365 | + } | |
| 366 | + | |
| 367 | + return $child_type; | |
| 332 | 368 | } |
| 333 | 369 | } |