PluginProbe
Elementor Website Builder – more than just a page builder / 3.33.0-dev1
Elementor Website Builder – more than just a page builder v3.33.0-dev1
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.33.0-dev1, at modules/promotions/module.php

172 lines 5.0 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\Form_Submissions_Promotion_Item;
13 use Elementor\Modules\Promotions\AdminMenuItems\Go_Pro_Promotion_Item;
14 use Elementor\Modules\Promotions\AdminMenuItems\Popups_Promotion_Item;
15 use Elementor\Modules\Promotions\Pointers\Birthday;
16 use Elementor\Modules\Promotions\Pointers\Black_Friday;
17 use Elementor\Widgets_Manager;
18 use Elementor\Utils;
19 use Elementor\Includes\EditorAssetsAPI;
20
21 if ( ! defined( 'ABSPATH' ) ) {
22 exit; // Exit if accessed directly.
23 }
24
25 class Module extends Base_Module {
26
27 const ADMIN_MENU_PRIORITY = 100;
28
29 const ADMIN_MENU_PROMOTIONS_PRIORITY = 120;
30
31 public static function is_active() {
32 return ! Utils::has_pro();
33 }
34
35 public function get_name() {
36 return 'promotions';
37 }
38
39 public function __construct() {
40 parent::__construct();
41
42 add_action( 'admin_init', function () {
43 $this->handle_external_redirects();
44 } );
45
46 add_action( 'elementor/admin/menu/register', function ( Admin_Menu_Manager $admin_menu ) {
47 $this->register_menu_items( $admin_menu );
48 }, static::ADMIN_MENU_PRIORITY );
49
50 add_action( 'elementor/admin/menu/register', function ( Admin_Menu_Manager $admin_menu ) {
51 $this->register_promotion_menu_item( $admin_menu );
52 }, static::ADMIN_MENU_PROMOTIONS_PRIORITY );
53
54 add_action( 'elementor/widgets/register', function( Widgets_Manager $manager ) {
55 foreach ( Api::get_promotion_widgets() as $widget_data ) {
56 $manager->register( new Widgets\Pro_Widget_Promotion( [], [
57 'widget_name' => $widget_data['name'],
58 'widget_title' => $widget_data['title'],
59 ] ) );
60 }
61 } );
62
63 if ( Birthday::should_display_notice() ) {
64 new Birthday();
65 }
66
67 if ( Black_Friday::should_display_notice() ) {
68 new Black_Friday();
69 }
70
71 if ( Utils::has_pro() ) {
72 return;
73 }
74
75 add_action( 'elementor/controls/register', function ( Controls_Manager $controls_manager ) {
76 $controls_manager->register( new Controls\Promotion_Control() );
77 } );
78
79 add_action( 'elementor/editor/before_enqueue_scripts', [ $this, 'enqueue_react_data' ] );
80 add_action( 'elementor/editor/before_enqueue_scripts', [ $this, 'enqueue_editor_v4_alphachip' ] );
81 }
82
83 private function handle_external_redirects() {
84 if ( empty( $_GET['page'] ) ) {
85 return;
86 }
87
88 if ( 'go_elementor_pro' === $_GET['page'] ) {
89 wp_redirect( Go_Pro_Promotion_Item::get_url() );
90 die;
91 }
92 }
93
94 private function register_menu_items( Admin_Menu_Manager $admin_menu ) {
95 $admin_menu->register( 'e-form-submissions', new Form_Submissions_Promotion_Item() );
96 $admin_menu->register( 'elementor_custom_fonts', new Custom_Fonts_Promotion_Item() );
97 $admin_menu->register( 'elementor_custom_icons', new Custom_Icons_Promotion_Item() );
98 $admin_menu->register( 'elementor_custom_code', new Custom_Code_Promotion_Item() );
99 $admin_menu->register( 'popup_templates', new Popups_Promotion_Item() );
100 }
101
102 private function register_promotion_menu_item( Admin_Menu_Manager $admin_menu ) {
103 $admin_menu->register( 'go_elementor_pro', new Go_Pro_Promotion_Item() );
104 }
105
106 public function enqueue_react_data(): void {
107 if ( ! current_user_can( 'manage_options' ) ) {
108 return;
109 }
110
111 $min_suffix = Utils::is_script_debug() ? '' : '.min';
112
113 wp_enqueue_script(
114 'e-react-promotions',
115 ELEMENTOR_ASSETS_URL . 'js/e-react-promotions' . $min_suffix . '.js',
116 [
117 'react',
118 'react-dom',
119 'backbone-marionette',
120 'elementor-editor-modules',
121 'elementor-v2-ui',
122 ],
123 ELEMENTOR_VERSION,
124 true
125 );
126
127 wp_set_script_translations( 'e-react-promotions', 'elementor' );
128
129 wp_localize_script(
130 'e-react-promotions',
131 'elementorPromotionsData',
132 $this->get_app_js_config()
133 );
134 }
135
136 public function enqueue_editor_v4_alphachip(): void {
137 if ( ! current_user_can( 'manage_options' ) ) {
138 return;
139 }
140
141 $min_suffix = Utils::is_script_debug() ? '' : '.min';
142
143 wp_enqueue_script(
144 'editor-v4-opt-in-alphachip',
145 ELEMENTOR_ASSETS_URL . 'js/editor-v4-opt-in-alphachip' . $min_suffix . '.js',
146 [
147 'react',
148 'react-dom',
149 'elementor-common',
150 'elementor-v2-ui',
151 ],
152 ELEMENTOR_VERSION,
153 true
154 );
155 }
156
157 private function get_app_js_config(): array {
158 $editor_assets_api = new EditorAssetsAPI( $this->get_api_config() );
159 $promotion_data = new PromotionData( $editor_assets_api );
160
161 return $promotion_data->get_promotion_data();
162 }
163
164 private function get_api_config(): array {
165 return [
166 EditorAssetsAPI::ASSETS_DATA_URL => 'https://assets.elementor.com/free-to-pro-upsell/v1/free-to-pro-upsell.json',
167 EditorAssetsAPI::ASSETS_DATA_TRANSIENT_KEY => '_elementor_free_to_pro_upsell',
168 EditorAssetsAPI::ASSETS_DATA_KEY => 'free-to-pro-upsell',
169 ];
170 }
171 }
172