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