PluginProbe
Elementor Website Builder – more than just a page builder / 3.30.3
Elementor Website Builder – more than just a page builder v3.30.3
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.30.3, at app/modules/kit-library/module.php

176 lines 5.6 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 use Elementor\Utils as ElementorUtils;
16
17 if ( ! defined( 'ABSPATH' ) ) {
18 exit; // Exit if accessed directly.
19 }
20
21 class Module extends BaseModule {
22 /**
23 * Get name.
24 *
25 * @access public
26 *
27 * @return string
28 */
29 public function get_name() {
30 return 'kit-library';
31 }
32
33 private function register_admin_menu( MainMenu $menu ) {
34 $menu->add_submenu( [
35 'page_title' => esc_html__( 'Website Templates', 'elementor' ),
36 'menu_title' => '<span id="e-admin-menu__kit-library">' . esc_html__( 'Website Templates', 'elementor' ) . '</span>',
37 'menu_slug' => Plugin::$instance->app->get_base_url() . '#/kit-library',
38 'index' => 40,
39 ] );
40 }
41
42 /**
43 * Register the admin menu the old way.
44 */
45 private function register_admin_menu_legacy( Admin_Menu_Manager $admin_menu ) {
46 $admin_menu->register(
47 Plugin::$instance->app->get_base_url() . '#/kit-library',
48 new Kit_Library_Menu_Item()
49 );
50 }
51
52 private function set_kit_library_settings() {
53 if ( ! Plugin::$instance->common ) {
54 return;
55 }
56
57 /** @var ConnectModule $connect */
58 $connect = Plugin::$instance->common->get_component( 'connect' );
59
60 /** @var Kit_Library $kit_library */
61 $kit_library = $connect->get_app( 'kit-library' );
62
63 Plugin::$instance->app->set_settings( 'kit-library', [
64 'has_access_to_module' => current_user_can( 'manage_options' ),
65 'subscription_plans' => $this->apply_filter_subscription_plans( $connect->get_subscription_plans( 'kit-library' ) ),
66 'is_pro' => false,
67 'is_library_connected' => $kit_library->is_connected(),
68 'library_connect_url' => $kit_library->get_admin_url( 'authorize', [
69 'utm_source' => 'kit-library',
70 'utm_medium' => 'wp-dash',
71 'utm_campaign' => 'library-connect',
72 'utm_term' => '%%page%%', // Will be replaced in the frontend.
73 ] ),
74 'access_level' => ConnectModule::ACCESS_LEVEL_CORE,
75 'access_tier' => ConnectModule::ACCESS_TIER_FREE,
76 'app_url' => Plugin::$instance->app->get_base_url() . '#/' . $this->get_name(),
77 ] );
78 }
79
80 private function apply_filter_subscription_plans( array $subscription_plans ): array {
81 foreach ( $subscription_plans as $key => $plan ) {
82 if ( null === $plan['promotion_url'] ) {
83 continue;
84 }
85
86 $subscription_plans[ $key ] = Filtered_Promotions_Manager::get_filtered_promotion_data(
87 $plan,
88 'elementor/kit_library/' . $key . '/promotion',
89 'promotion_url'
90 );
91 }
92
93 return $subscription_plans;
94 }
95
96 /**
97 * Module constructor.
98 */
99 public function __construct() {
100 Plugin::$instance->data_manager_v2->register_controller( new Kits_Controller() );
101 Plugin::$instance->data_manager_v2->register_controller( new Taxonomies_Controller() );
102
103 $this->register_actions();
104
105 do_action( 'elementor/kit_library/registered', $this );
106 }
107
108 public function register_actions() {
109 // Assigning this action here since the repository is being loaded by demand.
110 add_action( 'elementor/experiments/feature-state-change/container', [ Repository::class, 'clear_cache' ], 10, 0 );
111
112 add_action( 'elementor/admin/menu/register', function( Admin_Menu_Manager $admin_menu ) {
113 $this->register_admin_menu_legacy( $admin_menu );
114 }, Source_Local::ADMIN_MENU_PRIORITY + 30 );
115
116 add_action( 'elementor/connect/apps/register', function ( ConnectModule $connect_module ) {
117 $connect_module->register_app( 'kit-library', Kit_Library::get_class_name() );
118 } );
119
120 add_action( 'elementor/init', function () {
121 $this->set_kit_library_settings();
122 }, 12 /** After the initiation of the connect kit library */ );
123
124 if ( Plugin::$instance->experiments->is_feature_active( 'cloud-library' ) ) {
125 add_action( 'template_redirect', [ $this, 'handle_kit_screenshot_generation' ] );
126 }
127 }
128
129 public function handle_kit_screenshot_generation() {
130 $is_kit_preview = ElementorUtils::get_super_global_value( $_GET, 'kit_thumbnail' );
131 $nonce = ElementorUtils::get_super_global_value( $_GET, 'nonce' );
132
133 if ( $is_kit_preview ) {
134 if ( ! wp_verify_nonce( $nonce, 'kit_thumbnail' ) ) {
135 wp_die( esc_html__( 'Not Authorized', 'elementor' ), esc_html__( 'Error', 'elementor' ), 403 );
136 }
137
138 $suffix = ( ElementorUtils::is_script_debug() || ElementorUtils::is_elementor_tests() ) ? '' : '.min';
139
140 show_admin_bar( false );
141
142 wp_enqueue_script(
143 'dom-to-image',
144 ELEMENTOR_ASSETS_URL . "/lib/dom-to-image/js/dom-to-image{$suffix}.js",
145 [],
146 '2.6.0',
147 true
148 );
149
150 wp_enqueue_script(
151 'html2canvas',
152 ELEMENTOR_ASSETS_URL . "/lib/html2canvas/js/html2canvas{$suffix}.js",
153 [],
154 '1.4.1',
155 true
156 );
157
158 wp_enqueue_script(
159 'cloud-library-screenshot',
160 ELEMENTOR_ASSETS_URL . "/js/cloud-library-screenshot{$suffix}.js",
161 [ 'dom-to-image', 'html2canvas', 'elementor-common', 'elementor-common-modules' ],
162 ELEMENTOR_VERSION,
163 true
164 );
165
166 $config = [
167 'home_url' => home_url(),
168 'kit_id' => uniqid(),
169 'selector' => 'body',
170 ];
171
172 wp_add_inline_script( 'cloud-library-screenshot', 'var ElementorScreenshotConfig = ' . wp_json_encode( $config ) . ';' );
173 }
174 }
175 }
176