PluginProbe
Elementor Website Builder – more than just a page builder / 3.26.4
Elementor Website Builder – more than just a page builder v3.26.4
4.3.0-beta2 4.3.0-beta1 4.2.4 4.2.3 4.2.2 4.2.1 4.2.0 4.1.5 4.2.0-beta2 4.2.0-dev2 4.2.0-beta1 4.1.4 4.1.3 4.1.2 4.1.1 4.1.0 4.1.0-beta3 4.1.0-dev3 4.0.9 4.1.0-beta2 4.1.0-dev2 4.0.8 4.1.0-beta1 4.1.0-dev1 4.0.7 All 451 releases
elementor / app / modules / kit-library / module.php

module.php in Elementor Website Builder – more than just a page builder 3.26.4, at app/modules/kit-library/module.php

118 lines 3.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Elementor\App\Modules\KitLibrary;
3
4 use Elementor\App\Modules\KitLibrary\Data\Repository;
5 use Elementor\Core\Admin\Menu\Admin_Menu_Manager;
6 use Elementor\Core\Admin\Menu\Main as MainMenu;
7 use Elementor\Plugin;
8 use Elementor\TemplateLibrary\Source_Local;
9 use Elementor\Core\Base\Module as BaseModule;
10 use Elementor\App\Modules\KitLibrary\Connect\Kit_Library;
11 use Elementor\Core\Common\Modules\Connect\Module as ConnectModule;
12 use Elementor\App\Modules\KitLibrary\Data\Kits\Controller as Kits_Controller;
13 use Elementor\App\Modules\KitLibrary\Data\Taxonomies\Controller as Taxonomies_Controller;
14 use Elementor\Core\Utils\Promotions\Filtered_Promotions_Manager;
15
16 if ( ! defined( 'ABSPATH' ) ) {
17 exit; // Exit if accessed directly
18 }
19
20 class Module extends BaseModule {
21 /**
22 * Get name.
23 *
24 * @access public
25 *
26 * @return string
27 */
28 public function get_name() {
29 return 'kit-library';
30 }
31
32 private function register_admin_menu( MainMenu $menu ) {
33 $menu->add_submenu( [
34 'page_title' => esc_html__( 'Kit Library', 'elementor' ),
35 'menu_title' => '<span id="e-admin-menu__kit-library">' . esc_html__( 'Kit Library', 'elementor' ) . '</span>',
36 'menu_slug' => Plugin::$instance->app->get_base_url() . '#/kit-library',
37 'index' => 40,
38 ] );
39 }
40
41 /**
42 * Register the admin menu the old way.
43 */
44 private function register_admin_menu_legacy( Admin_Menu_Manager $admin_menu ) {
45 $admin_menu->register(
46 Plugin::$instance->app->get_base_url() . '#/kit-library',
47 new Kit_Library_Menu_Item()
48 );
49 }
50
51 private function set_kit_library_settings() {
52 if ( ! Plugin::$instance->common ) {
53 return;
54 }
55
56 /** @var ConnectModule $connect */
57 $connect = Plugin::$instance->common->get_component( 'connect' );
58
59 /** @var Kit_Library $kit_library */
60 $kit_library = $connect->get_app( 'kit-library' );
61
62 Plugin::$instance->app->set_settings( 'kit-library', [
63 'has_access_to_module' => current_user_can( 'administrator' ),
64 'subscription_plans' => $this->apply_filter_subscription_plans( $connect->get_subscription_plans( 'kit-library' ) ),
65 'is_pro' => false,
66 'is_library_connected' => $kit_library->is_connected(),
67 'library_connect_url' => $kit_library->get_admin_url( 'authorize', [
68 'utm_source' => 'kit-library',
69 'utm_medium' => 'wp-dash',
70 'utm_campaign' => 'library-connect',
71 'utm_term' => '%%page%%', // Will be replaced in the frontend.
72 ] ),
73 'access_level' => ConnectModule::ACCESS_LEVEL_CORE,
74 'access_tier' => ConnectModule::ACCESS_TIER_FREE,
75 'app_url' => Plugin::$instance->app->get_base_url() . '#/' . $this->get_name(),
76 ] );
77 }
78
79 private function apply_filter_subscription_plans( array $subscription_plans ): array {
80 foreach ( $subscription_plans as $key => $plan ) {
81 if ( null === $plan['promotion_url'] ) {
82 continue;
83 }
84
85 $subscription_plans[ $key ] = Filtered_Promotions_Manager::get_filtered_promotion_data(
86 $plan,
87 'elementor/kit_library/' . $key . '/promotion',
88 'promotion_url'
89 );
90 }
91
92 return $subscription_plans;
93 }
94
95 /**
96 * Module constructor.
97 */
98 public function __construct() {
99 Plugin::$instance->data_manager_v2->register_controller( new Kits_Controller() );
100 Plugin::$instance->data_manager_v2->register_controller( new Taxonomies_Controller() );
101
102 // Assigning this action here since the repository is being loaded by demand.
103 add_action( 'elementor/experiments/feature-state-change/container', [ Repository::class, 'clear_cache' ], 10, 0 );
104
105 add_action( 'elementor/admin/menu/register', function( Admin_Menu_Manager $admin_menu ) {
106 $this->register_admin_menu_legacy( $admin_menu );
107 }, Source_Local::ADMIN_MENU_PRIORITY + 30 );
108
109 add_action( 'elementor/connect/apps/register', function ( ConnectModule $connect_module ) {
110 $connect_module->register_app( 'kit-library', Kit_Library::get_class_name() );
111 } );
112
113 add_action( 'elementor/init', function () {
114 $this->set_kit_library_settings();
115 }, 12 /** after the initiation of the connect kit library */ );
116 }
117 }
118