PluginProbe
Polylang / 2.5
Polylang v2.5
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 +58 -117 3.0.22.5 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,26 +5,13 @@
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;
11 + static private $notices = array();
21 12
22 13 /**
23 - * Stores custom notices.
24 - *
25 - * @var string[]
26 - */
27 - private static $notices = array();
28 -
29 - /**
30 14 * Constructor
31 15 * Setup actions
32 16 *
33 17 * @since 2.3.9
@@ -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,16 +149,14 @@
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>',
215 157 esc_url( wp_nonce_url( add_query_arg( 'pll-hide-notice', $name ), $name, '_pll_notice_nonce' ) ),
216 - /* translators: accessibility text */
217 - esc_html__( 'Dismiss this notice.', 'polylang' )
158 + esc_html__( 'Dismiss this notice.' )
218 159 );
219 160 }
220 161
221 162 /**
@@ -221,27 +162,27 @@
221 162 /**
222 163 * Displays a notice if WooCommerce is activated without Polylang for WooCommerce
223 164 *
224 165 * @since 2.3.9
225 - *
226 - * @return void
227 166 */
228 167 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
168 + if ( defined( 'WOOCOMMERCE_VERSION' ) && ! defined( 'PLLWC_VERSION' ) && ! $this->is_dismissed( 'pllwc' ) ) {
169 + ?>
170 + <div class="pll-notice notice notice-warning">
171 + <?php $this->dismiss_button( 'pllwc' ); ?>
172 + <p>
173 + <?php
174 + printf(
175 + /* translators: %1$s is link start tag, %2$s is link end tag. */
176 + esc_html__( 'We have noticed that you are using Polylang with WooCommerce. We recommend you to use %1$sPolylang for WooCommerce%2$s to ensure the compatibility.', 'polylang' ),
177 + '<a href="https://polylang.pro/downloads/polylang-for-woocommerce/">',
178 + '</a>'
179 + );
180 + ?>
181 + </p>
182 + </div>
183 + <?php
184 + }
244 185 }
245 186
246 187 /**
247 188 * Displays a notice asking for a review
@@ -246,25 +187,25 @@
246 187 /**
247 188 * Displays a notice asking for a review
248 189 *
249 190 * @since 2.3.9
250 - *
251 - * @return void
252 191 */
253 192 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
193 + if ( ! defined( 'POLYLANG_PRO' ) && ! $this->is_dismissed( 'review' ) && ! empty( $this->options['first_activation'] ) && time() > $this->options['first_activation'] + 15 * DAY_IN_SECONDS ) {
194 + ?>
195 + <div class="pll-notice notice notice-info">
196 + <?php $this->dismiss_button( 'review' ); ?>
197 + <p>
198 + <?php
199 + printf(
200 + /* translators: %1$s is link start tag, %2$s is link end tag. */
201 + esc_html__( 'We have noticed that you are using Polylang for some time. We hope that you love it! We would be thrilled if you could %1$sgive us a 5 stars rating%2$s.', 'polylang' ),
202 + '<a href="https://wordpress.org/support/plugin/polylang/reviews/?rate=5#new-post">',
203 + '</a>'
204 + );
205 + ?>
206 + </p>
207 + </div>
208 + <?php
209 + }
269 210 }
270 211 }