PluginProbe
Elementor Website Builder – more than just a page builder / 4.0.9
Elementor Website Builder – more than just a page builder v4.0.9
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 4.0.9, at modules/promotions/module.php

297 lines 8.3 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\Base\Module as Base_Module;
8 use Elementor\Modules\Promotions\AdminMenuItems\Editor_One_Custom_Code_Menu;
9 use Elementor\Modules\Promotions\AdminMenuItems\Editor_One_Custom_Elements_Menu;
10 use Elementor\Modules\Promotions\AdminMenuItems\Editor_One_Fonts_Menu;
11 use Elementor\Modules\Promotions\AdminMenuItems\Editor_One_Icons_Menu;
12 use Elementor\Modules\Promotions\AdminMenuItems\Editor_One_Popups_Menu;
13 use Elementor\Modules\Promotions\AdminMenuItems\Editor_One_Submissions_Menu;
14 use Elementor\Modules\Promotions\AdminMenuItems\Go_Pro_Promotion_Item;
15 use Elementor\Modules\Promotions\Controls\Atomic_Promotion_Control;
16 use Elementor\Modules\Promotions\Pointers\Birthday;
17 use Elementor\Modules\Promotions\Pointers\Black_Friday;
18 use Elementor\Modules\Promotions\PropTypes\Promotion_Prop_Type;
19 use Elementor\Modules\Promotions\Widgets\Ally_Dashboard_Widget;
20 use Elementor\Modules\Promotions\Widgets\Atomic_Form_Widget_Promotion;
21 use Elementor\Widgets_Manager;
22 use Elementor\Utils;
23 use Elementor\Includes\EditorAssetsAPI;
24 use Elementor\Plugin;
25 use Elementor\Modules\EditorOne\Classes\Menu_Data_Provider;
26
27 if ( ! defined( 'ABSPATH' ) ) {
28 exit; // Exit if accessed directly.
29 }
30
31 class Module extends Base_Module {
32
33 const ADMIN_MENU_PRIORITY = 100;
34
35 const ADMIN_MENU_PROMOTIONS_PRIORITY = 120;
36
37 public static function is_active() {
38 return ! Utils::has_pro();
39 }
40
41 public function get_name() {
42 return 'promotions';
43 }
44
45 public function __construct() {
46 parent::__construct();
47
48 add_action( 'admin_init', function () {
49 $this->handle_external_redirects();
50 } );
51
52 add_action( 'elementor/editor-one/menu/register', function ( Menu_Data_Provider $menu_data_provider ) {
53 $this->register_editor_one_menu_items( $menu_data_provider );
54 } );
55
56 add_action( 'elementor/widgets/register', function( Widgets_Manager $manager ) {
57 foreach ( Api::get_promotion_widgets() as $widget_data ) {
58 $manager->register( new Widgets\Pro_Widget_Promotion( [], [
59 'widget_name' => $widget_data['name'],
60 'widget_title' => $widget_data['title'],
61 ] ) );
62 }
63 } );
64
65 if ( Birthday::should_display_notice() ) {
66 new Birthday();
67 }
68
69 if ( Black_Friday::should_display_notice() ) {
70 new Black_Friday();
71 }
72
73 if ( Utils::has_pro() ) {
74 return;
75 }
76
77 add_action( 'elementor/controls/register', function ( Controls_Manager $controls_manager ) {
78 $controls_manager->register( new Controls\Promotion_Control() );
79 } );
80
81 add_action( 'elementor/editor/before_enqueue_scripts', [ $this, 'enqueue_react_data' ] );
82 add_action( 'elementor/editor/before_enqueue_scripts', [ $this, 'enqueue_editor_v4_alphachip' ] );
83 add_filter( 'elementor/editor/localize_settings', [ $this, 'add_v4_promotions_data' ] );
84
85 // Add Ally promo
86 Ally_Dashboard_Widget::init();
87
88 $this->register_atomic_promotions();
89 }
90
91 /**
92 * Get Ally Scanner URL
93 *
94 * @return string
95 */
96 public static function get_ally_external_scanner_url(): string {
97 return apply_filters( 'elementor/ally_external_scanner_url', 'https://go.elementor.com/acc-checker-dashboard-plg' );
98 }
99
100 private function handle_external_redirects() {
101 $page = filter_input( INPUT_GET, 'page', FILTER_SANITIZE_FULL_SPECIAL_CHARS );
102 if ( empty( $page ) ) {
103 return;
104 }
105
106 if ( 'go_elementor_pro' === $page ) {
107 wp_redirect( Go_Pro_Promotion_Item::get_url() ); // phpcs:ignore WordPress.Security.SafeRedirect.wp_redirect_wp_redirect
108 die;
109 }
110 }
111
112 private function register_editor_one_menu_items( Menu_Data_Provider $menu_data_provider ) {
113 $menu_data_provider->register_menu( new Editor_One_Custom_Elements_Menu() );
114 $menu_data_provider->register_menu( new Editor_One_Submissions_Menu() );
115 $menu_data_provider->register_menu( new Editor_One_Fonts_Menu() );
116 $menu_data_provider->register_menu( new Editor_One_Icons_Menu() );
117 $menu_data_provider->register_menu( new Editor_One_Custom_Code_Menu() );
118 $menu_data_provider->register_menu( new Editor_One_Popups_Menu() );
119 }
120
121 public function enqueue_react_data(): void {
122 if ( ! current_user_can( 'manage_options' ) ) {
123 return;
124 }
125
126 $min_suffix = Utils::is_script_debug() ? '' : '.min';
127
128 wp_enqueue_script(
129 'e-react-promotions',
130 ELEMENTOR_ASSETS_URL . 'js/e-react-promotions' . $min_suffix . '.js',
131 [
132 'react',
133 'react-dom',
134 'backbone-marionette',
135 'elementor-editor-modules',
136 'elementor-v2-ui',
137 ],
138 ELEMENTOR_VERSION,
139 true
140 );
141
142 wp_set_script_translations( 'e-react-promotions', 'elementor' );
143
144 wp_localize_script(
145 'e-react-promotions',
146 'elementorPromotionsData',
147 $this->get_app_js_config()
148 );
149 }
150
151 public function enqueue_editor_v4_alphachip(): void {
152 if ( ! current_user_can( 'manage_options' ) ) {
153 return;
154 }
155
156 $min_suffix = Utils::is_script_debug() ? '' : '.min';
157
158 wp_enqueue_script(
159 'editor-v4-opt-in-alphachip',
160 ELEMENTOR_ASSETS_URL . 'js/editor-v4-opt-in-alphachip' . $min_suffix . '.js',
161 [
162 'react',
163 'react-dom',
164 'elementor-common',
165 'elementor-v2-ui',
166 ],
167 ELEMENTOR_VERSION,
168 true
169 );
170 }
171
172 private function get_app_js_config(): array {
173 $editor_assets_api = new EditorAssetsAPI( $this->get_api_config() );
174 $promotion_data = new PromotionData( $editor_assets_api );
175
176 return $promotion_data->get_promotion_data();
177 }
178
179 private function get_api_config(): array {
180 return [
181 EditorAssetsAPI::ASSETS_DATA_URL => 'https://assets.elementor.com/free-to-pro-upsell/v1/free-to-pro-upsell.json',
182 EditorAssetsAPI::ASSETS_DATA_TRANSIENT_KEY => '_elementor_free_to_pro_upsell',
183 EditorAssetsAPI::ASSETS_DATA_KEY => 'free-to-pro-upsell',
184 ];
185 }
186
187 public function add_v4_promotions_data( array $settings ): array {
188 if ( ! current_user_can( 'manage_options' ) ) {
189 return $settings;
190 }
191
192 $editor_assets_api = new EditorAssetsAPI( $this->get_v4_promotions_api_config() );
193 $promotion_data = new PromotionData( $editor_assets_api );
194
195 $settings['v4Promotions'] = $promotion_data->get_v4_promotions_data();
196
197 return $settings;
198 }
199
200 private function get_v4_promotions_api_config(): array {
201 return [
202 EditorAssetsAPI::ASSETS_DATA_URL => 'https://assets.elementor.com/packages/v1/promotions.json',
203 EditorAssetsAPI::ASSETS_DATA_TRANSIENT_KEY => '_elementor_v4_promotions',
204 EditorAssetsAPI::ASSETS_DATA_KEY => 'promotions',
205 ];
206 }
207
208 private function is_atomic_widgets_active(): bool {
209 return Plugin::$instance->experiments->is_feature_active( 'e_atomic_elements' );
210 }
211
212 private function get_atomic_promotion_configs(): array {
213 return [
214 [
215 'key' => 'attributes',
216 'label' => __( 'Attributes', 'elementor' ),
217 'section' => 'settings',
218 'priority' => 40,
219 ],
220 [
221 'key' => 'display-conditions',
222 'label' => __( 'Display Conditions', 'elementor' ),
223 'section' => 'settings',
224 'priority' => 50,
225 ],
226 ];
227 }
228
229 private function register_atomic_promotions(): void {
230 add_action( 'elementor/init', function() {
231 if ( ! $this->is_atomic_widgets_active() ) {
232 return;
233 }
234
235 add_filter(
236 'elementor/atomic-widgets/props-schema',
237 [ $this, 'inject_atomic_promotion_props' ]
238 );
239
240 foreach ( $this->get_atomic_promotion_configs() as $config ) {
241 add_filter(
242 'elementor/atomic-widgets/controls',
243 fn( array $controls, $element ) => $this->inject_atomic_promotion_control( $controls, $element, $config ),
244 $config['priority'],
245 2
246 );
247 }
248 } );
249
250 ( new Atomic_Form_Widget_Promotion() )->register();
251 }
252
253 public function inject_atomic_promotion_props( array $schema ): array {
254 foreach ( $this->get_atomic_promotion_configs() as $config ) {
255 $key = $config['key'];
256
257 if ( isset( $schema[ $key ] ) ) {
258 continue;
259 }
260
261 $schema[ $key ] = Promotion_Prop_Type::make( $key );
262 }
263
264 return $schema;
265 }
266
267 protected function inject_atomic_promotion_control( array $element_controls, $atomic_element, array $config ): array {
268 $key = $config['key'];
269 $schema = $atomic_element::get_props_schema();
270
271 if ( ! array_key_exists( $key, $schema ) ) {
272 return $element_controls;
273 }
274
275 foreach ( $element_controls as $item ) {
276 if ( ! ( $item instanceof \Elementor\Modules\AtomicWidgets\Controls\Section ) ) {
277 continue;
278 }
279
280 if ( $item->get_id() !== $config['section'] ) {
281 continue;
282 }
283
284 $control = Atomic_Promotion_Control::make( $key )
285 ->set_label( $config['label'] )
286 ->set_meta( [
287 'topDivider' => true,
288 ] );
289
290 $item->add_item( $control );
291 break;
292 }
293
294 return $element_controls;
295 }
296 }
297