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