| @@ -1,7 +1,8 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | namespace Elementor; |
| 3 | 3 | |
| 4 | +use Elementor\Core\Experiments\Manager; | |
| 4 | 5 | use Elementor\Includes\Elements\Container; |
| 5 | 6 | |
| 6 | 7 | if ( ! defined( 'ABSPATH' ) ) { |
| 7 | 8 | exit; // Exit if accessed directly. |
| @@ -16,14 +17,8 @@ | ||
| 16 | 17 | * @since 1.0.0 |
| 17 | 18 | */ |
| 18 | 19 | class Elements_Manager { |
| 19 | 20 | |
| 20 | - const CATEGORY_ATOMIC_ELEMENTS = 'v4-elements'; | |
| 21 | - const CATEGORY_ATOMIC_FORM = 'atomic-form'; | |
| 22 | - const CATEGORY_FAVORITES = 'favorites'; | |
| 23 | - const CATEGORY_ANGIE_WIDGETS = 'angie-widgets'; | |
| 24 | - const CATEGORY_CUSTOM_WIDGETS = 'custom-widgets'; | |
| 25 | - | |
| 26 | 21 | /** |
| 27 | 22 | * Element types. |
| 28 | 23 | * |
| 29 | 24 | * Holds the list of all the element types. |
| @@ -40,9 +35,9 @@ | ||
| 40 | 35 | * Holds the list of all the element categories. |
| 41 | 36 | * |
| 42 | 37 | * @access private |
| 43 | 38 | * |
| 44 | - * @var $categories | |
| 39 | + * @var | |
| 45 | 40 | */ |
| 46 | 41 | private $categories; |
| 47 | 42 | |
| 48 | 43 | /** |
| @@ -72,11 +67,15 @@ | ||
| 72 | 67 | * |
| 73 | 68 | * @return Element_Base|null Element instance if element created, or null |
| 74 | 69 | * otherwise. |
| 75 | 70 | */ |
| 76 | - public function create_element_instance( array $element_data, array $element_args = [], ?Element_Base $element_type = null ) { | |
| 71 | + public function create_element_instance( array $element_data, array $element_args = [], Element_Base $element_type = null ) { | |
| 77 | 72 | if ( null === $element_type ) { |
| 78 | - $element_type = $this->get_element( $element_data['elType'], isset( $element_data['widgetType'] ) ? $element_data['widgetType'] : null ); | |
| 73 | + if ( 'widget' === $element_data['elType'] ) { | |
| 74 | + $element_type = Plugin::$instance->widgets_manager->get_widget_types( $element_data['widgetType'] ); | |
| 75 | + } else { | |
| 76 | + $element_type = $this->get_element_types( $element_data['elType'] ); | |
| 77 | + } | |
| 79 | 78 | } |
| 80 | 79 | |
| 81 | 80 | if ( ! $element_type ) { |
| 82 | 81 | return null; |
| @@ -94,20 +93,8 @@ | ||
| 94 | 93 | |
| 95 | 94 | return $element; |
| 96 | 95 | } |
| 97 | 96 | |
| 98 | - public function get_element( string $el_type, ?string $widget_type = null ) { | |
| 99 | - $element = null; | |
| 100 | - | |
| 101 | - if ( 'widget' === $el_type ) { | |
| 102 | - $element = Plugin::$instance->widgets_manager->get_widget_types( $widget_type ); | |
| 103 | - } else { | |
| 104 | - $element = $this->get_element_types( $el_type ); | |
| 105 | - } | |
| 106 | - | |
| 107 | - return $element; | |
| 108 | - } | |
| 109 | - | |
| 110 | 97 | /** |
| 111 | 98 | * Get element categories. |
| 112 | 99 | * |
| 113 | 100 | * Retrieve the list of categories the element belongs to. |
| @@ -289,12 +276,8 @@ | ||
| 289 | 276 | * @access private |
| 290 | 277 | */ |
| 291 | 278 | private function init_categories() { |
| 292 | 279 | $this->categories = [ |
| 293 | - self::CATEGORY_ATOMIC_ELEMENTS => [ | |
| 294 | - 'title' => esc_html__( 'Atomic Elements', 'elementor' ), | |
| 295 | - 'hideIfEmpty' => true, | |
| 296 | - ], | |
| 297 | 280 | 'layout' => [ |
| 298 | 281 | 'title' => esc_html__( 'Layout', 'elementor' ), |
| 299 | 282 | 'hideIfEmpty' => true, |
| 300 | 283 | ], |
| @@ -303,66 +286,26 @@ | ||
| 303 | 286 | 'icon' => 'eicon-font', |
| 304 | 287 | ], |
| 305 | 288 | 'pro-elements' => [ |
| 306 | 289 | 'title' => esc_html__( 'Pro', 'elementor' ), |
| 307 | - 'promotion' => [ | |
| 308 | - 'url' => esc_url( 'https://go.elementor.com/go-pro-section-pro-widget-panel/' ), | |
| 309 | - ], | |
| 310 | 290 | ], |
| 311 | - 'helloplus' => [ | |
| 312 | - 'title' => esc_html__( 'Hello+', 'elementor' ), | |
| 313 | - 'hideIfEmpty' => true, | |
| 314 | - ], | |
| 315 | 291 | 'general' => [ |
| 316 | 292 | 'title' => esc_html__( 'General', 'elementor' ), |
| 317 | 293 | 'icon' => 'eicon-font', |
| 318 | 294 | ], |
| 319 | - 'link-in-bio' => [ | |
| 320 | - 'title' => esc_html__( 'Link In Bio', 'elementor' ), | |
| 321 | - 'hideIfEmpty' => true, | |
| 322 | - ], | |
| 323 | 295 | 'theme-elements' => [ |
| 324 | 296 | 'title' => esc_html__( 'Site', 'elementor' ), |
| 325 | 297 | 'active' => false, |
| 326 | - 'promotion' => [ | |
| 327 | - 'url' => esc_url( 'https://go.elementor.com/go-pro-section-site-widget-panel/' ), | |
| 328 | - ], | |
| 329 | 298 | ], |
| 330 | 299 | 'woocommerce-elements' => [ |
| 331 | 300 | 'title' => esc_html__( 'WooCommerce', 'elementor' ), |
| 332 | 301 | 'active' => false, |
| 333 | - 'promotion' => [ | |
| 334 | - 'url' => esc_url( 'https://go.elementor.com/go-pro-section-woocommerce-widget-panel/' ), | |
| 335 | - ], | |
| 336 | 302 | ], |
| 337 | 303 | ]; |
| 338 | 304 | |
| 339 | - if ( Plugin::$instance->experiments->is_feature_active( 'e_atomic_elements' ) ) { | |
| 340 | - $atomic_form_category = [ | |
| 341 | - 'title' => esc_html__( 'Atomic Form', 'elementor' ), | |
| 342 | - ]; | |
| 343 | - | |
| 344 | - if ( Utils::has_pro() && Plugin::$instance->experiments->is_feature_active( 'e_pro_atomic_form' ) ) { | |
| 345 | - $atomic_form_category['hideIfEmpty'] = true; | |
| 346 | - } elseif ( ! Utils::has_pro() ) { | |
| 347 | - $atomic_form_category['hideIfEmpty'] = false; | |
| 348 | - $atomic_form_category['promotion'] = [ | |
| 349 | - 'url' => esc_url( 'https://go.elementor.com/go-pro-atomic-form-section/' ), | |
| 350 | - ]; | |
| 351 | - } else { | |
| 352 | - $atomic_form_category['hideIfEmpty'] = true; | |
| 353 | - } | |
| 354 | - | |
| 355 | - $this->categories = array_merge( | |
| 356 | - [ self::CATEGORY_ATOMIC_ELEMENTS => $this->categories[ self::CATEGORY_ATOMIC_ELEMENTS ] ], | |
| 357 | - [ self::CATEGORY_ATOMIC_FORM => $atomic_form_category ], | |
| 358 | - array_diff_key( $this->categories, [ self::CATEGORY_ATOMIC_ELEMENTS => true ] ) | |
| 359 | - ); | |
| 360 | - } | |
| 361 | - | |
| 362 | 305 | // Not using the `add_category` because it doesn't allow 3rd party to inject a category on top the others. |
| 363 | 306 | $this->categories = array_merge_recursive( [ |
| 364 | - self::CATEGORY_FAVORITES => [ | |
| 307 | + 'favorites' => [ | |
| 365 | 308 | 'title' => esc_html__( 'Favorites', 'elementor' ), |
| 366 | 309 | 'icon' => 'eicon-heart', |
| 367 | 310 | 'sort' => 'a-z', |
| 368 | 311 | 'hideIfEmpty' => false, |
| @@ -383,63 +326,13 @@ | ||
| 383 | 326 | * @param Elements_Manager $this Elements manager instance. |
| 384 | 327 | */ |
| 385 | 328 | do_action( 'elementor/elements/categories_registered', $this ); |
| 386 | 329 | |
| 387 | - $this->promote_category_after( self::CATEGORY_ANGIE_WIDGETS, [ self::CATEGORY_ATOMIC_FORM, self::CATEGORY_ATOMIC_ELEMENTS ] ); | |
| 388 | - $this->promote_category_after( self::CATEGORY_CUSTOM_WIDGETS, [ self::CATEGORY_ATOMIC_FORM, self::CATEGORY_ATOMIC_ELEMENTS ] ); | |
| 389 | - | |
| 390 | 330 | $this->categories['wordpress'] = [ |
| 391 | 331 | 'title' => esc_html__( 'WordPress', 'elementor' ), |
| 392 | 332 | 'icon' => 'eicon-wordpress', |
| 393 | 333 | 'active' => false, |
| 394 | 334 | ]; |
| 395 | - } | |
| 396 | - | |
| 397 | - public function enqueue_elements_styles() { | |
| 398 | - foreach ( $this->get_element_types() as $element ) { | |
| 399 | - $element->enqueue_styles(); | |
| 400 | - } | |
| 401 | - } | |
| 402 | - | |
| 403 | - public function enqueue_elements_scripts() { | |
| 404 | - foreach ( $this->get_element_types() as $element ) { | |
| 405 | - $element->enqueue_scripts(); | |
| 406 | - } | |
| 407 | - } | |
| 408 | - | |
| 409 | - public function register_frontend_handlers() { | |
| 410 | - foreach ( $this->get_element_types() as $element ) { | |
| 411 | - $element->register_frontend_handlers(); | |
| 412 | - } | |
| 413 | - } | |
| 414 | - | |
| 415 | - private function promote_category_after( string $category_name, array $after_candidates ): void { | |
| 416 | - if ( ! isset( $this->categories[ $category_name ] ) ) { | |
| 417 | - return; | |
| 418 | - } | |
| 419 | - | |
| 420 | - $after = null; | |
| 421 | - | |
| 422 | - foreach ( $after_candidates as $candidate ) { | |
| 423 | - if ( isset( $this->categories[ $candidate ] ) ) { | |
| 424 | - $after = $candidate; | |
| 425 | - break; | |
| 426 | - } | |
| 427 | - } | |
| 428 | - | |
| 429 | - if ( ! $after ) { | |
| 430 | - return; | |
| 431 | - } | |
| 432 | - | |
| 433 | - $category = $this->categories[ $category_name ]; | |
| 434 | - unset( $this->categories[ $category_name ] ); | |
| 435 | - | |
| 436 | - $position = array_search( $after, array_keys( $this->categories ), true ) + 1; | |
| 437 | - $this->categories = array_merge( | |
| 438 | - array_slice( $this->categories, 0, $position, true ), | |
| 439 | - [ $category_name => $category ], | |
| 440 | - array_slice( $this->categories, $position, null, true ) | |
| 441 | - ); | |
| 442 | 335 | } |
| 443 | 336 | |
| 444 | 337 | /** |
| 445 | 338 | * Require files. |