Diff: STRATO-apps/wordpress_03/app/wp-content/plugins/elementor/modules/promotions/pointers/birthday.php

Keine Baseline-Datei – Diff nur gegen leer.
Zur Liste
1 -
1 + <?php
2 +
3 + namespace Elementor\Modules\Promotions\Pointers;
4 +
5 + use Elementor\User;
6 + use Elementor\Utils;
7 +
8 + if ( ! defined( 'ABSPATH' ) ) {
9 + exit; // Exit if accessed directly.
10 + }
11 +
12 + class Birthday {
13 + const PROMOTION_URL = 'https://go.elementor.com/go-pro-wordpress-notice-birthday/';
14 + const ELEMENTOR_POINTER_ID = 'toplevel_page_elementor';
15 + const SEEN_TODAY_KEY = '_elementor-2025-birthday';
16 + const DISMISS_ACTION_KEY = 'birthday_pointer_2025';
17 +
18 + public function __construct() {
19 + add_action( 'admin_print_footer_scripts-index.php', [ $this, 'enqueue_notice' ] );
20 + }
21 +
22 + public function enqueue_notice() {
23 + if ( ! $this->should_display_notice() ) {
24 + return;
25 + }
26 +
27 + $this->set_seen_today();
28 + $this->enqueue_dependencies();
29 +
30 + $pointer_content = '<h3>' . esc_html__( 'Elementor’s 9th Birthday sale!', 'elementor' ) . '</h3>';
31 + $pointer_content .= '<p>' . esc_html__( 'Celebrate Elementor’s birthday with us—exclusive deals are available now.', 'elementor' );
32 + $pointer_content .= sprintf(
33 + '<p><a class="button button-primary" href="%s" target="_blank">%s</a></p>',
34 + self::PROMOTION_URL,
35 + esc_html__( 'View Deals', 'elementor' )
36 + );
37 +
38 + $allowed_tags = [
39 + 'h3' => [],
40 + 'p' => [],
41 + 'a' => [
42 + 'class' => [],
43 + 'target' => [ '_blank' ],
44 + 'href' => [],
45 + ],
46 + ];
47 + ?>
48 +
49 + <script>
50 + jQuery( document ).ready( function( $ ) {
51 + $( "#<?php echo esc_attr( self::ELEMENTOR_POINTER_ID ); ?>" ).pointer( {
52 + content: '<?php echo wp_kses( $pointer_content, $allowed_tags ); ?>',
53 + position: {
54 + edge: <?php echo is_rtl() ? "'right'" : "'left'"; ?>,
55 + align: "center"
56 + },
57 + close: function() {
58 + elementorCommon.ajax.addRequest( "introduction_viewed", {
59 + data: {
60 + introductionKey: '<?php echo esc_attr( static::DISMISS_ACTION_KEY ); ?>'
61 + }
62 + } );
63 + }
64 + } ).pointer( "open" );
65 + } );
66 + </script>
67 + <?php
68 + }
69 +
70 + public static function should_display_notice(): bool {
71 + return self::is_user_allowed() &&
72 + ! self::is_dismissed() &&
73 + self::is_campaign_time() &&
74 + ! self::is_already_seen_today() &&
75 + ! Utils::has_pro();
76 + }
77 +
78 + private static function is_user_allowed(): bool {
79 + return current_user_can( 'manage_options' ) || current_user_can( 'edit_pages' );
80 + }
81 +
82 + private static function is_campaign_time() {
83 + $start = new \DateTime( '2025-06-10 12:00:00', new \DateTimeZone( 'UTC' ) );
84 + $end = new \DateTime( '2025-06-17 03:59:00', new \DateTimeZone( 'UTC' ) );
85 + $now = new \DateTime( 'now', new \DateTimeZone( 'UTC' ) );
86 +
87 + return $now >= $start && $now <= $end;
88 + }
89 +
90 + private static function is_already_seen_today() {
91 + return get_transient( self::get_user_transient_id() );
92 + }
93 +
94 + private function set_seen_today() {
95 + $now = time();
96 + $midnight = strtotime( 'tomorrow midnight' );
97 + $seconds_until_midnight = $midnight - $now;
98 +
99 + set_transient( self::get_user_transient_id(), $now, $seconds_until_midnight );
100 + }
101 +
102 + private static function get_user_transient_id(): string {
103 + return self::SEEN_TODAY_KEY . '_' . get_current_user_id();
104 + }
105 +
106 + private function enqueue_dependencies() {
107 + wp_enqueue_script( 'wp-pointer' );
108 + wp_enqueue_style( 'wp-pointer' );
109 + }
110 +
111 + private static function is_dismissed(): bool {
112 + return User::get_introduction_meta( static::DISMISS_ACTION_KEY );
113 + }
114 + }
115 +