| 1 |
<?php |
| 2 |
|
| 3 |
namespace Elementor\Modules\SiteNavigation; |
| 4 |
|
| 5 |
use Elementor\Core\Base\Module as Module_Base; |
| 6 |
use Elementor\Core\Experiments\Exceptions\Dependency_Exception; |
| 7 |
use Elementor\Core\Experiments\Manager as Experiments_Manager; |
| 8 |
use Elementor\Modules\SiteNavigation\Data\Controller; |
| 9 |
use Elementor\Modules\SiteNavigation\Rest_Fields\Page_User_Can; |
| 10 |
use Elementor\Plugin; |
| 11 |
use Elementor\Utils; |
| 12 |
|
| 13 |
|
| 14 |
if ( ! defined( 'ABSPATH' ) ) { |
| 15 |
exit; // Exit if accessed directly. |
| 16 |
} |
| 17 |
|
| 18 |
class Module extends Module_Base { |
| 19 |
const PAGES_PANEL_EXPERIMENT_NAME = 'pages_panel'; |
| 20 |
const PACKAGES = [ |
| 21 |
'editor-site-navigation', |
| 22 |
]; |
| 23 |
/** |
| 24 |
* Initialize the Site navigation module. |
| 25 |
* |
| 26 |
* @return void |
| 27 |
* @throws \Exception If the experiment registration fails. |
| 28 |
*/ |
| 29 |
public function __construct() { |
| 30 |
Plugin::$instance->data_manager_v2->register_controller( new Controller() ); |
| 31 |
|
| 32 |
$this->register_pages_panel_experiment(); |
| 33 |
|
| 34 |
add_filter( 'elementor/editor/v2/packages', fn( $packages ) => $this->add_packages( $packages ) ); |
| 35 |
|
| 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(); |
| 48 |
} |
| 49 |
} |
| 50 |
|
| 51 |
/** |
| 52 |
* Retrieve the module name. |
| 53 |
* |
| 54 |
* @return string |
| 55 |
*/ |
| 56 |
public function get_name() { |
| 57 |
return 'site-navigation'; |
| 58 |
} |
| 59 |
|
| 60 |
/** |
| 61 |
* Register Experiment |
| 62 |
* |
| 63 |
* @since 3.16.0 |
| 64 |
* |
| 65 |
* @return void |
| 66 |
*/ |
| 67 |
private function register_pages_panel_experiment() { |
| 68 |
Plugin::$instance->experiments->add_feature( [ |
| 69 |
'name' => self::PAGES_PANEL_EXPERIMENT_NAME, |
| 70 |
'title' => esc_html__( 'Pages Panel', 'elementor' ), |
| 71 |
'release_status' => Experiments_Manager::RELEASE_STATUS_ALPHA, |
| 72 |
'default' => Experiments_Manager::STATE_INACTIVE, |
| 73 |
'hidden' => true, |
| 74 |
] ); |
| 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 |
} |
| 86 |
} |
| 87 |
|