PluginProbe
Elementor Website Builder – more than just a page builder / 3.19.0-beta1
Elementor Website Builder – more than just a page builder v3.19.0-beta1
4.3.3 4.3.2 4.3.1 4.3.0 4.3.0-beta3 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 All 456 releases
← All changes | modules/promotions/module.php +25 -290 4.3.3 → 3.19.0-beta1 View file →
@@ -2,34 +2,21 @@
2 2
3 3 namespace Elementor\Modules\Promotions;
4 4
5 5 use Elementor\Api;
6 -use Elementor\Controls_Manager;
6 +use Elementor\Core\Admin\Menu\Admin_Menu_Manager;
7 7 use Elementor\Core\Base\Module as Base_Module;
8 -use Elementor\Core\Utils\Promotions\Filtered_Promotions_Manager;
9 -use Elementor\Modules\Promotions\AdminMenuItems\Editor_One_Custom_Code_Menu;
10 -use Elementor\Modules\Promotions\AdminMenuItems\Editor_One_Custom_Elements_Menu;
11 -use Elementor\Modules\Promotions\AdminMenuItems\Editor_One_Fonts_Menu;
12 -use Elementor\Modules\Promotions\AdminMenuItems\Editor_One_Icons_Menu;
13 -use Elementor\Modules\Promotions\AdminMenuItems\Editor_One_Popups_Menu;
14 -use Elementor\Modules\Promotions\AdminMenuItems\Editor_One_Submissions_Menu;
8 +use Elementor\Modules\Promotions\AdminMenuItems\Custom_Code_Promotion_Item;
9 +use Elementor\Modules\Promotions\AdminMenuItems\Custom_Fonts_Promotion_Item;
10 +use Elementor\Modules\Promotions\AdminMenuItems\Custom_Icons_Promotion_Item;
11 +use Elementor\Modules\Promotions\AdminMenuItems\Form_Submissions_Promotion_Item;
15 12 use Elementor\Modules\Promotions\AdminMenuItems\Go_Pro_Promotion_Item;
16 -use Elementor\Modules\Promotions\Controls\Atomic_Promotion_Control;
17 -use Elementor\Modules\Promotions\Conversion_Banner;
18 -use Elementor\Modules\Promotions\Pointers\Birthday;
19 -use Elementor\Modules\Promotions\Pointers\Black_Friday;
20 -use Elementor\Modules\Promotions\PropTypes\Promotion_Prop_Type;
21 -use Elementor\Modules\Promotions\Widgets\Atomic_Form_Widget_Promotion;
22 -use Elementor\Modules\Promotions\Widgets\Collection_Loop_Widget_Promotion;
13 +use Elementor\Modules\Promotions\AdminMenuItems\Popups_Promotion_Item;
23 14 use Elementor\Widgets_Manager;
24 15 use Elementor\Utils;
25 -use Elementor\Includes\EditorAssetsAPI;
26 -use Elementor\Plugin;
27 -use Elementor\Modules\EditorOne\Classes\Menu_Config;
28 -use Elementor\Modules\EditorOne\Classes\Menu_Data_Provider;
29 16
30 17 if ( ! defined( 'ABSPATH' ) ) {
31 - exit; // Exit if accessed directly.
18 + exit; // Exit if accessed directly
32 19 }
33 20
34 21 class Module extends Base_Module {
35 22
@@ -37,13 +24,9 @@
37 24
38 25 const ADMIN_MENU_PROMOTIONS_PRIORITY = 120;
39 26
40 27 public static function is_active() {
41 - if ( Utils::has_pro() ) {
42 - return true;
43 - }
44 -
45 - return ! Utils::is_license_active();
28 + return ! Utils::has_pro();
46 29 }
47 30
48 31 public function get_name() {
49 32 return 'promotions';
@@ -51,28 +34,19 @@
51 34
52 35 public function __construct() {
53 36 parent::__construct();
54 37
55 - add_filter( 'elementor/editor/localize_settings', [ $this, 'add_v4_promotions_data' ] );
56 -
57 - if ( Utils::has_pro() ) {
58 - add_action( 'elementor/editor/before_enqueue_scripts', [ $this, 'enqueue_react_data' ] );
59 - $this->register_atomic_promotions();
60 -
61 - return;
62 - }
63 -
64 38 add_action( 'admin_init', function () {
65 39 $this->handle_external_redirects();
66 40 } );
67 41
68 - add_action( 'elementor/editor-one/menu/register', function ( Menu_Data_Provider $menu_data_provider ) {
69 - $this->register_editor_one_menu_items( $menu_data_provider );
70 - } );
42 + add_action( 'elementor/admin/menu/register', function ( Admin_Menu_Manager $admin_menu ) {
43 + $this->register_menu_items( $admin_menu );
44 + }, static::ADMIN_MENU_PRIORITY );
71 45
72 - if ( Utils::is_sale_time() ) {
73 - add_filter( 'add_menu_classes', [ $this, 'override_one_menu_upgrade_label_during_sale' ] );
74 - }
46 + add_action( 'elementor/admin/menu/register', function ( Admin_Menu_Manager $admin_menu ) {
47 + $this->register_promotion_menu_item( $admin_menu );
48 + }, static::ADMIN_MENU_PROMOTIONS_PRIORITY );
75 49
76 50 add_action( 'elementor/widgets/register', function( Widgets_Manager $manager ) {
77 51 foreach ( Api::get_promotion_widgets() as $widget_data ) {
78 52 $manager->register( new Widgets\Pro_Widget_Promotion( [], [
@@ -80,268 +54,29 @@
80 54 'widget_title' => $widget_data['title'],
81 55 ] ) );
82 56 }
83 57 } );
84 -
85 - if ( Birthday::should_display_notice() ) {
86 - new Birthday();
87 - }
88 -
89 - if ( Black_Friday::should_display_notice() ) {
90 - new Black_Friday();
91 - }
92 -
93 - if ( ! Utils::has_pro() ) {
94 - Conversion_Banner::register_cache_invalidation_hooks();
95 -
96 - if ( Conversion_Banner::should_display_banner() ) {
97 - new Conversion_Banner();
98 - }
99 - }
100 -
101 - add_filter( 'elementor/editor/localize_settings', [ $this, 'add_editing_panel_sticky_promotion' ] );
102 -
103 - add_action( 'elementor/controls/register', function ( Controls_Manager $controls_manager ) {
104 - $controls_manager->register( new Controls\Promotion_Control() );
105 - } );
106 -
107 - add_action( 'elementor/editor/before_enqueue_scripts', [ $this, 'enqueue_react_data' ] );
108 - add_action( 'elementor/editor/before_enqueue_scripts', [ $this, 'enqueue_editor_v4_alphachip' ] );
109 -
110 - $this->register_atomic_promotions();
111 58 }
112 59
113 60 private function handle_external_redirects() {
114 - $page = filter_input( INPUT_GET, 'page', FILTER_SANITIZE_FULL_SPECIAL_CHARS );
115 - if ( empty( $page ) ) {
61 + if ( empty( $_GET['page'] ) ) {
116 62 return;
117 63 }
118 64
119 - if ( in_array( $page, [ 'go_elementor_pro', 'elementor-one-upgrade' ], true ) ) {
120 - wp_redirect( Go_Pro_Promotion_Item::get_url() ); // phpcs:ignore WordPress.Security.SafeRedirect.wp_redirect_wp_redirect
65 + if ( 'go_elementor_pro' === $_GET['page'] ) {
66 + wp_redirect( Go_Pro_Promotion_Item::URL );
121 67 die;
122 68 }
123 69 }
124 70
125 - public function override_one_menu_upgrade_label_during_sale( $menu ) {
126 - global $submenu;
127 -
128 - $parent_slug = Menu_Config::ELEMENTOR_HOME_MENU_SLUG;
129 - $upgrade_slug = 'elementor-one-upgrade';
130 -
131 - if ( empty( $submenu[ $parent_slug ] ) ) {
132 - return $menu;
133 - }
134 -
135 - foreach ( $submenu[ $parent_slug ] as &$item ) {
136 - if ( isset( $item[2] ) && $upgrade_slug === $item[2] ) {
137 - $item[0] = esc_html__( 'Sale!', 'elementor' ) . '<br />' . esc_html__( 'Upgrade Now', 'elementor' ); // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
138 - break;
139 - }
140 - }
141 -
142 - return $menu;
71 + private function register_menu_items( Admin_Menu_Manager $admin_menu ) {
72 + $admin_menu->register( 'e-form-submissions', new Form_Submissions_Promotion_Item() );
73 + $admin_menu->register( 'elementor_custom_fonts', new Custom_Fonts_Promotion_Item() );
74 + $admin_menu->register( 'elementor_custom_icons', new Custom_Icons_Promotion_Item() );
75 + $admin_menu->register( 'elementor_custom_code', new Custom_Code_Promotion_Item() );
76 + $admin_menu->register( 'popup_templates', new Popups_Promotion_Item() );
143 77 }
144 78
145 - private function register_editor_one_menu_items( Menu_Data_Provider $menu_data_provider ) {
146 - $menu_data_provider->register_menu( new Editor_One_Custom_Elements_Menu() );
147 - $menu_data_provider->register_menu( new Editor_One_Submissions_Menu() );
148 - $menu_data_provider->register_menu( new Editor_One_Fonts_Menu() );
149 - $menu_data_provider->register_menu( new Editor_One_Icons_Menu() );
150 - $menu_data_provider->register_menu( new Editor_One_Custom_Code_Menu() );
151 - $menu_data_provider->register_menu( new Editor_One_Popups_Menu() );
152 - }
153 -
154 - public function enqueue_react_data(): void {
155 - if ( ! current_user_can( 'manage_options' ) ) {
156 - return;
157 - }
158 -
159 - $min_suffix = Utils::is_script_debug() ? '' : '.min';
160 -
161 - wp_enqueue_script(
162 - 'e-react-promotions',
163 - ELEMENTOR_ASSETS_URL . 'js/e-react-promotions' . $min_suffix . '.js',
164 - [
165 - 'react',
166 - 'react-dom',
167 - 'backbone-marionette',
168 - 'elementor-editor-modules',
169 - 'elementor-v2-ui',
170 - 'elementor-v2-icons',
171 - ],
172 - ELEMENTOR_VERSION,
173 - true
174 - );
175 -
176 - wp_set_script_translations( 'e-react-promotions', 'elementor' );
177 -
178 - wp_localize_script(
179 - 'e-react-promotions',
180 - 'elementorPromotionsData',
181 - $this->get_app_js_config()
182 - );
183 - }
184 -
185 - public function enqueue_editor_v4_alphachip(): void {
186 - if ( ! current_user_can( 'manage_options' ) ) {
187 - return;
188 - }
189 -
190 - $min_suffix = Utils::is_script_debug() ? '' : '.min';
191 -
192 - wp_enqueue_script(
193 - 'editor-v4-opt-in-alphachip',
194 - ELEMENTOR_ASSETS_URL . 'js/editor-v4-opt-in-alphachip' . $min_suffix . '.js',
195 - [
196 - 'react',
197 - 'react-dom',
198 - 'elementor-common',
199 - 'elementor-v2-ui',
200 - ],
201 - ELEMENTOR_VERSION,
202 - true
203 - );
204 - }
205 -
206 - private function get_app_js_config(): array {
207 - $editor_assets_api = new EditorAssetsAPI( $this->get_api_config() );
208 - $promotion_data = new PromotionData( $editor_assets_api );
209 -
210 - return $promotion_data->get_promotion_data();
211 - }
212 -
213 - private function get_api_config(): array {
214 - return [
215 - EditorAssetsAPI::ASSETS_DATA_URL => 'https://assets.elementor.com/free-to-pro-upsell/v1/free-to-pro-upsell.json',
216 - EditorAssetsAPI::ASSETS_DATA_TRANSIENT_KEY => '_elementor_free_to_pro_upsell',
217 - EditorAssetsAPI::ASSETS_DATA_KEY => 'free-to-pro-upsell',
218 - ];
219 - }
220 -
221 - public function add_editing_panel_sticky_promotion( array $settings ): array {
222 - $settings['editingPanelStickyPromotion'] = Filtered_Promotions_Manager::get_editor_panel_sticky_promotion();
223 -
224 - return $settings;
225 - }
226 -
227 - public function add_v4_promotions_data( array $settings ): array {
228 - if ( ! current_user_can( 'manage_options' ) ) {
229 - return $settings;
230 - }
231 -
232 - $editor_assets_api = new EditorAssetsAPI( $this->get_v4_promotions_api_config() );
233 - $promotion_data = new PromotionData( $editor_assets_api );
234 -
235 - $settings['v4Promotions'] = $promotion_data->get_v4_promotions_data();
236 -
237 - return $settings;
238 - }
239 -
240 - private function get_v4_promotions_api_config(): array {
241 - return [
242 - EditorAssetsAPI::ASSETS_DATA_URL => 'https://assets.elementor.com/packages/v1/promotions.json',
243 - EditorAssetsAPI::ASSETS_DATA_TRANSIENT_KEY => '_elementor_v4_promotions',
244 - EditorAssetsAPI::ASSETS_DATA_KEY => 'promotions',
245 - ];
246 - }
247 -
248 - private function is_atomic_widgets_active(): bool {
249 - return Plugin::$instance->experiments->is_feature_active( 'e_atomic_elements' );
250 - }
251 -
252 - private function get_atomic_promotion_configs(): array {
253 - return [
254 - [
255 - 'key' => 'attributes',
256 - 'label' => __( 'Attributes', 'elementor' ),
257 - 'section' => 'settings',
258 - 'priority' => 40,
259 - ],
260 - [
261 - 'key' => 'display-conditions',
262 - 'label' => __( 'Display Conditions', 'elementor' ),
263 - 'section' => 'settings',
264 - 'priority' => 50,
265 - ],
266 - ];
267 - }
268 -
269 - private function should_register_core_atomic_panel_promotions(): bool {
270 - // Pro with an active license registers real atomic widgets (or its own panel
271 - // promotion layer). Core stubs caused duplicate panel entries after ED-25600.
272 - return ! Utils::has_pro() || ! Utils::is_license_active();
273 - }
274 -
275 - private function register_atomic_promotions(): void {
276 - if ( ! $this->should_register_core_atomic_panel_promotions() ) {
277 - return;
278 - }
279 -
280 - add_action( 'elementor/init', function() {
281 - if ( ! $this->is_atomic_widgets_active() ) {
282 - return;
283 - }
284 -
285 - add_filter(
286 - 'elementor/atomic-widgets/props-schema',
287 - [ $this, 'inject_atomic_promotion_props' ]
288 - );
289 -
290 - foreach ( $this->get_atomic_promotion_configs() as $config ) {
291 - add_filter(
292 - 'elementor/atomic-widgets/controls',
293 - fn( array $controls, $element ) => $this->inject_atomic_promotion_control( $controls, $element, $config ),
294 - $config['priority'],
295 - 2
296 - );
297 - }
298 - } );
299 -
300 - ( new Atomic_Form_Widget_Promotion() )->register();
301 - ( new Collection_Loop_Widget_Promotion() )->register();
302 - }
303 -
304 - public function inject_atomic_promotion_props( array $schema ): array {
305 - foreach ( $this->get_atomic_promotion_configs() as $config ) {
306 - $key = $config['key'];
307 -
308 - if ( isset( $schema[ $key ] ) ) {
309 - continue;
310 - }
311 -
312 - $schema[ $key ] = Promotion_Prop_Type::make( $key );
313 - }
314 -
315 - return $schema;
316 - }
317 -
318 - protected function inject_atomic_promotion_control( array $element_controls, $atomic_element, array $config ): array {
319 - $key = $config['key'];
320 - $schema = $atomic_element::get_props_schema();
321 -
322 - if ( ! array_key_exists( $key, $schema ) ) {
323 - return $element_controls;
324 - }
325 -
326 - foreach ( $element_controls as $item ) {
327 - if ( ! ( $item instanceof \Elementor\Modules\AtomicWidgets\Controls\Section ) ) {
328 - continue;
329 - }
330 -
331 - if ( $item->get_id() !== $config['section'] ) {
332 - continue;
333 - }
334 -
335 - $control = Atomic_Promotion_Control::make( $key )
336 - ->set_label( $config['label'] )
337 - ->set_meta( [
338 - 'topDivider' => true,
339 - ] );
340 -
341 - $item->add_item( $control );
342 - break;
343 - }
344 -
345 - return $element_controls;
79 + private function register_promotion_menu_item( Admin_Menu_Manager $admin_menu ) {
80 + $admin_menu->register( 'go_elementor_pro', new Go_Pro_Promotion_Item() );
346 81 }
347 82 }