PluginProbe
Elementor Website Builder – more than just a page builder / 4.2.0-beta1
Elementor Website Builder – more than just a page builder v4.2.0-beta1
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 4.1.0-dev2 4.0.8 4.1.0-beta1 4.1.0-dev1 All 452 releases
elementor / modules / promotions / conversion-banner.php

conversion-banner.php in Elementor Website Builder – more than just a page builder 4.2.0-beta1, at modules/promotions/conversion-banner.php

279 lines 8.1 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\Modules\Promotions\AdminMenuItems\Go_Pro_Promotion_Item;
6 use Elementor\User;
7 use Elementor\Utils;
8
9 if ( ! defined( 'ABSPATH' ) ) {
10 exit; // Exit if accessed directly.
11 }
12
13 class Conversion_Banner {
14
15 const DEFAULT_SELECTOR = '.wrap h1, .wrap h2';
16 const SCRIPT_HANDLE = 'e-conversion-banner';
17 const STYLE_HANDLE = 'e-conversion-banner';
18 const NONCE_ACTION = 'e_conversion_banner_nonce';
19 const OBJECT_NAME = 'eConversionBanner';
20 const DISMISS_KEY = 'conversion_banner_go_pro';
21 const AJAX_ACTION = 'elementor_dismiss_conversion_banner';
22 const CONTAINER_ID = 'e-conversion-banner';
23 const BIRTHDAY_PROMOTION_URL = 'https://go.elementor.com/go-pro-wp-admin-upgrad-notice/';
24
25 const HELLO_THEME_CONFIG_FILTER = 'hello-plus-theme/rest/admin-config';
26 const THEME_SLUGS = [ 'hello-elementor', 'hello-biz', 'hello-commerce' ];
27 const GO_PRO_TITLE_PREFIX = 'Go Pro';
28
29 public function __construct() {
30 add_action( 'wp_ajax_' . self::AJAX_ACTION, [ $this, 'ajax_dismiss_banner' ] );
31
32 add_filter( self::HELLO_THEME_CONFIG_FILTER, [ $this, 'suppress_hello_theme_banner' ] );
33
34 add_action( 'current_screen', [ $this, 'maybe_register_banner_hooks' ] );
35 }
36
37 public function maybe_register_banner_hooks(): void {
38 $placement = $this->get_active_placement();
39
40 if ( empty( $placement ) ) {
41 return;
42 }
43
44 add_action( 'in_admin_header', [ $this, 'render_banner_container' ], 11 );
45 add_action( 'admin_enqueue_scripts', function () use ( $placement ) {
46 $this->enqueue_assets( $placement );
47 } );
48 }
49
50 public function render_banner_container(): void {
51 ?>
52 <div id="<?php echo esc_attr( self::CONTAINER_ID ); ?>">
53 <?php $this->print_banner_markup( true ); ?>
54 </div>
55 <?php
56 }
57
58 public function suppress_hello_theme_banner( $config ) {
59 if ( $this->is_request_from_theme_admin_page()
60 || ! ( is_array( $config ) && isset( $config['welcome'] ) )
61 || Utils::has_pro()
62 ) {
63 return $config;
64 }
65
66 $title = $config['welcome']['title'] ?? '';
67
68 if ( is_string( $title ) && substr( $title, 0, strlen( self::GO_PRO_TITLE_PREFIX ) ) === self::GO_PRO_TITLE_PREFIX ) {
69 $config['welcome'] = [];
70 }
71
72 return $config;
73 }
74
75 private function is_request_from_theme_admin_page(): bool {
76 $referer = wp_get_referer();
77
78 if ( ! $referer ) {
79 return false;
80 }
81
82 parse_str( (string) wp_parse_url( $referer, PHP_URL_QUERY ), $query_args );
83
84 return in_array( $query_args['page'] ?? '', self::THEME_SLUGS );
85 }
86
87 public function ajax_dismiss_banner(): void {
88 try {
89 check_ajax_referer( self::NONCE_ACTION, 'nonce' );
90
91 if ( ! $this->is_user_allowed() ) {
92 wp_send_json_error( 'Permission denied', 403 );
93 }
94
95 User::set_introduction_viewed( [ 'introductionKey' => self::DISMISS_KEY ] );
96
97 wp_send_json_success();
98
99 } catch ( \Exception $e ) {
100 wp_send_json_error( 'Failed to dismiss banner', 500 );
101 }
102 }
103
104 private function enqueue_assets( array $placement ): void {
105 $min_suffix = Utils::is_script_debug() ? '' : '.min';
106
107 wp_enqueue_script(
108 self::SCRIPT_HANDLE,
109 ELEMENTOR_ASSETS_URL . 'js/' . self::SCRIPT_HANDLE . $min_suffix . '.js',
110 [ 'wp-util', 'elementor-common' ],
111 ELEMENTOR_VERSION,
112 true
113 );
114
115 wp_set_script_translations( self::SCRIPT_HANDLE, 'elementor' );
116
117 wp_localize_script(
118 self::SCRIPT_HANDLE,
119 self::OBJECT_NAME,
120 [
121 'nonce' => wp_create_nonce( self::NONCE_ACTION ),
122 'action' => self::AJAX_ACTION,
123 'placement' => $placement,
124 ]
125 );
126
127 $this->enqueue_styles();
128 }
129
130 private function enqueue_styles(): void {
131 wp_enqueue_style(
132 self::STYLE_HANDLE,
133 ELEMENTOR_ASSETS_URL . 'css/modules/promotions/conversion-banner.css',
134 [],
135 ELEMENTOR_VERSION
136 );
137 }
138
139 private function print_banner_markup( bool $dismissable ): void {
140 $banner = $this->get_banner_config();
141
142 ?>
143 <div class="e-conversion-banner__paper">
144 <?php if ( $dismissable ) : ?>
145 <button type="button" class="e-conversion-banner__dismiss notice-dismiss">
146 <span class="screen-reader-text"><?php echo esc_html__( 'Dismiss this notice.', 'elementor' ); ?></span>
147 </button>
148 <?php endif; ?>
149 <div class="e-conversion-banner__content">
150 <h2 class="e-conversion-banner__title"><?php echo esc_html( $banner['title'] ); ?></h2>
151 <p class="e-conversion-banner__text"><?php echo esc_html( $banner['text'] ); ?></p>
152 <div class="e-conversion-banner__actions">
153 <?php foreach ( $banner['buttons'] as $button ) : ?>
154 <a
155 class="e-conversion-banner__button button button-primary"
156 href="<?php echo esc_url( $button['link'] ); ?>"
157 target="<?php echo esc_attr( $button['target'] ?? '_self' ); ?>"
158 ><?php echo esc_html( $button['text'] ); ?></a>
159 <?php endforeach; ?>
160 </div>
161 </div>
162 <?php if ( ! empty( $banner['image']['src'] ) ) : ?>
163 <img
164 class="e-conversion-banner__image"
165 src="<?php echo esc_url( $banner['image']['src'] ); ?>"
166 alt="<?php echo esc_attr( $banner['image']['alt'] ); ?>"
167 />
168 <?php endif; ?>
169 </div>
170 <?php
171 }
172
173 private function get_banner_config(): array {
174 if ( Utils::is_sale_time() ) {
175 return $this->get_birthday_banner_config();
176 }
177
178 return [
179 'title' => esc_html__( 'Go Pro, Go Limitless', 'elementor' ),
180 'text' => esc_html__( 'Unlock the theme builder, popup builder, 100+ widgets and more advanced tools to take your website to the next level.', 'elementor' ),
181 'buttons' => [
182 [
183 'text' => esc_html__( 'Upgrade Now', 'elementor' ),
184 'link' => Go_Pro_Promotion_Item::get_url(),
185 'target' => '_blank',
186 ],
187 ],
188 'image' => [
189 'src' => '',
190 'alt' => esc_html__( 'Upgrade to Elementor Pro', 'elementor' ),
191 ],
192 ];
193 }
194
195 private function get_birthday_banner_config(): array {
196 return [
197 'title' => esc_html__( 'Celebrate 10 years of Elementor', 'elementor' ),
198 'text' => esc_html__( 'Upgrade your workflow with more capabilities for less. Offer ends June 17.', 'elementor' ),
199 'buttons' => [
200 [
201 'text' => esc_html__( 'Get Discounts', 'elementor' ),
202 'link' => self::BIRTHDAY_PROMOTION_URL,
203 'target' => '_blank',
204 ],
205 ],
206 'image' => [
207 'src' => ELEMENTOR_ASSETS_URL . 'images/decade-birthday.png',
208 'alt' => esc_html__( 'Celebrate 10 years of Elementor', 'elementor' ),
209 ],
210 ];
211 }
212
213 public static function should_display_banner(): bool {
214 return self::is_user_allowed() && self::should_display();
215 }
216
217 private function get_active_placement(): array {
218 $current_screen = get_current_screen();
219
220 if ( ! $current_screen ) {
221 return [];
222 }
223
224 $allowed_pages = $this->get_allowed_admin_pages();
225
226 return $allowed_pages[ $current_screen->id ] ?? [];
227 }
228
229 private static function should_display(): bool {
230 return ! Utils::has_pro() && ! self::is_dismissed();
231 }
232
233 private static function is_user_allowed(): bool {
234 return current_user_can( 'manage_options' );
235 }
236
237 private static function is_dismissed(): bool {
238 return (bool) User::get_introduction_meta( self::DISMISS_KEY );
239 }
240
241 private function get_allowed_admin_pages(): array {
242 $default = [ 'selector' => self::DEFAULT_SELECTOR ];
243
244 return [
245 'dashboard' => [ 'selector' => '#wpbody #wpbody-content .wrap h1' ],
246 'toplevel_page_elementor' => [
247 'selector' => '#e-home-screen',
248 'before' => true,
249 ],
250 'elementor_page_elementor-settings' => $default,
251 'elementor_page_elementor-tools' => $default,
252 'elementor_page_elementor-role-manager' => $default,
253 'elementor_page_elementor-element-manager' => [
254 'selector' => '.wrap h1, .wrap h3.wp-heading-inline',
255 ],
256 'elementor_page_elementor-system-info' => [
257 'selector' => '#wpbody #wpbody-content #elementor-system-info .elementor-system-info-header',
258 'before' => true,
259 ],
260 'elementor_library_page_e-floating-buttons' => [
261 'selector' => '#wpbody-content .e-landing-pages-empty, .wrap h2',
262 'before' => true,
263 ],
264 'edit-e-floating-buttons' => $default,
265 'edit-elementor_library' => [
266 'selector' => self::DEFAULT_SELECTOR,
267 'before' => true,
268 ],
269 'edit-elementor_library_category' => $default,
270 'themes' => $default,
271 'nav-menus' => $default,
272 'theme-editor' => $default,
273 'plugins' => $default,
274 'plugin-install' => $default,
275 'plugin-editor' => $default,
276 ];
277 }
278 }
279