PluginProbe
Polylang / 2.6.3
Polylang v2.6.3
3.8.9 3.8.8 3.8.7 3.8.6 3.8.5 3.8.4 3.8.3 2.7 2.7.0.1 2.7.1 2.7.2 2.7.3 2.7.4 2.8 2.8.1 2.8.2 2.8.3 2.8.4 2.9 2.9.1 2.9.2 3.0 3.0.1 3.0.2 3.0.3 All 233 releases
← All changes | admin/admin-notices.php +56 -114 3.02.6.3 View file →
@@ -1,8 +1,5 @@
1 1 <?php
2 -/**
3 - * @package Polylang
4 - */
5 2
6 3 /**
7 4 * A class to manage admin notices
8 5 * displayed only to admin, based on 'manage_options' capability
@@ -8,23 +5,10 @@
8 5 * displayed only to admin, based on 'manage_options' capability
9 6 * and only on dashboard, plugins and Polylang admin pages
10 7 *
11 8 * @since 2.3.9
12 - * @since 2.7 Dismissed notices are stored in an option instead of a user meta
13 9 */
14 10 class PLL_Admin_Notices {
15 - /**
16 - * Stores the plugin options.
17 - *
18 - * @var array
19 - */
20 - protected $options;
21 -
22 - /**
23 - * Stores custom notices.
24 - *
25 - * @var string[]
26 - */
27 11 private static $notices = array();
28 12
29 13 /**
30 14 * Constructor
@@ -47,9 +31,8 @@
47 31 * @since 2.3.9
48 32 *
49 33 * @param string $name Notice name
50 34 * @param string $html Content of the notice
51 - * @return void
52 35 */
53 36 public static function add_notice( $name, $html ) {
54 37 self::$notices[ $name ] = $html;
55 38 }
@@ -54,13 +37,13 @@
54 37 self::$notices[ $name ] = $html;
55 38 }
56 39
57 40 /**
58 - * Get custom notices.
41 + * Get custom notices
59 42 *
60 43 * @since 2.3.9
61 44 *
62 - * @return string[]
45 + * @return array
63 46 */
64 47 public static function get_notices() {
65 48 return self::$notices;
66 49 }
@@ -73,24 +56,10 @@
73 56 * @param string $notice Notice name
74 57 * @return bool
75 58 */
76 59 public static function is_dismissed( $notice ) {
77 - $dismissed = get_option( 'pll_dismissed_notices', array() );
78 -
79 - // Handle legacy user meta
80 - $dismissed_meta = get_user_meta( get_current_user_id(), 'pll_dismissed_notices', true );
81 - if ( is_array( $dismissed_meta ) ) {
82 - if ( array_diff( $dismissed_meta, $dismissed ) ) {
83 - $dismissed = array_merge( $dismissed, $dismissed_meta );
84 - update_option( 'pll_dismissed_notices', $dismissed );
85 - }
86 - if ( ! is_multisite() ) {
87 - // Don't delete on multisite to avoid the notices to appear in other sites.
88 - delete_user_meta( get_current_user_id(), 'pll_dismissed_notices' );
89 - }
90 - }
91 -
92 - return in_array( $notice, $dismissed );
60 + $dismissed = get_user_meta( get_current_user_id(), 'pll_dismissed_notices', true );
61 + return is_array( $dismissed ) && in_array( $notice, $dismissed );
93 62 }
94 63
95 64 /**
96 65 * Should we display notices on this screen?
@@ -96,41 +65,23 @@
96 65 * Should we display notices on this screen?
97 66 *
98 67 * @since 2.3.9
99 68 *
100 - * @param string $notice The notice name.
101 69 * @return bool
102 70 */
103 - protected function can_display_notice( $notice ) {
71 + protected function can_display_notice() {
104 72 $screen = get_current_screen();
105 -
106 - if ( empty( $screen ) ) {
107 - return false;
108 - }
109 -
110 73 $screen_id = sanitize_title( __( 'Languages', 'polylang' ) );
111 74
112 - /**
113 - * Filter admin notices which can be displayed
114 - *
115 - * @since 2.7.0
116 - *
117 - * @param bool $display Whether the notice should be displayed or not.
118 - * @param string $notice The notice name.
119 - */
120 - return apply_filters(
121 - 'pll_can_display_notice',
122 - in_array(
123 - $screen->id,
124 - array(
125 - 'dashboard',
126 - 'plugins',
127 - 'toplevel_page_mlang',
128 - $screen_id . '_page_mlang_strings',
129 - $screen_id . '_page_mlang_settings',
130 - )
131 - ),
132 - $notice
75 + return in_array(
76 + $screen->id,
77 + array(
78 + 'dashboard',
79 + 'plugins',
80 + 'toplevel_page_mlang',
81 + $screen_id . '_page_mlang_strings',
82 + $screen_id . '_page_mlang_settings',
83 + )
133 84 );
134 85 }
135 86
136 87 /**
@@ -138,16 +89,17 @@
138 89 *
139 90 * @since 2.3.9
140 91 *
141 92 * @param string $notice
142 - * @return void
143 93 */
144 94 public static function dismiss( $notice ) {
145 - $dismissed = get_option( 'pll_dismissed_notices', array() );
95 + if ( ! $dismissed = get_user_meta( get_current_user_id(), 'pll_dismissed_notices', true ) ) {
96 + $dismissed = array();
97 + }
146 98
147 99 if ( ! in_array( $notice, $dismissed ) ) {
148 100 $dismissed[] = $notice;
149 - update_option( 'pll_dismissed_notices', array_unique( $dismissed ) );
101 + update_user_meta( get_current_user_id(), 'pll_dismissed_notices', array_unique( $dismissed ) );
150 102 }
151 103 }
152 104
153 105 /**
@@ -153,10 +105,8 @@
153 105 /**
154 106 * Handle a click on the dismiss button
155 107 *
156 108 * @since 2.3.9
157 - *
158 - * @return void
159 109 */
160 110 public function hide_notice() {
161 111 if ( isset( $_GET['pll-hide-notice'], $_GET['_pll_notice_nonce'] ) ) {
162 112 $notice = sanitize_key( $_GET['pll-hide-notice'] );
@@ -170,25 +120,18 @@
170 120 /**
171 121 * Displays notices
172 122 *
173 123 * @since 2.3.9
174 - *
175 - * @return void
176 124 */
177 125 public function display_notices() {
178 - if ( current_user_can( 'manage_options' ) ) {
126 + if ( current_user_can( 'manage_options' ) && $this->can_display_notice() ) {
179 127 // Core notices
180 - if ( defined( 'WOOCOMMERCE_VERSION' ) && ! defined( 'PLLWC_VERSION' ) && $this->can_display_notice( 'pllwc' ) && ! $this->is_dismissed( 'pllwc' ) ) {
181 - $this->pllwc_notice();
182 - }
128 + $this->pllwc_notice();
129 + $this->review_notice();
183 130
184 - if ( ! defined( 'POLYLANG_PRO' ) && $this->can_display_notice( 'review' ) && ! $this->is_dismissed( 'review' ) && ! empty( $this->options['first_activation'] ) && time() > $this->options['first_activation'] + 15 * DAY_IN_SECONDS ) {
185 - $this->review_notice();
186 - }
187 -
188 131 // Custom notices
189 132 foreach ( $this->get_notices() as $notice => $html ) {
190 - if ( $this->can_display_notice( $notice ) && ! $this->is_dismissed( $notice ) ) {
133 + if ( ! $this->is_dismissed( $notice ) ) {
191 134 ?>
192 135 <div class="pll-notice notice notice-info">
193 136 <?php
194 137 $this->dismiss_button( $notice );
@@ -206,9 +149,8 @@
206 149 *
207 150 * @since 2.3.9
208 151 *
209 152 * @param string $name Notice name
210 - * @return void
211 153 */
212 154 public function dismiss_button( $name ) {
213 155 printf(
214 156 '<a class="notice-dismiss" href="%s"><span class="screen-reader-text">%s</span></a>',
@@ -221,27 +163,27 @@
221 163 /**
222 164 * Displays a notice if WooCommerce is activated without Polylang for WooCommerce
223 165 *
224 166 * @since 2.3.9
225 - *
226 - * @return void
227 167 */
228 168 private function pllwc_notice() {
229 - ?>
230 - <div class="pll-notice notice notice-warning">
231 - <?php $this->dismiss_button( 'pllwc' ); ?>
232 - <p>
233 - <?php
234 - printf(
235 - /* translators: %1$s is link start tag, %2$s is link end tag. */
236 - esc_html__( 'We have noticed that you are using Polylang with WooCommerce. To ensure compatibility, we recommend you use %1$sPolylang for WooCommerce%2$s.', 'polylang' ),
237 - '<a href="https://polylang.pro/downloads/polylang-for-woocommerce/">',
238 - '</a>'
239 - );
240 - ?>
241 - </p>
242 - </div>
243 - <?php
169 + if ( defined( 'WOOCOMMERCE_VERSION' ) && ! defined( 'PLLWC_VERSION' ) && ! $this->is_dismissed( 'pllwc' ) ) {
170 + ?>
171 + <div class="pll-notice notice notice-warning">
172 + <?php $this->dismiss_button( 'pllwc' ); ?>
173 + <p>
174 + <?php
175 + printf(
176 + /* translators: %1$s is link start tag, %2$s is link end tag. */
177 + esc_html__( 'We have noticed that you are using Polylang with WooCommerce. To ensure compatibility, we recommend you use %1$sPolylang for WooCommerce%2$s.', 'polylang' ),
178 + '<a href="https://polylang.pro/downloads/polylang-for-woocommerce/">',
179 + '</a>'
180 + );
181 + ?>
182 + </p>
183 + </div>
184 + <?php
185 + }
244 186 }
245 187
246 188 /**
247 189 * Displays a notice asking for a review
@@ -246,25 +188,25 @@
246 188 /**
247 189 * Displays a notice asking for a review
248 190 *
249 191 * @since 2.3.9
250 - *
251 - * @return void
252 192 */
253 193 private function review_notice() {
254 - ?>
255 - <div class="pll-notice notice notice-info">
256 - <?php $this->dismiss_button( 'review' ); ?>
257 - <p>
258 - <?php
259 - printf(
260 - /* translators: %1$s is link start tag, %2$s is link end tag. */
261 - esc_html__( 'We have noticed that you have been using Polylang for some time. We hope you love it, and we would really appreciate it if you would %1$sgive us a 5 stars rating%2$s.', 'polylang' ),
262 - '<a href="https://wordpress.org/support/plugin/polylang/reviews/?rate=5#new-post">',
263 - '</a>'
264 - );
265 - ?>
266 - </p>
267 - </div>
268 - <?php
194 + if ( ! defined( 'POLYLANG_PRO' ) && ! $this->is_dismissed( 'review' ) && ! empty( $this->options['first_activation'] ) && time() > $this->options['first_activation'] + 15 * DAY_IN_SECONDS ) {
195 + ?>
196 + <div class="pll-notice notice notice-info">
197 + <?php $this->dismiss_button( 'review' ); ?>
198 + <p>
199 + <?php
200 + printf(
201 + /* translators: %1$s is link start tag, %2$s is link end tag. */
202 + esc_html__( 'We have noticed that you have been using Polylang for some time. We hope you love it, and we would really appreciate it if you would %1$sgive us a 5 stars rating%2$s.', 'polylang' ),
203 + '<a href="https://wordpress.org/support/plugin/polylang/reviews/?rate=5#new-post">',
204 + '</a>'
205 + );
206 + ?>
207 + </p>
208 + </div>
209 + <?php
210 + }
269 211 }
270 212 }