PluginProbe
Elementor Website Builder – more than just a page builder / 3.20.4
Elementor Website Builder – more than just a page builder v3.20.4
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
elementor / core / editor / notice-bar.php

notice-bar.php in Elementor Website Builder – more than just a page builder 3.20.4, at core/editor/notice-bar.php

153 lines 4.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Elementor\Core\Editor;
3
4 use Elementor\Core\Base\Base_Object;
5 use Elementor\Core\Common\Modules\Ajax\Module as Ajax;
6 use Elementor\Core\Utils\Promotions\Validate_Promotion;
7 use Elementor\Plugin;
8 use Elementor\Utils;
9
10 if ( ! defined( 'ABSPATH' ) ) {
11 exit; // Exit if accessed directly
12 }
13
14 class Notice_Bar extends Base_Object {
15
16 protected function get_init_settings() {
17 if ( Plugin::$instance->get_install_time() > strtotime( '-1 days' ) ) {
18 return [];
19 }
20
21 $upgrade_url = 'https://go.elementor.com/go-pro-editor-notice-bar/';
22
23 $config = [
24 'description' => $this->get_description(),
25 'upgrade_text' => $this->get_upgrade_text(),
26 'upgrade_url' => $upgrade_url,
27 ];
28
29 $config = apply_filters( 'elementor/notice-bar/custom_promotion', $config );
30
31 if ( isset( $config['upgrade_url'] ) && ! Validate_Promotion::domain_is_on_elementor_dot_com( $config['upgrade_url'] ) ) {
32 $config['upgrade_url'] = esc_url( $upgrade_url );
33 }
34
35 return [
36 'muted_period' => 14,
37 'option_key' => '_elementor_editor_upgrade_notice_dismissed',
38 'message' => $config['description'] ?? $this->get_description(),
39 'action_title' => $config['upgrade_text'] ?? $this->get_upgrade_text(),
40 'action_url' => $config['upgrade_url'] ?? $upgrade_url,
41 ];
42 }
43
44 public function get_upgrade_text() {
45 return esc_html__( 'Upgrade Now', 'elementor' );
46 }
47
48 public function get_description() {
49 return esc_html__( 'Unleash the full power of Elementor\'s features and web creation tools.', 'elementor' );
50 }
51
52 final public function get_notice() {
53 if ( ! $this->has_access_to_notice() ) {
54 return null;
55 }
56
57 $settings = $this->get_settings();
58
59 if ( empty( $settings['option_key'] ) ) {
60 return null;
61 }
62
63 $dismissed_time = get_option( $settings['option_key'] );
64
65 if ( $dismissed_time ) {
66 if ( $dismissed_time > strtotime( '-' . $settings['muted_period'] . ' days' ) ) {
67 return null;
68 }
69
70 $this->set_notice_dismissed();
71 }
72
73 return $this;
74 }
75
76 protected function render_action( $type ) {
77 $settings = $this->get_settings();
78
79 // TODO: Make the API better. The bad naming is because of BC.
80 $prefix_map = [
81 'primary' => '',
82 'secondary' => 'secondary_',
83 ];
84
85 $prefix = $prefix_map[ $type ];
86
87 $action_title = "{$prefix}action_title";
88 $action_url = "{$prefix}action_url";
89 $action_message = "{$prefix}message";
90 $action_target = "{$prefix}action_target";
91
92 if ( empty( $settings[ $action_title ] ) || empty( $settings[ $action_url ] ) || empty( $settings[ $action_message ] ) ) {
93 return;
94
95 }
96
97 ?>
98 <div class="e-notice-bar__message <?php echo esc_attr( "e-notice-bar__{$type}_message" ); ?>">
99 <?php Utils::print_unescaped_internal_string( sprintf( $settings[ $action_message ], $settings[ $action_url ] ) ); ?>
100 </div>
101
102 <div class="e-notice-bar__action <?php echo esc_attr( "e-notice-bar__{$type}_action" ); ?>">
103 <a href="<?php Utils::print_unescaped_internal_string( $settings[ $action_url ] ); ?>"
104 target="<?php echo empty( $settings[ $action_target ] ) ? '_blank' : esc_attr( $settings[ $action_target ] ); ?>"
105 >
106 <?php Utils::print_unescaped_internal_string( $settings[ $action_title ] ); ?>
107 </a>
108 </div>
109 <?php
110 }
111
112 public function render() {
113 $settings = $this->get_settings();
114
115 $icon = empty( $settings['icon'] )
116 ? 'eicon-elementor-square'
117 : esc_attr( $settings['icon'] );
118
119 ?>
120 <div id="e-notice-bar" class="e-notice-bar">
121 <i class="e-notice-bar__icon <?php echo esc_attr( $icon ); ?>"></i>
122
123 <?php
124 $this->render_action( 'primary' );
125 $this->render_action( 'secondary' );
126 ?>
127
128 <i id="e-notice-bar__close" class="e-notice-bar__close eicon-close"></i>
129 </div>
130 <?php
131 }
132
133 public function __construct() {
134 add_action( 'elementor/ajax/register_actions', [ $this, 'register_ajax_actions' ] );
135 }
136
137 public function set_notice_dismissed() {
138 if ( ! $this->has_access_to_notice() ) {
139 throw new \Exception( 'Access denied' );
140 }
141
142 update_option( $this->get_settings( 'option_key' ), time() );
143 }
144
145 public function register_ajax_actions( Ajax $ajax ) {
146 $ajax->register_ajax_action( 'notice_bar_dismiss', [ $this, 'set_notice_dismissed' ] );
147 }
148
149 private function has_access_to_notice() {
150 return current_user_can( 'manage_options' );
151 }
152 }
153