PluginProbe
Elementor Website Builder – more than just a page builder / 3.35.0-dev4
Elementor Website Builder – more than just a page builder v3.35.0-dev4
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
← All changes | modules/promotions/module.php +59 -98 4.2.23.35.0-dev4 View file →
@@ -3,10 +3,13 @@
3 3 namespace Elementor\Modules\Promotions;
4 4
5 5 use Elementor\Api;
6 6 use Elementor\Controls_Manager;
7 +use Elementor\Core\Admin\Menu\Admin_Menu_Manager;
7 8 use Elementor\Core\Base\Module as Base_Module;
8 -use Elementor\Core\Utils\Promotions\Filtered_Promotions_Manager;
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;
9 12 use Elementor\Modules\Promotions\AdminMenuItems\Editor_One_Custom_Code_Menu;
10 13 use Elementor\Modules\Promotions\AdminMenuItems\Editor_One_Custom_Elements_Menu;
11 14 use Elementor\Modules\Promotions\AdminMenuItems\Editor_One_Fonts_Menu;
12 15 use Elementor\Modules\Promotions\AdminMenuItems\Editor_One_Icons_Menu;
@@ -11,21 +14,17 @@
11 14 use Elementor\Modules\Promotions\AdminMenuItems\Editor_One_Fonts_Menu;
12 15 use Elementor\Modules\Promotions\AdminMenuItems\Editor_One_Icons_Menu;
13 16 use Elementor\Modules\Promotions\AdminMenuItems\Editor_One_Popups_Menu;
14 17 use Elementor\Modules\Promotions\AdminMenuItems\Editor_One_Submissions_Menu;
18 +use Elementor\Modules\Promotions\AdminMenuItems\Form_Submissions_Promotion_Item;
15 19 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;
20 +use Elementor\Modules\Promotions\AdminMenuItems\Popups_Promotion_Item;
18 21 use Elementor\Modules\Promotions\Pointers\Birthday;
19 22 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;
23 23 use Elementor\Widgets_Manager;
24 24 use Elementor\Utils;
25 25 use Elementor\Includes\EditorAssetsAPI;
26 26 use Elementor\Plugin;
27 -use Elementor\Modules\EditorOne\Classes\Menu_Config;
28 27 use Elementor\Modules\EditorOne\Classes\Menu_Data_Provider;
29 28
30 29 if ( ! defined( 'ABSPATH' ) ) {
31 30 exit; // Exit if accessed directly.
@@ -37,9 +36,9 @@
37 36
38 37 const ADMIN_MENU_PROMOTIONS_PRIORITY = 120;
39 38
40 39 public static function is_active() {
41 - return ! Utils::has_pro() || ! Utils::is_license_active();
40 + return ! Utils::has_pro();
42 41 }
43 42
44 43 public function get_name() {
45 44 return 'promotions';
@@ -47,28 +46,23 @@
47 46
48 47 public function __construct() {
49 48 parent::__construct();
50 49
51 - add_filter( 'elementor/editor/localize_settings', [ $this, 'add_v4_promotions_data' ] );
52 -
53 - if ( Utils::has_pro() ) {
54 - add_action( 'elementor/editor/before_enqueue_scripts', [ $this, 'enqueue_react_data' ] );
55 - $this->register_atomic_promotions();
56 -
57 - return;
58 - }
59 -
60 50 add_action( 'admin_init', function () {
61 51 $this->handle_external_redirects();
62 52 } );
63 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 +
64 58 add_action( 'elementor/editor-one/menu/register', function ( Menu_Data_Provider $menu_data_provider ) {
65 59 $this->register_editor_one_menu_items( $menu_data_provider );
66 60 } );
67 61
68 - if ( Utils::is_sale_time() ) {
69 - add_filter( 'add_menu_classes', [ $this, 'override_one_menu_upgrade_label_during_sale' ] );
70 - }
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 );
71 65
72 66 add_action( 'elementor/widgets/register', function( Widgets_Manager $manager ) {
73 67 foreach ( Api::get_promotion_widgets() as $widget_data ) {
74 68 $manager->register( new Widgets\Pro_Widget_Promotion( [], [
@@ -85,14 +79,12 @@
85 79 if ( Black_Friday::should_display_notice() ) {
86 80 new Black_Friday();
87 81 }
88 82
89 - if ( Conversion_Banner::should_display_banner() ) {
90 - new Conversion_Banner();
83 + if ( Utils::has_pro() ) {
84 + return;
91 85 }
92 86
93 - add_filter( 'elementor/editor/localize_settings', [ $this, 'add_editing_panel_sticky_promotion' ] );
94 -
95 87 add_action( 'elementor/controls/register', function ( Controls_Manager $controls_manager ) {
96 88 $controls_manager->register( new Controls\Promotion_Control() );
97 89 } );
98 90
@@ -97,10 +89,11 @@
97 89 } );
98 90
99 91 add_action( 'elementor/editor/before_enqueue_scripts', [ $this, 'enqueue_react_data' ] );
100 92 add_action( 'elementor/editor/before_enqueue_scripts', [ $this, 'enqueue_editor_v4_alphachip' ] );
93 + add_filter( 'elementor/editor/localize_settings', [ $this, 'add_v4_promotions_data' ] );
101 94
102 - $this->register_atomic_promotions();
95 + $this->register_display_conditions_promo_hooks();
103 96 }
104 97
105 98 private function handle_external_redirects() {
106 99 $page = filter_input( INPUT_GET, 'page', FILTER_SANITIZE_FULL_SPECIAL_CHARS );
@@ -107,32 +100,22 @@
107 100 if ( empty( $page ) ) {
108 101 return;
109 102 }
110 103
111 - if ( in_array( $page, [ 'go_elementor_pro', 'elementor-one-upgrade' ], true ) ) {
104 + if ( 'go_elementor_pro' === $page ) {
112 105 wp_redirect( Go_Pro_Promotion_Item::get_url() ); // phpcs:ignore WordPress.Security.SafeRedirect.wp_redirect_wp_redirect
113 106 die;
114 107 }
115 108 }
116 109
117 - public function override_one_menu_upgrade_label_during_sale( $menu ) {
118 - global $submenu;
119 -
120 - $parent_slug = Menu_Config::ELEMENTOR_HOME_MENU_SLUG;
121 - $upgrade_slug = 'elementor-one-upgrade';
122 -
123 - if ( empty( $submenu[ $parent_slug ] ) ) {
124 - return $menu;
110 + private function register_menu_items( Admin_Menu_Manager $admin_menu ) {
111 + if ( ! $this->is_editor_one_active() ) {
112 + $admin_menu->register( 'e-form-submissions', new Form_Submissions_Promotion_Item() );
113 + $admin_menu->register( 'elementor_custom_fonts', new Custom_Fonts_Promotion_Item() );
114 + $admin_menu->register( 'elementor_custom_icons', new Custom_Icons_Promotion_Item() );
115 + $admin_menu->register( 'elementor_custom_code', new Custom_Code_Promotion_Item() );
116 + $admin_menu->register( 'popup_templates', new Popups_Promotion_Item() );
125 117 }
126 -
127 - foreach ( $submenu[ $parent_slug ] as &$item ) {
128 - if ( isset( $item[2] ) && $upgrade_slug === $item[2] ) {
129 - $item[0] = esc_html__( 'Sale!', 'elementor' ) . '<br />' . esc_html__( 'Upgrade Now', 'elementor' ); // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
130 - break;
131 - }
132 - }
133 -
134 - return $menu;
135 118 }
136 119
137 120 private function register_editor_one_menu_items( Menu_Data_Provider $menu_data_provider ) {
138 121 $menu_data_provider->register_menu( new Editor_One_Custom_Elements_Menu() );
@@ -142,8 +125,14 @@
142 125 $menu_data_provider->register_menu( new Editor_One_Custom_Code_Menu() );
143 126 $menu_data_provider->register_menu( new Editor_One_Popups_Menu() );
144 127 }
145 128
129 + private function register_promotion_menu_item( Admin_Menu_Manager $admin_menu ) {
130 + if ( ! $this->is_editor_one_active() ) {
131 + $admin_menu->register( 'go_elementor_pro', new Go_Pro_Promotion_Item() );
132 + }
133 + }
134 +
146 135 public function enqueue_react_data(): void {
147 136 if ( ! current_user_can( 'manage_options' ) ) {
148 137 return;
149 138 }
@@ -158,9 +147,8 @@
158 147 'react-dom',
159 148 'backbone-marionette',
160 149 'elementor-editor-modules',
161 150 'elementor-v2-ui',
162 - 'elementor-v2-icons',
163 151 ],
164 152 ELEMENTOR_VERSION,
165 153 true
166 154 );
@@ -209,18 +197,8 @@
209 197 EditorAssetsAPI::ASSETS_DATA_KEY => 'free-to-pro-upsell',
210 198 ];
211 199 }
212 200
213 - public function add_editing_panel_sticky_promotion( array $settings ): array {
214 - if ( ! Plugin::$instance->experiments->is_feature_active( 'e_panel_promotions' ) ) {
215 - return $settings;
216 - }
217 -
218 - $settings['editingPanelStickyPromotion'] = Filtered_Promotions_Manager::get_editor_panel_sticky_promotion();
219 -
220 - return $settings;
221 - }
222 -
223 201 public function add_v4_promotions_data( array $settings ): array {
224 202 if ( ! current_user_can( 'manage_options' ) ) {
225 203 return $settings;
226 204 }
@@ -240,73 +218,56 @@
240 218 EditorAssetsAPI::ASSETS_DATA_KEY => 'promotions',
241 219 ];
242 220 }
243 221
222 + private function is_editor_one_active(): bool {
223 + return (bool) Plugin::instance()->modules_manager->get_modules( 'editor-one' );
224 + }
225 +
244 226 private function is_atomic_widgets_active(): bool {
245 227 return Plugin::$instance->experiments->is_feature_active( 'e_atomic_elements' );
246 228 }
247 229
248 - private function get_atomic_promotion_configs(): array {
249 - return [
250 - [
251 - 'key' => 'attributes',
252 - 'label' => __( 'Attributes', 'elementor' ),
253 - 'section' => 'settings',
254 - 'priority' => 40,
255 - ],
256 - [
257 - 'key' => 'display-conditions',
258 - 'label' => __( 'Display Conditions', 'elementor' ),
259 - 'section' => 'settings',
260 - 'priority' => 50,
261 - ],
262 - ];
263 - }
264 -
265 - private function register_atomic_promotions(): void {
230 + private function register_display_conditions_promo_hooks(): void {
266 231 add_action( 'elementor/init', function() {
267 232 if ( ! $this->is_atomic_widgets_active() ) {
268 233 return;
269 234 }
270 235
236 + require_once __DIR__ . '/prop-types/display-conditions-prop-type.php';
237 + require_once __DIR__ . '/controls/display-conditions-promotion-control.php';
238 +
271 239 add_filter(
272 240 'elementor/atomic-widgets/props-schema',
273 - [ $this, 'inject_atomic_promotion_props' ]
241 + [ $this, 'inject_display_conditions_promo_prop' ]
274 242 );
275 243
276 - foreach ( $this->get_atomic_promotion_configs() as $config ) {
277 - add_filter(
278 - 'elementor/atomic-widgets/controls',
279 - fn( array $controls, $element ) => $this->inject_atomic_promotion_control( $controls, $element, $config ),
280 - $config['priority'],
281 - 2
282 - );
283 - }
244 + add_filter(
245 + 'elementor/atomic-widgets/controls',
246 + [ $this, 'inject_display_conditions_promo_control' ],
247 + 50,
248 + 2
249 + );
284 250 } );
285 -
286 - ( new Atomic_Form_Widget_Promotion() )->register();
287 - ( new Collection_Loop_Widget_Promotion() )->register();
288 251 }
289 252
290 - public function inject_atomic_promotion_props( array $schema ): array {
291 - foreach ( $this->get_atomic_promotion_configs() as $config ) {
292 - $key = $config['key'];
253 + public function inject_display_conditions_promo_prop( array $schema ): array {
254 + $prop_key = PropTypes\Display_Conditions_Prop_Type::get_key();
293 255
294 - if ( isset( $schema[ $key ] ) ) {
295 - continue;
296 - }
256 + if ( isset( $schema[ $prop_key ] ) ) {
257 + return $schema;
258 + }
297 259
298 - $schema[ $key ] = Promotion_Prop_Type::make( $key );
299 - }
260 + $schema[ $prop_key ] = PropTypes\Display_Conditions_Prop_Type::make();
300 261
301 262 return $schema;
302 263 }
303 264
304 - protected function inject_atomic_promotion_control( array $element_controls, $atomic_element, array $config ): array {
305 - $key = $config['key'];
265 + public function inject_display_conditions_promo_control( array $element_controls, $atomic_element ): array {
266 + $prop_key = PropTypes\Display_Conditions_Prop_Type::get_key();
306 267 $schema = $atomic_element::get_props_schema();
307 268
308 - if ( ! array_key_exists( $key, $schema ) ) {
269 + if ( ! array_key_exists( $prop_key, $schema ) ) {
309 270 return $element_controls;
310 271 }
311 272
312 273 foreach ( $element_controls as $item ) {
@@ -313,14 +274,14 @@
313 274 if ( ! ( $item instanceof \Elementor\Modules\AtomicWidgets\Controls\Section ) ) {
314 275 continue;
315 276 }
316 277
317 - if ( $item->get_id() !== $config['section'] ) {
278 + if ( $item->get_id() !== 'settings' ) {
318 279 continue;
319 280 }
320 281
321 - $control = Atomic_Promotion_Control::make( $key )
322 - ->set_label( $config['label'] )
282 + $control = Controls\Display_Conditions_Promotion_Control::bind_to( $prop_key )
283 + ->set_label( __( 'Display Conditions', 'elementor' ) )
323 284 ->set_meta( [
324 285 'topDivider' => true,
325 286 ] );
326 287