PluginProbe
Elementor Website Builder – more than just a page builder / 3.34.1
Elementor Website Builder – more than just a page builder v3.34.1
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 / modules / promotions / module.php

module.php in Elementor Website Builder – more than just a page builder 3.34.1, at modules/promotions/module.php

202 lines 6.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Elementor\Modules\Promotions;
4
5 use Elementor\Api;
6 use Elementor\Controls_Manager;
7 use Elementor\Core\Admin\Menu\Admin_Menu_Manager;
8 use Elementor\Core\Base\Module as Base_Module;
9 use Elementor\Modules\Promotions\AdminMenuItems\Custom_Code_Promotion_Item;
10 use Elementor\Modules\Promotions\AdminMenuItems\Custom_Fonts_Promotion_Item;
11 use Elementor\Modules\Promotions\AdminMenuItems\Custom_Icons_Promotion_Item;
12 use Elementor\Modules\Promotions\AdminMenuItems\Editor_One_Custom_Code_Menu;
13 use Elementor\Modules\Promotions\AdminMenuItems\Editor_One_Custom_Elements_Menu;
14 use Elementor\Modules\Promotions\AdminMenuItems\Editor_One_Fonts_Menu;
15 use Elementor\Modules\Promotions\AdminMenuItems\Editor_One_Icons_Menu;
16 use Elementor\Modules\Promotions\AdminMenuItems\Editor_One_Popups_Menu;
17 use Elementor\Modules\Promotions\AdminMenuItems\Editor_One_Submissions_Menu;
18 use Elementor\Modules\Promotions\AdminMenuItems\Form_Submissions_Promotion_Item;
19 use Elementor\Modules\Promotions\AdminMenuItems\Go_Pro_Promotion_Item;
20 use Elementor\Modules\Promotions\AdminMenuItems\Popups_Promotion_Item;
21 use Elementor\Modules\Promotions\Pointers\Birthday;
22 use Elementor\Modules\Promotions\Pointers\Black_Friday;
23 use Elementor\Widgets_Manager;
24 use Elementor\Utils;
25 use Elementor\Includes\EditorAssetsAPI;
26 use Elementor\Plugin;
27 use Elementor\Modules\EditorOne\Classes\Menu_Data_Provider;
28
29 if ( ! defined( 'ABSPATH' ) ) {
30 exit; // Exit if accessed directly.
31 }
32
33 class Module extends Base_Module {
34
35 const ADMIN_MENU_PRIORITY = 100;
36
37 const ADMIN_MENU_PROMOTIONS_PRIORITY = 120;
38
39 public static function is_active() {
40 return ! Utils::has_pro();
41 }
42
43 public function get_name() {
44 return 'promotions';
45 }
46
47 public function __construct() {
48 parent::__construct();
49
50 add_action( 'admin_init', function () {
51 $this->handle_external_redirects();
52 } );
53
54 add_action( 'elementor/admin/menu/register', function ( Admin_Menu_Manager $admin_menu ) {
55 $this->register_menu_items( $admin_menu );
56 }, static::ADMIN_MENU_PRIORITY );
57
58 add_action( 'elementor/editor-one/menu/register', function ( Menu_Data_Provider $menu_data_provider ) {
59 $this->register_editor_one_menu_items( $menu_data_provider );
60 } );
61
62 add_action( 'elementor/admin/menu/register', function ( Admin_Menu_Manager $admin_menu ) {
63 $this->register_promotion_menu_item( $admin_menu );
64 }, static::ADMIN_MENU_PROMOTIONS_PRIORITY );
65
66 add_action( 'elementor/widgets/register', function( Widgets_Manager $manager ) {
67 foreach ( Api::get_promotion_widgets() as $widget_data ) {
68 $manager->register( new Widgets\Pro_Widget_Promotion( [], [
69 'widget_name' => $widget_data['name'],
70 'widget_title' => $widget_data['title'],
71 ] ) );
72 }
73 } );
74
75 if ( Birthday::should_display_notice() ) {
76 new Birthday();
77 }
78
79 if ( Black_Friday::should_display_notice() ) {
80 new Black_Friday();
81 }
82
83 if ( Utils::has_pro() ) {
84 return;
85 }
86
87 add_action( 'elementor/controls/register', function ( Controls_Manager $controls_manager ) {
88 $controls_manager->register( new Controls\Promotion_Control() );
89 } );
90
91 add_action( 'elementor/editor/before_enqueue_scripts', [ $this, 'enqueue_react_data' ] );
92 add_action( 'elementor/editor/before_enqueue_scripts', [ $this, 'enqueue_editor_v4_alphachip' ] );
93 }
94
95 private function handle_external_redirects() {
96 $page = filter_input( INPUT_GET, 'page', FILTER_SANITIZE_FULL_SPECIAL_CHARS );
97 if ( empty( $page ) ) {
98 return;
99 }
100
101 if ( 'go_elementor_pro' === $page ) {
102 wp_redirect( Go_Pro_Promotion_Item::get_url() ); // phpcs:ignore WordPress.Security.SafeRedirect.wp_redirect_wp_redirect
103 die;
104 }
105 }
106
107 private function register_menu_items( Admin_Menu_Manager $admin_menu ) {
108 if ( ! $this->is_editor_one_active() ) {
109 $admin_menu->register( 'e-form-submissions', new Form_Submissions_Promotion_Item() );
110 $admin_menu->register( 'elementor_custom_fonts', new Custom_Fonts_Promotion_Item() );
111 $admin_menu->register( 'elementor_custom_icons', new Custom_Icons_Promotion_Item() );
112 $admin_menu->register( 'elementor_custom_code', new Custom_Code_Promotion_Item() );
113 $admin_menu->register( 'popup_templates', new Popups_Promotion_Item() );
114 }
115 }
116
117 private function register_editor_one_menu_items( Menu_Data_Provider $menu_data_provider ) {
118 $menu_data_provider->register_menu( new Editor_One_Custom_Elements_Menu() );
119 $menu_data_provider->register_menu( new Editor_One_Submissions_Menu() );
120 $menu_data_provider->register_menu( new Editor_One_Fonts_Menu() );
121 $menu_data_provider->register_menu( new Editor_One_Icons_Menu() );
122 $menu_data_provider->register_menu( new Editor_One_Custom_Code_Menu() );
123 $menu_data_provider->register_menu( new Editor_One_Popups_Menu() );
124 }
125
126 private function register_promotion_menu_item( Admin_Menu_Manager $admin_menu ) {
127 if ( ! $this->is_editor_one_active() ) {
128 $admin_menu->register( 'go_elementor_pro', new Go_Pro_Promotion_Item() );
129 }
130 }
131
132 public function enqueue_react_data(): void {
133 if ( ! current_user_can( 'manage_options' ) ) {
134 return;
135 }
136
137 $min_suffix = Utils::is_script_debug() ? '' : '.min';
138
139 wp_enqueue_script(
140 'e-react-promotions',
141 ELEMENTOR_ASSETS_URL . 'js/e-react-promotions' . $min_suffix . '.js',
142 [
143 'react',
144 'react-dom',
145 'backbone-marionette',
146 'elementor-editor-modules',
147 'elementor-v2-ui',
148 ],
149 ELEMENTOR_VERSION,
150 true
151 );
152
153 wp_set_script_translations( 'e-react-promotions', 'elementor' );
154
155 wp_localize_script(
156 'e-react-promotions',
157 'elementorPromotionsData',
158 $this->get_app_js_config()
159 );
160 }
161
162 public function enqueue_editor_v4_alphachip(): void {
163 if ( ! current_user_can( 'manage_options' ) ) {
164 return;
165 }
166
167 $min_suffix = Utils::is_script_debug() ? '' : '.min';
168
169 wp_enqueue_script(
170 'editor-v4-opt-in-alphachip',
171 ELEMENTOR_ASSETS_URL . 'js/editor-v4-opt-in-alphachip' . $min_suffix . '.js',
172 [
173 'react',
174 'react-dom',
175 'elementor-common',
176 'elementor-v2-ui',
177 ],
178 ELEMENTOR_VERSION,
179 true
180 );
181 }
182
183 private function get_app_js_config(): array {
184 $editor_assets_api = new EditorAssetsAPI( $this->get_api_config() );
185 $promotion_data = new PromotionData( $editor_assets_api );
186
187 return $promotion_data->get_promotion_data();
188 }
189
190 private function get_api_config(): array {
191 return [
192 EditorAssetsAPI::ASSETS_DATA_URL => 'https://assets.elementor.com/free-to-pro-upsell/v1/free-to-pro-upsell.json',
193 EditorAssetsAPI::ASSETS_DATA_TRANSIENT_KEY => '_elementor_free_to_pro_upsell',
194 EditorAssetsAPI::ASSETS_DATA_KEY => 'free-to-pro-upsell',
195 ];
196 }
197
198 private function is_editor_one_active(): bool {
199 return (bool) Plugin::instance()->modules_manager->get_modules( 'editor-one' );
200 }
201 }
202