PluginProbe
Adminify – White Label, Admin Menu Editor, Login Customizer / 3.2.4.1
Adminify – White Label, Admin Menu Editor, Login Customizer v3.2.4.1
4.3.1 4.3.0 4.2.26 4.2.25 4.2.24 4.2.23 4.2.22 4.2.21 4.2.20 4.2.19 4.2.18 4.2.17 4.2.16 4.2.15 4.2.14 4.2.13 4.2.12 4.2.11 4.2.10 4.2.9 4.2.8 4.2.7 4.2.6 4.2.5 4.1.17 All 164 releases
adminify / Inc / Modules / NotificationBar / Inc / Notificationbar_Output.php

Notificationbar_Output.php in Adminify – White Label, Admin Menu Editor, Login Customizer 3.2.4.1, at Inc/Modules/NotificationBar/Inc/Notificationbar_Output.php

203 lines 7.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace WPAdminify\Inc\Modules\NotificationBar\Inc;
4 use WPAdminify\Inc\Utils;
5
6 if ( ! defined( 'ABSPATH' ) ) {
7 die;
8 } // Cannot access directly.
9
10 /**
11 * WP Adminify
12 * Module: Notification Bar Customization
13 *
14 * @author Jewel Theme <support@jeweltheme.com>
15 */
16
17 class Notificationbar_Output {
18
19 public $url;
20 public $prefix = '_adminify_notification_bar';
21 public $options;
22
23 public function __construct() {
24 $this->url = WP_ADMINIFY_URL . 'Inc/Modules/NotificationBar';
25 $this->options = ( new Notification_Customize() )->get();
26
27 add_filter( 'body_class', [ $this, 'add_body_class' ] );
28
29 // Add notification to the site.
30 add_action( 'wp', [ $this, 'adminify_notification_bar' ] );
31 }
32
33
34 /**
35 * Add Body Class for Notification bar
36 *
37 * @return void
38 */
39 public function add_body_class( $classes ) {
40 if ( ! empty( $this->options['show_notif_bar'] ) ) {
41 $classes[] = 'wp-adminify-notification-bar';
42 }
43
44 return $classes;
45 }
46
47
48 public function jltwp_adminify_notif_bar_devices_display() {
49 $isdevicesDisplay = $this->options['display_devices'];
50 if ( $isdevicesDisplay == 'all_devices' ) {
51 return true;
52 }
53 if ( $isdevicesDisplay == 'desktop' && ! wp_is_mobile() ) {
54 return true;
55 }
56 if ( $isdevicesDisplay == 'mobile' && wp_is_mobile() ) {
57 return true;
58 }
59 return false;
60 }
61
62
63 /**
64 * Add Notification Bar to site
65 */
66 public function adminify_notification_bar() {
67 if ( is_customize_preview() || ! empty( $this->options['show_notif_bar'] ) ) {
68 $priority = apply_filters( 'wp_adminify_notification_bar_priority', 10 );
69 add_filter( 'wp_adminify_notification_bar_message', 'wp_kses_post' );
70 add_filter( 'wp_adminify_notification_bar_message', 'shortcode_unautop' );
71 add_filter( 'wp_adminify_notification_bar_message', 'do_shortcode', 11 );
72
73 // Enqueue Notification Bar Script
74 add_action( 'wp_enqueue_scripts', [ $this, 'adminify_enqueue_scripts' ] );
75 }
76 }
77
78
79 // Enqueue Notification Bar Script
80 public function adminify_enqueue_scripts() {
81 wp_enqueue_script( 'wp-adminify-notification-bar', $this->url . '/assets/js/wp-adminify-notification-bar.min.js', [ 'jquery' ], WP_ADMINIFY_VER, true );
82
83 $notification_content = ! empty( $this->options['notif_bar_content_section']['notif_bar_content'] ) ? Utils::wp_kses_custom( $this->options['notif_bar_content_section']['notif_bar_content'] ) : '';
84 $text_color = ! empty( $this->options['text_color'] ) ? esc_html( $this->options['text_color'] ) : '#fff';
85
86 $notif_bar_typography = wp_kses_post_deep( $this->options['typography_sets'] );
87 $notif_bar_color = ! empty( $notif_bar_typography['color'] ) ? esc_html( $notif_bar_typography['color'] ) : '';
88 $notif_bar_unit = ! empty( $notif_bar_typography['unit'] ) ? esc_html( $notif_bar_typography['unit'] ) : '';
89 $notif_bar_font_size = ! empty( $notif_bar_typography['font-size'] ) ? esc_html( $notif_bar_typography['font-size'] . $notif_bar_unit ) : '12px';
90 $notif_bar_font_family = ! empty( $notif_bar_typography['font-family'] ) ? esc_html( $notif_bar_typography['font-family'] ) : '';
91 $notif_bar_font_style = ! empty( $notif_bar_typography['font-style'] ) ? esc_html( $notif_bar_typography['font-style'] ) : 'inherit';
92
93 $notice_bg_color = ! empty( $this->options['bg_color'] ) ? esc_html( $this->options['bg_color'] ) : '#000';
94
95 $show_notif_bar_btn = ! empty( $this->options['notif_bar_content_section']['show_notif_bar_btn'] ) ? true : false;
96 $btn_url = ! empty( $this->options['notif_bar_content_section']['notif_btn_url']['url'] ) ? esc_url( $this->options['notif_bar_content_section']['notif_btn_url']['url'] ) : '';
97 $btn_text = ! empty( $this->options['notif_bar_content_section']['notif_btn'] ) ? esc_html( $this->options['notif_bar_content_section']['notif_btn'] ) : '';
98 $btn_target = ! empty( $this->options['notif_bar_content_section']['notif_btn_url']['target'] ) ? esc_html( $this->options['notif_bar_content_section']['notif_btn_url']['target'] ) : '';
99 $btn_text_color = ! empty( $this->options['btn_text_color'] ) ? esc_html( $this->options['btn_text_color'] ) : '#fff';
100 $btn_bg_color = ! empty( $this->options['btn_color'] ) ? esc_html( $this->options['btn_color'] ) : '#d35400';
101 $link_color = ! empty( $this->options['link_color'] ) ? esc_html( $this->options['link_color'] ) : '#009fdd';
102 $link_bg_color = ! empty( $this->options['link_bg_color'] ) ? esc_html( $this->options['link_bg_color'] ) : '';
103
104 $display_position = ! empty( $this->options['display_position'] ) ? esc_html( $this->options['display_position'] ) : 'bottom';
105 $expires_in = ! empty( $this->options['expires_in'] ) ? esc_html( $this->options['expires_in'] ) : 30;
106 $close_btn_text = ! empty( $this->options['close_btn_text'] ) ? esc_html( $this->options['close_btn_text'] ) : 'bottom';
107
108 wp_add_inline_script(
109 'wp-adminify-notification-bar',
110 'new cookieNoticeJS(' . json_encode(
111 [
112 'messageLocales' => [
113 'en' => $notification_content,
114 ],
115
116 // Localizations of the dismiss button text
117 'buttonLocales' => [
118 // 'en' => $close_btn_text
119 'en' => $close_btn_text,
120 ],
121
122 // Position for the cookie-notifier (default=bottom)
123 'cookieNoticePosition' => $display_position,
124 'closeButtonEnabled' => true,
125 // Shows the "learn more button (default=false)
126 'learnMoreLinkEnabled' => $show_notif_bar_btn,
127
128 // The href of the learn more link must be applied if (learnMoreLinkEnabled=true)
129 'learnMoreLinkHref' => $btn_url,
130
131 // Text for optional learn more button
132 'learnMoreLinkText' => [
133 'en' => $btn_text,
134 ],
135
136 // The message will be shown again in X days
137 'expiresIn' => $expires_in,
138
139 // Specify a custom font family and size in pixels
140 'fontFamily' => $notif_bar_font_family,
141 'fontSize' => $notif_bar_font_size,
142
143 // Dismiss button background color
144 'buttonBgColor' => $btn_bg_color,
145
146 // Dismiss button text color
147 'buttonTextColor' => $btn_text_color,
148
149 // Notice background color
150 'noticeBgColor' => $notice_bg_color,
151
152 // Notice text color
153 'noticeTextColor' => $text_color,
154
155 // the learnMoreLink color (default='#009fdd')
156 'linkColor' => $link_color,
157
158 // The target of the learn more link (default='', or '_blank')
159 'linkTarget' => $btn_target,
160
161 ]
162 ) . ');',
163 'after'
164 );
165
166 if ( $inline_css = $this->inline_css() ) {
167 wp_add_inline_style( 'wp-adminify-notification-bar', $inline_css );
168 }
169 }
170
171
172 /**
173 * Notification Bar output CSS.
174 *
175 * @access public
176 */
177 public function inline_css() {
178 $output_css = $main_css = '';
179
180 $background_color = ! empty( $this->options['bg_color'] ) ? esc_html( $this->options['bg_color'] ) : '#000';
181 if ( $background_color ) {
182 $main_css .= 'background:' . $background_color . ';';
183 }
184
185 if ( $text_color = $this->options['text_color'] ) {
186 $main_css .= 'color:' . esc_html( $text_color ) . ';';
187 }
188
189 if ( $font_size = isset( $this->options['typography']['font-size'] ) && $this->options['typography']['font-size'] ) {
190 $font_size_escaped = is_numeric( $font_size ) ? absint( $font_size ) . 'px' : esc_attr( $font_size );
191 $main_css .= 'font-size:' . Utils::wp_kses_custom( $font_size_escaped ) . ';';
192 }
193
194 if ( $main_css ) {
195 $output_css .= '#wp-adminify-notification-bar{' . $main_css . '}';
196 }
197
198 $output_css .= '.logged-in.admin-bar #cookieNotice{ top:32px;}';
199
200 return $output_css;
201 }
202 }
203