PluginProbe
Elementor Website Builder – more than just a page builder / 3.16.0-dev1
Elementor Website Builder – more than just a page builder v3.16.0-dev1
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.16.0-dev1, at core/editor/notice-bar.php

130 lines 3.4 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\Plugin;
7 use Elementor\Utils;
8
9 if ( ! defined( 'ABSPATH' ) ) {
10 exit; // Exit if accessed directly
11 }
12
13 class Notice_Bar extends Base_Object {
14
15 protected function get_init_settings() {
16 if ( Plugin::$instance->get_install_time() > strtotime( '-1 days' ) ) {
17 return [];
18 }
19
20 return [
21 'muted_period' => 14,
22 'option_key' => '_elementor_editor_upgrade_notice_dismissed',
23 'message' => esc_html__( 'Unleash the full power of Elementor\'s features and web creation tools.', 'elementor' ),
24 'action_title' => esc_html__( 'Upgrade Now', 'elementor' ),
25 'action_url' => 'https://go.elementor.com/go-pro-editor-notice-bar/',
26 ];
27 }
28
29 final public function get_notice() {
30 if ( ! $this->has_access_to_notice() ) {
31 return null;
32 }
33
34 $settings = $this->get_settings();
35
36 if ( empty( $settings['option_key'] ) ) {
37 return null;
38 }
39
40 $dismissed_time = get_option( $settings['option_key'] );
41
42 if ( $dismissed_time ) {
43 if ( $dismissed_time > strtotime( '-' . $settings['muted_period'] . ' days' ) ) {
44 return null;
45 }
46
47 $this->set_notice_dismissed();
48 }
49
50 return $this;
51 }
52
53 protected function render_action( $type ) {
54 $settings = $this->get_settings();
55
56 // TODO: Make the API better. The bad naming is because of BC.
57 $prefix_map = [
58 'primary' => '',
59 'secondary' => 'secondary_',
60 ];
61
62 $prefix = $prefix_map[ $type ];
63
64 $action_title = "{$prefix}action_title";
65 $action_url = "{$prefix}action_url";
66 $action_message = "{$prefix}message";
67 $action_target = "{$prefix}action_target";
68
69 if ( empty( $settings[ $action_title ] ) || empty( $settings[ $action_url ] ) || empty( $settings[ $action_message ] ) ) {
70 return;
71
72 }
73
74 ?>
75 <div class="e-notice-bar__message <?php echo esc_attr( "e-notice-bar__{$type}_message" ); ?>">
76 <?php Utils::print_unescaped_internal_string( sprintf( $settings[ $action_message ], $settings[ $action_url ] ) ); ?>
77 </div>
78
79 <div class="e-notice-bar__action <?php echo esc_attr( "e-notice-bar__{$type}_action" ); ?>">
80 <a href="<?php Utils::print_unescaped_internal_string( $settings[ $action_url ] ); ?>"
81 target="<?php echo empty( $settings[ $action_target ] ) ? '_blank' : esc_attr( $settings[ $action_target ] ); ?>"
82 >
83 <?php Utils::print_unescaped_internal_string( $settings[ $action_title ] ); ?>
84 </a>
85 </div>
86 <?php
87 }
88
89 public function render() {
90 $settings = $this->get_settings();
91
92 $icon = empty( $settings['icon'] )
93 ? 'eicon-elementor-square'
94 : esc_attr( $settings['icon'] );
95
96 ?>
97 <div id="e-notice-bar" class="e-notice-bar">
98 <i class="e-notice-bar__icon <?php echo esc_attr( $icon ); ?>"></i>
99
100 <?php
101 $this->render_action( 'primary' );
102 $this->render_action( 'secondary' );
103 ?>
104
105 <i id="e-notice-bar__close" class="e-notice-bar__close eicon-close"></i>
106 </div>
107 <?php
108 }
109
110 public function __construct() {
111 add_action( 'elementor/ajax/register_actions', [ $this, 'register_ajax_actions' ] );
112 }
113
114 public function set_notice_dismissed() {
115 if ( ! $this->has_access_to_notice() ) {
116 throw new \Exception( 'Access denied' );
117 }
118
119 update_option( $this->get_settings( 'option_key' ), time() );
120 }
121
122 public function register_ajax_actions( Ajax $ajax ) {
123 $ajax->register_ajax_action( 'notice_bar_dismiss', [ $this, 'set_notice_dismissed' ] );
124 }
125
126 private function has_access_to_notice() {
127 return current_user_can( 'manage_options' );
128 }
129 }
130