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

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