| @@ -2,30 +2,24 @@ | ||
| 2 | 2 | |
| 3 | 3 | namespace Elementor\Modules\SiteNavigation; |
| 4 | 4 | |
| 5 | 5 | use Elementor\Core\Base\Module as Module_Base; |
| 6 | -use Elementor\Core\Experiments\Exceptions\Dependency_Exception; | |
| 7 | 6 | use Elementor\Core\Experiments\Manager as Experiments_Manager; |
| 8 | 7 | use Elementor\Modules\SiteNavigation\Data\Controller; |
| 9 | -use Elementor\Modules\SiteNavigation\Rest_Fields\Page_User_Can; | |
| 10 | 8 | use Elementor\Plugin; |
| 11 | 9 | use Elementor\Utils; |
| 12 | 10 | |
| 13 | - | |
| 14 | 11 | if ( ! defined( 'ABSPATH' ) ) { |
| 15 | - exit; // Exit if accessed directly. | |
| 12 | + exit; // Exit if accessed directly | |
| 16 | 13 | } |
| 17 | 14 | |
| 18 | 15 | class Module extends Module_Base { |
| 19 | 16 | const PAGES_PANEL_EXPERIMENT_NAME = 'pages_panel'; |
| 20 | - const PACKAGES = [ | |
| 21 | - 'editor-site-navigation', | |
| 22 | - ]; | |
| 17 | + | |
| 23 | 18 | /** |
| 24 | - * Initialize the Site navigation module. | |
| 25 | - * | |
| 19 | + * Initialize the Container-Converter module. | |
| 26 | 20 | * @return void |
| 27 | - * @throws \Exception If the experiment registration fails. | |
| 21 | + * @throws \Exception | |
| 28 | 22 | */ |
| 29 | 23 | public function __construct() { |
| 30 | 24 | Plugin::$instance->data_manager_v2->register_controller( new Controller() ); |
| 31 | 25 | |
| @@ -30,22 +24,16 @@ | ||
| 30 | 24 | Plugin::$instance->data_manager_v2->register_controller( new Controller() ); |
| 31 | 25 | |
| 32 | 26 | $this->register_pages_panel_experiment(); |
| 33 | 27 | |
| 34 | - add_filter( 'elementor/editor/v2/packages', fn( $packages ) => $this->add_packages( $packages ) ); | |
| 28 | + if ( Plugin::$instance->experiments->is_feature_active( self::PAGES_PANEL_EXPERIMENT_NAME ) ) { | |
| 29 | + add_filter( 'elementor/editor/v2/scripts/env', function ( $env ) { | |
| 30 | + $env['@elementor/editor-site-navigation'] = [ | |
| 31 | + 'is_pages_panel_active' => true, | |
| 32 | + ]; | |
| 35 | 33 | |
| 36 | - add_filter( 'elementor/editor/v2/scripts/env', function( $env ) { | |
| 37 | - $env['@elementor/editor-site-navigation'] = [ | |
| 38 | - 'is_pages_panel_active' => Plugin::$instance->experiments->is_feature_active( | |
| 39 | - self::PAGES_PANEL_EXPERIMENT_NAME | |
| 40 | - ), | |
| 41 | - ]; | |
| 42 | - | |
| 43 | - return $env; | |
| 44 | - } ); | |
| 45 | - | |
| 46 | - if ( Plugin::$instance->experiments->is_feature_active( self::PAGES_PANEL_EXPERIMENT_NAME ) ) { | |
| 47 | - $this->register_rest_fields(); | |
| 34 | + return $env; | |
| 35 | + } ); | |
| 48 | 36 | } |
| 49 | 37 | } |
| 50 | 38 | |
| 51 | 39 | /** |
| @@ -57,13 +45,27 @@ | ||
| 57 | 45 | return 'site-navigation'; |
| 58 | 46 | } |
| 59 | 47 | |
| 60 | 48 | /** |
| 49 | + * Determine whether the module is active. | |
| 50 | + * | |
| 51 | + * @return bool | |
| 52 | + */ | |
| 53 | + public static function is_active() { | |
| 54 | + if ( Utils::is_elementor_tests() ) { | |
| 55 | + return true; | |
| 56 | + } | |
| 57 | + | |
| 58 | + return Plugin::$instance->experiments->is_feature_active( 'editor_v2' ); | |
| 59 | + } | |
| 60 | + | |
| 61 | + /** | |
| 61 | 62 | * Register Experiment |
| 62 | 63 | * |
| 63 | 64 | * @since 3.16.0 |
| 64 | 65 | * |
| 65 | 66 | * @return void |
| 67 | + * @throws \Exception | |
| 66 | 68 | */ |
| 67 | 69 | private function register_pages_panel_experiment() { |
| 68 | 70 | Plugin::$instance->experiments->add_feature( [ |
| 69 | 71 | 'name' => self::PAGES_PANEL_EXPERIMENT_NAME, |
| @@ -70,17 +72,10 @@ | ||
| 70 | 72 | 'title' => esc_html__( 'Pages Panel', 'elementor' ), |
| 71 | 73 | 'release_status' => Experiments_Manager::RELEASE_STATUS_ALPHA, |
| 72 | 74 | 'default' => Experiments_Manager::STATE_INACTIVE, |
| 73 | 75 | 'hidden' => true, |
| 76 | + 'dependencies' => [ | |
| 77 | + 'editor_v2', | |
| 78 | + ], | |
| 74 | 79 | ] ); |
| 75 | - } | |
| 76 | - | |
| 77 | - private function register_rest_fields() { | |
| 78 | - add_action( 'rest_api_init', function() { | |
| 79 | - ( new Page_User_Can() )->register_rest_field(); | |
| 80 | - } ); | |
| 81 | - } | |
| 82 | - | |
| 83 | - private function add_packages( $packages ) { | |
| 84 | - return array_merge( $packages, self::PACKAGES ); | |
| 85 | 80 | } |
| 86 | 81 | } |