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