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 +56 -84 2.7.32.5 View file →
@@ -5,12 +5,11 @@
5 5 * displayed only to admin, based on 'manage_options' capability
6 6 * and only on dashboard, plugins and Polylang admin pages
7 7 *
8 8 * @since 2.3.9
9 - * @since 2.7 Dismissed notices are stored in an option instead of a user meta
10 9 */
11 10 class PLL_Admin_Notices {
12 - private static $notices = array();
11 + static private $notices = array();
13 12
14 13 /**
15 14 * Constructor
16 15 * Setup actions
@@ -57,24 +56,10 @@
57 56 * @param string $notice Notice name
58 57 * @return bool
59 58 */
60 59 public static function is_dismissed( $notice ) {
61 - $dismissed = get_option( 'pll_dismissed_notices', array() );
62 -
63 - // Handle legacy user meta
64 - $dismissed_meta = get_user_meta( get_current_user_id(), 'pll_dismissed_notices', true );
65 - if ( is_array( $dismissed_meta ) ) {
66 - if ( array_diff( $dismissed_meta, $dismissed ) ) {
67 - $dismissed = array_merge( $dismissed, $dismissed_meta );
68 - update_option( 'pll_dismissed_notices', $dismissed );
69 - }
70 - if ( ! is_multisite() ) {
71 - // Don't delete on multisite to avoid the notices to appear in other sites.
72 - delete_user_meta( get_current_user_id(), 'pll_dismissed_notices' );
73 - }
74 - }
75 -
76 - 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 );
77 62 }
78 63
79 64 /**
80 65 * Should we display notices on this screen?
@@ -80,36 +65,23 @@
80 65 * Should we display notices on this screen?
81 66 *
82 67 * @since 2.3.9
83 68 *
84 - * @param string $notice The notice name.
85 69 * @return bool
86 70 */
87 - protected function can_display_notice( $notice ) {
71 + protected function can_display_notice() {
88 72 $screen = get_current_screen();
89 73 $screen_id = sanitize_title( __( 'Languages', 'polylang' ) );
90 74
91 - /**
92 - * Filter admin notices which can be displayed
93 - *
94 - * @since 2.7.0
95 - *
96 - * @param bool $display Whether the notice should be displayed or not.
97 - * @param string $notice The notice name.
98 - */
99 - return apply_filters(
100 - 'pll_can_display_notice',
101 - in_array(
102 - $screen->id,
103 - array(
104 - 'dashboard',
105 - 'plugins',
106 - 'toplevel_page_mlang',
107 - $screen_id . '_page_mlang_strings',
108 - $screen_id . '_page_mlang_settings',
109 - )
110 - ),
111 - $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 + )
112 84 );
113 85 }
114 86
115 87 /**
@@ -119,13 +91,15 @@
119 91 *
120 92 * @param string $notice
121 93 */
122 94 public static function dismiss( $notice ) {
123 - $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 + }
124 98
125 99 if ( ! in_array( $notice, $dismissed ) ) {
126 100 $dismissed[] = $notice;
127 - update_option( 'pll_dismissed_notices', array_unique( $dismissed ) );
101 + update_user_meta( get_current_user_id(), 'pll_dismissed_notices', array_unique( $dismissed ) );
128 102 }
129 103 }
130 104
131 105 /**
@@ -148,21 +122,16 @@
148 122 *
149 123 * @since 2.3.9
150 124 */
151 125 public function display_notices() {
152 - if ( current_user_can( 'manage_options' ) ) {
126 + if ( current_user_can( 'manage_options' ) && $this->can_display_notice() ) {
153 127 // Core notices
154 - if ( defined( 'WOOCOMMERCE_VERSION' ) && ! defined( 'PLLWC_VERSION' ) && $this->can_display_notice( 'pllwc' ) && ! $this->is_dismissed( 'pllwc' ) ) {
155 - $this->pllwc_notice();
156 - }
128 + $this->pllwc_notice();
129 + $this->review_notice();
157 130
158 - 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 ) {
159 - $this->review_notice();
160 - }
161 -
162 131 // Custom notices
163 132 foreach ( $this->get_notices() as $notice => $html ) {
164 - if ( $this->can_display_notice( $notice ) && ! $this->is_dismissed( $notice ) ) {
133 + if ( ! $this->is_dismissed( $notice ) ) {
165 134 ?>
166 135 <div class="pll-notice notice notice-info">
167 136 <?php
168 137 $this->dismiss_button( $notice );
@@ -185,10 +154,9 @@
185 154 public function dismiss_button( $name ) {
186 155 printf(
187 156 '<a class="notice-dismiss" href="%s"><span class="screen-reader-text">%s</span></a>',
188 157 esc_url( wp_nonce_url( add_query_arg( 'pll-hide-notice', $name ), $name, '_pll_notice_nonce' ) ),
189 - /* translators: accessibility text */
190 - esc_html__( 'Dismiss this notice.', 'polylang' )
158 + esc_html__( 'Dismiss this notice.' )
191 159 );
192 160 }
193 161
194 162 /**
@@ -196,23 +164,25 @@
196 164 *
197 165 * @since 2.3.9
198 166 */
199 167 private function pllwc_notice() {
200 - ?>
201 - <div class="pll-notice notice notice-warning">
202 - <?php $this->dismiss_button( 'pllwc' ); ?>
203 - <p>
204 - <?php
205 - printf(
206 - /* translators: %1$s is link start tag, %2$s is link end tag. */
207 - 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' ),
208 - '<a href="https://polylang.pro/downloads/polylang-for-woocommerce/">',
209 - '</a>'
210 - );
211 - ?>
212 - </p>
213 - </div>
214 - <?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 + }
215 185 }
216 186
217 187 /**
218 188 * Displays a notice asking for a review
@@ -219,21 +189,23 @@
219 189 *
220 190 * @since 2.3.9
221 191 */
222 192 private function review_notice() {
223 - ?>
224 - <div class="pll-notice notice notice-info">
225 - <?php $this->dismiss_button( 'review' ); ?>
226 - <p>
227 - <?php
228 - printf(
229 - /* translators: %1$s is link start tag, %2$s is link end tag. */
230 - 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' ),
231 - '<a href="https://wordpress.org/support/plugin/polylang/reviews/?rate=5#new-post">',
232 - '</a>'
233 - );
234 - ?>
235 - </p>
236 - </div>
237 - <?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 + }
238 210 }
239 211 }