PluginProbe
Elementor Website Builder – more than just a page builder / 3.8.0-beta1
Elementor Website Builder – more than just a page builder v3.8.0-beta1
4.3.4 4.3.3 4.3.2 4.3.1 4.3.0 4.3.0-beta3 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 All 457 releases
← All changes | app/modules/kit-library/module.php +34 -99 4.1.1 → 3.8.0-beta1 View file →
@@ -1,8 +1,8 @@
1 1 <?php
2 2 namespace Elementor\App\Modules\KitLibrary;
3 3
4 -use Elementor\App\Modules\KitLibrary\Data\Repository;
4 +use Elementor\Core\Admin\Menu\Main as MainMenu;
5 5 use Elementor\Plugin;
6 6 use Elementor\TemplateLibrary\Source_Local;
7 7 use Elementor\Core\Base\Module as BaseModule;
8 8 use Elementor\App\Modules\KitLibrary\Connect\Kit_Library;
@@ -8,15 +8,11 @@
8 8 use Elementor\App\Modules\KitLibrary\Connect\Kit_Library;
9 9 use Elementor\Core\Common\Modules\Connect\Module as ConnectModule;
10 10 use Elementor\App\Modules\KitLibrary\Data\Kits\Controller as Kits_Controller;
11 11 use Elementor\App\Modules\KitLibrary\Data\Taxonomies\Controller as Taxonomies_Controller;
12 -use Elementor\Core\Utils\Promotions\Filtered_Promotions_Manager;
13 -use Elementor\Utils as ElementorUtils;
14 -use Elementor\Modules\EditorOne\Classes\Menu_Data_Provider;
15 -use Elementor\App\Modules\KitLibrary\AdminMenuItems\Editor_One_Website_Templates_Menu;
16 12
17 13 if ( ! defined( 'ABSPATH' ) ) {
18 - exit; // Exit if accessed directly.
14 + exit; // Exit if accessed directly
19 15 }
20 16
21 17 class Module extends BaseModule {
22 18 /**
@@ -29,12 +25,30 @@
29 25 public function get_name() {
30 26 return 'kit-library';
31 27 }
32 28
33 - private function register_editor_one_menu( Menu_Data_Provider $menu_data_provider ) {
34 - $menu_data_provider->register_menu( new Editor_One_Website_Templates_Menu() );
29 + private function register_admin_menu( MainMenu $menu ) {
30 + $menu->add_submenu( [
31 + 'page_title' => __( 'Kit Library', 'elementor' ),
32 + 'menu_title' => '<span id="e-admin-menu__kit-library">' . __( 'Kit Library', 'elementor' ) . '</span>',
33 + 'menu_slug' => Plugin::$instance->app->get_base_url() . '#/kit-library',
34 + 'index' => 40,
35 + ] );
35 36 }
36 37
38 + /**
39 + * Register the admin menu the old way.
40 + */
41 + private function register_admin_menu_legacy() {
42 + add_submenu_page(
43 + Source_Local::ADMIN_MENU_SLUG,
44 + __( 'Kit Library', 'elementor' ),
45 + __( 'Kit Library', 'elementor' ),
46 + 'manage_options',
47 + Plugin::$instance->app->get_base_url() . '#/kit-library'
48 + );
49 + }
50 +
37 51 private function set_kit_library_settings() {
38 52 if ( ! Plugin::$instance->common ) {
39 53 return;
40 54 }
@@ -45,10 +59,10 @@
45 59 /** @var Kit_Library $kit_library */
46 60 $kit_library = $connect->get_app( 'kit-library' );
47 61
48 62 Plugin::$instance->app->set_settings( 'kit-library', [
49 - 'has_access_to_module' => current_user_can( 'manage_options' ),
50 - 'subscription_plans' => $this->apply_filter_subscription_plans( $connect->get_subscription_plans( 'kit-library' ) ),
63 + 'has_access_to_module' => current_user_can( 'administrator' ),
64 + 'subscription_plans' => $connect->get_subscription_plans( 'kit-library' ),
51 65 'is_pro' => false,
52 66 'is_library_connected' => $kit_library->is_connected(),
53 67 'library_connect_url' => $kit_library->get_admin_url( 'authorize', [
54 68 'utm_source' => 'kit-library',
@@ -56,33 +70,11 @@
56 70 'utm_campaign' => 'library-connect',
57 71 'utm_term' => '%%page%%', // Will be replaced in the frontend.
58 72 ] ),
59 73 'access_level' => ConnectModule::ACCESS_LEVEL_CORE,
60 - 'access_tier' => ConnectModule::ACCESS_TIER_FREE,
61 - 'plan_type' => ConnectModule::ACCESS_TIER_FREE,
62 - 'app_url' => Plugin::$instance->app->get_base_url() . '#/' . $this->get_name(),
63 - 'urls' => [
64 - 'createNewPage' => Plugin::$instance->documents->get_create_new_post_url(),
65 - ],
66 74 ] );
67 75 }
68 76
69 - private function apply_filter_subscription_plans( array $subscription_plans ): array {
70 - foreach ( $subscription_plans as $key => $plan ) {
71 - if ( null === $plan['promotion_url'] ) {
72 - continue;
73 - }
74 -
75 - $subscription_plans[ $key ] = Filtered_Promotions_Manager::get_filtered_promotion_data(
76 - $plan,
77 - 'elementor/kit_library/' . $key . '/promotion',
78 - 'promotion_url'
79 - );
80 - }
81 -
82 - return $subscription_plans;
83 - }
84 -
85 77 /**
86 78 * Module constructor.
87 79 */
88 80 public function __construct() {
@@ -88,26 +80,18 @@
88 80 public function __construct() {
89 81 Plugin::$instance->data_manager_v2->register_controller( new Kits_Controller() );
90 82 Plugin::$instance->data_manager_v2->register_controller( new Taxonomies_Controller() );
91 83
92 - $this->register_actions();
84 + if ( Plugin::$instance->experiments->is_feature_active( 'admin_menu_rearrangement' ) ) {
85 + add_action( 'elementor/admin/menu_registered/elementor', function( MainMenu $menu ) {
86 + $this->register_admin_menu( $menu );
87 + } );
88 + } else {
89 + add_action( 'admin_menu', function() {
90 + $this->register_admin_menu_legacy();
91 + }, 50 /* after Elementor page */ );
92 + }
93 93
94 - do_action( 'elementor/kit_library/registered', $this );
95 - }
96 -
97 - public function register_actions() {
98 - // Assigning this action here since the repository is being loaded by demand.
99 - add_action( 'elementor/experiments/feature-state-change/container', [ Repository::class, 'clear_cache' ], 10, 0 );
100 -
101 - add_action( 'elementor/editor-one/menu/register', function ( Menu_Data_Provider $menu_data_provider ) {
102 - $this->register_editor_one_menu( $menu_data_provider );
103 - } );
104 -
105 - add_filter( 'elementor/editor-one/menu/protected_templates_submenu_slugs', function ( array $protected_slugs ): array {
106 - $protected_slugs[] = 'edit-tags.php?taxonomy=elementor_library_category&amp;post_type=elementor_library';
107 - return $protected_slugs;
108 - } );
109 -
110 94 add_action( 'elementor/connect/apps/register', function ( ConnectModule $connect_module ) {
111 95 $connect_module->register_app( 'kit-library', Kit_Library::get_class_name() );
112 96 } );
113 97
@@ -112,56 +96,7 @@
112 96 } );
113 97
114 98 add_action( 'elementor/init', function () {
115 99 $this->set_kit_library_settings();
116 - }, 12 /** After the initiation of the connect kit library */ );
117 -
118 - add_action( 'template_redirect', [ $this, 'handle_kit_screenshot_generation' ] );
119 - }
120 -
121 - public function handle_kit_screenshot_generation() {
122 - $is_kit_preview = ElementorUtils::get_super_global_value( $_GET, 'kit_thumbnail' );
123 - $nonce = ElementorUtils::get_super_global_value( $_GET, 'nonce' );
124 -
125 - if ( $is_kit_preview ) {
126 - if ( ! wp_verify_nonce( $nonce, 'kit_thumbnail' ) ) {
127 - wp_die( esc_html__( 'Not Authorized', 'elementor' ), esc_html__( 'Error', 'elementor' ), 403 );
128 - }
129 -
130 - $suffix = ( ElementorUtils::is_script_debug() || ElementorUtils::is_elementor_tests() ) ? '' : '.min';
131 -
132 - show_admin_bar( false );
133 -
134 - wp_enqueue_script(
135 - 'dom-to-image',
136 - ELEMENTOR_ASSETS_URL . "/lib/dom-to-image/js/dom-to-image{$suffix}.js",
137 - [],
138 - '2.6.0',
139 - true
140 - );
141 -
142 - wp_enqueue_script(
143 - 'html2canvas',
144 - ELEMENTOR_ASSETS_URL . "/lib/html2canvas/js/html2canvas{$suffix}.js",
145 - [],
146 - '1.4.1',
147 - true
148 - );
149 -
150 - wp_enqueue_script(
151 - 'cloud-library-screenshot',
152 - ELEMENTOR_ASSETS_URL . "/js/cloud-library-screenshot{$suffix}.js",
153 - [ 'dom-to-image', 'html2canvas', 'elementor-common', 'elementor-common-modules' ],
154 - ELEMENTOR_VERSION,
155 - true
156 - );
157 -
158 - $config = [
159 - 'home_url' => home_url(),
160 - 'kit_id' => uniqid(),
161 - 'selector' => 'body',
162 - ];
163 -
164 - wp_add_inline_script( 'cloud-library-screenshot', 'var ElementorScreenshotConfig = ' . wp_json_encode( $config ) . ';' );
165 - }
100 + }, 12 /** after the initiation of the connect kit library */ );
166 101 }
167 102 }