PluginProbe
Elementor Website Builder – more than just a page builder / 4.3.0-beta3
Elementor Website Builder – more than just a page builder v4.3.0-beta3
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
← All changes | modules/promotions/conversion-banner.php +89 -11 4.2.0-dev24.3.0-beta3 View file →
@@ -1,9 +1,9 @@
1 1 <?php
2 2
3 3 namespace Elementor\Modules\Promotions;
4 4
5 -use Elementor\Modules\Promotions\AdminMenuItems\Go_Pro_Promotion_Item;
5 +use Elementor\Core\Base\Document;
6 6 use Elementor\User;
7 7 use Elementor\Utils;
8 8
9 9 if ( ! defined( 'ABSPATH' ) ) {
@@ -19,13 +19,20 @@
19 19 const OBJECT_NAME = 'eConversionBanner';
20 20 const DISMISS_KEY = 'conversion_banner_go_pro';
21 21 const AJAX_ACTION = 'elementor_dismiss_conversion_banner';
22 22 const CONTAINER_ID = 'e-conversion-banner';
23 + const UPGRADE_URL = 'https://go.elementor.com/go-pro-wp-admin-upgrade-notice/';
23 24 const BIRTHDAY_PROMOTION_URL = 'https://go.elementor.com/go-pro-wp-admin-upgrad-notice/';
24 25
25 26 const HELLO_THEME_CONFIG_FILTER = 'hello-plus-theme/rest/admin-config';
26 27 const THEME_SLUGS = [ 'hello-elementor', 'hello-biz', 'hello-commerce' ];
28 + const THEME_SETTINGS_PAGE_SUFFIX = '-settings';
27 29 const GO_PRO_TITLE_PREFIX = 'Go Pro';
30 + const MIN_ELEMENTOR_PAGES_TO_TRIGGER = 2;
31 + const PENDING_TRANSIENT_KEY = 'elementor_conversion_banner_pages_pending';
32 + const PENDING_TTL = DAY_IN_SECONDS;
33 + const UNLOCK_OPTION_KEY = 'elementor_conversion_banner_unlocked';
34 + const UNLOCK_OPTION_VALUE = '1';
28 35
29 36 public function __construct() {
30 37 add_action( 'wp_ajax_' . self::AJAX_ACTION, [ $this, 'ajax_dismiss_banner' ] );
31 38
@@ -33,12 +40,37 @@
33 40
34 41 add_action( 'current_screen', [ $this, 'maybe_register_banner_hooks' ] );
35 42 }
36 43
44 + public static function register_cache_invalidation_hooks(): void {
45 + static $hooks_registered = false;
46 +
47 + if ( $hooks_registered ) {
48 + return;
49 + }
50 +
51 + $hooks_registered = true;
52 +
53 + add_action( 'added_post_meta', [ self::class, 'maybe_invalidate_pending_cache' ], 10, 4 );
54 + add_action( 'updated_post_meta', [ self::class, 'maybe_invalidate_pending_cache' ], 10, 4 );
55 + }
56 +
57 + public static function maybe_invalidate_pending_cache( $meta_id, $post_id, $meta_key, $meta_value ): void {
58 + if ( Document::BUILT_WITH_ELEMENTOR_META_KEY !== $meta_key ) {
59 + return;
60 + }
61 +
62 + if ( self::is_unlocked() ) {
63 + return;
64 + }
65 +
66 + delete_transient( self::PENDING_TRANSIENT_KEY );
67 + }
68 +
37 69 public function maybe_register_banner_hooks(): void {
38 70 $placement = $this->get_active_placement();
39 71
40 - if ( empty( $placement ) ) {
72 + if ( empty( $placement ) || ! self::has_min_elementor_pages() ) {
41 73 return;
42 74 }
43 75
44 76 add_action( 'in_admin_header', [ $this, 'render_banner_container' ], 11 );
@@ -80,9 +112,17 @@
80 112 }
81 113
82 114 parse_str( (string) wp_parse_url( $referer, PHP_URL_QUERY ), $query_args );
83 115
84 - return in_array( $query_args['page'] ?? '', self::THEME_SLUGS );
116 + $page = $query_args['page'] ?? '';
117 +
118 + foreach ( self::THEME_SLUGS as $theme_slug ) {
119 + if ( $page === $theme_slug || $page === $theme_slug . self::THEME_SETTINGS_PAGE_SUFFIX ) {
120 + return true;
121 + }
122 + }
123 +
124 + return false;
85 125 }
86 126
87 127 public function ajax_dismiss_banner(): void {
88 128 try {
@@ -175,14 +215,14 @@
175 215 return $this->get_birthday_banner_config();
176 216 }
177 217
178 218 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' ),
219 + 'title' => esc_html__( 'Build more with Elementor Pro', 'elementor' ),
220 + 'text' => esc_html__( 'Add the theme builder, popup builder, and 85+ advanced widgets to your Elementor Editor.', 'elementor' ),
181 221 'buttons' => [
182 222 [
183 - 'text' => esc_html__( 'Upgrade Now', 'elementor' ),
184 - 'link' => Go_Pro_Promotion_Item::get_url(),
223 + 'text' => esc_html__( 'Upgrade now', 'elementor' ),
224 + 'link' => self::UPGRADE_URL,
185 225 'target' => '_blank',
186 226 ],
187 227 ],
188 228 'image' => [
@@ -226,11 +266,48 @@
226 266 return $allowed_pages[ $current_screen->id ] ?? [];
227 267 }
228 268
229 269 private static function should_display(): bool {
230 - return ! Utils::has_pro() && ! self::is_dismissed();
270 + return ! Utils::has_pro() && ! self::is_dismissed() && self::has_min_elementor_pages();
231 271 }
232 272
273 + private static function is_unlocked(): bool {
274 + return self::UNLOCK_OPTION_VALUE === get_option( self::UNLOCK_OPTION_KEY );
275 + }
276 +
277 + private static function has_min_elementor_pages(): bool {
278 + if ( self::is_unlocked() ) {
279 + return true;
280 + }
281 +
282 + if ( get_transient( self::PENDING_TRANSIENT_KEY ) ) {
283 + return false;
284 + }
285 +
286 + $query = new \WP_Query( [
287 + 'fields' => 'ids',
288 + 'meta_key' => Document::BUILT_WITH_ELEMENTOR_META_KEY,
289 + 'meta_value' => 'builder',
290 + 'no_found_rows' => true,
291 + 'post_status' => 'any',
292 + 'post_type' => 'any',
293 + 'posts_per_page' => self::MIN_ELEMENTOR_PAGES_TO_TRIGGER,
294 + 'update_post_meta_cache' => false,
295 + 'update_post_term_cache' => false,
296 + ] );
297 +
298 + if ( count( $query->posts ) >= self::MIN_ELEMENTOR_PAGES_TO_TRIGGER ) {
299 + update_option( self::UNLOCK_OPTION_KEY, self::UNLOCK_OPTION_VALUE, true );
300 + delete_transient( self::PENDING_TRANSIENT_KEY );
301 +
302 + return true;
303 + }
304 +
305 + set_transient( self::PENDING_TRANSIENT_KEY, 1, self::PENDING_TTL );
306 +
307 + return false;
308 + }
309 +
233 310 private static function is_user_allowed(): bool {
234 311 return current_user_can( 'manage_options' );
235 312 }
236 313
@@ -239,8 +316,9 @@
239 316 }
240 317
241 318 private function get_allowed_admin_pages(): array {
242 319 $default = [ 'selector' => self::DEFAULT_SELECTOR ];
320 + $plugin_pages = [ 'selector' => '.wrap hr.wp-header-end' ];
243 321
244 322 return [
245 323 'dashboard' => [ 'selector' => '#wpbody #wpbody-content .wrap h1' ],
246 324 'toplevel_page_elementor' => [
@@ -269,10 +347,10 @@
269 347 'edit-elementor_library_category' => $default,
270 348 'themes' => $default,
271 349 'nav-menus' => $default,
272 350 'theme-editor' => $default,
273 - 'plugins' => $default,
274 - 'plugin-install' => $default,
275 - 'plugin-editor' => $default,
351 + 'plugins' => $plugin_pages,
352 + 'plugin-install' => $plugin_pages,
353 + 'plugin-editor' => $plugin_pages,
276 354 ];
277 355 }
278 356 }