PluginProbe
Polylang / 3.7.7
Polylang v3.7.7
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 +82 -28 2.93.7.7 View file →
@@ -11,8 +11,20 @@
11 11 * @since 2.3.9
12 12 * @since 2.7 Dismissed notices are stored in an option instead of a user meta
13 13 */
14 14 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 + */
15 27 private static $notices = array();
16 28
17 29 /**
18 30 * Constructor
@@ -19,9 +31,9 @@
19 31 * Setup actions
20 32 *
21 33 * @since 2.3.9
22 34 *
23 - * @param object $polylang
35 + * @param object $polylang The Polylang object.
24 36 */
25 37 public function __construct( $polylang ) {
26 38 $this->options = &$polylang->options;
27 39
@@ -35,8 +47,9 @@
35 47 * @since 2.3.9
36 48 *
37 49 * @param string $name Notice name
38 50 * @param string $html Content of the notice
51 + * @return void
39 52 */
40 53 public static function add_notice( $name, $html ) {
41 54 self::$notices[ $name ] = $html;
42 55 }
@@ -41,13 +54,13 @@
41 54 self::$notices[ $name ] = $html;
42 55 }
43 56
44 57 /**
45 - * Get custom notices
58 + * Get custom notices.
46 59 *
47 60 * @since 2.3.9
48 61 *
49 - * @return array
62 + * @return string[]
50 63 */
51 64 public static function get_notices() {
52 65 return self::$notices;
53 66 }
@@ -83,17 +96,34 @@
83 96 * Should we display notices on this screen?
84 97 *
85 98 * @since 2.3.9
86 99 *
87 - * @param string $notice The notice name.
100 + * @param string $notice The notice name.
101 + * @param array $allowed_screens The screens allowed to display the notice.
102 + * If empty, default screens are used, i.e. dashboard, plugins, languages, strings and settings.
103 + *
88 104 * @return bool
89 105 */
90 - protected function can_display_notice( $notice ) {
106 + protected function can_display_notice( string $notice, array $allowed_screens = array() ) {
91 107 $screen = get_current_screen();
92 - $screen_id = sanitize_title( __( 'Languages', 'polylang' ) );
93 108
109 + if ( empty( $screen ) ) {
110 + return false;
111 + }
112 +
113 + if ( empty( $allowed_screens ) ) {
114 + $screen_id = sanitize_title( __( 'Languages', 'polylang' ) );
115 + $allowed_screens = array(
116 + 'dashboard',
117 + 'plugins',
118 + 'toplevel_page_mlang',
119 + $screen_id . '_page_mlang_strings',
120 + $screen_id . '_page_mlang_settings',
121 + );
122 + }
123 +
94 124 /**
95 - * Filter admin notices which can be displayed
125 + * Filters admin notices which can be displayed.
96 126 *
97 127 * @since 2.7.0
98 128 *
99 129 * @param bool $display Whether the notice should be displayed or not.
@@ -98,30 +128,18 @@
98 128 *
99 129 * @param bool $display Whether the notice should be displayed or not.
100 130 * @param string $notice The notice name.
101 131 */
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
115 - );
132 + return apply_filters( 'pll_can_display_notice', in_array( $screen->id, $allowed_screens, true ), $notice );
116 133 }
117 134
118 135 /**
119 - * Stores a dismissed notice in database
136 + * Stores a dismissed notice in the database.
120 137 *
121 138 * @since 2.3.9
122 139 *
123 - * @param string $notice
140 + * @param string $notice Notice name.
141 + * @return void
124 142 */
125 143 public static function dismiss( $notice ) {
126 144 $dismissed = get_option( 'pll_dismissed_notices', array() );
127 145
@@ -134,8 +152,10 @@
134 152 /**
135 153 * Handle a click on the dismiss button
136 154 *
137 155 * @since 2.3.9
156 + *
157 + * @return void
138 158 */
139 159 public function hide_notice() {
140 160 if ( isset( $_GET['pll-hide-notice'], $_GET['_pll_notice_nonce'] ) ) {
141 161 $notice = sanitize_key( $_GET['pll-hide-notice'] );
@@ -149,23 +169,34 @@
149 169 /**
150 170 * Displays notices
151 171 *
152 172 * @since 2.3.9
173 + *
174 + * @return void
153 175 */
154 176 public function display_notices() {
155 177 if ( current_user_can( 'manage_options' ) ) {
156 178 // Core notices
157 - if ( defined( 'WOOCOMMERCE_VERSION' ) && ! defined( 'PLLWC_VERSION' ) && $this->can_display_notice( 'pllwc' ) && ! $this->is_dismissed( 'pllwc' ) ) {
179 + if ( defined( 'WOOCOMMERCE_VERSION' ) && ! defined( 'PLLWC_VERSION' ) && $this->can_display_notice( 'pllwc' ) && ! static::is_dismissed( 'pllwc' ) ) {
158 180 $this->pllwc_notice();
159 181 }
160 182
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 ) {
183 + if ( ! defined( 'POLYLANG_PRO' ) && $this->can_display_notice( 'review' ) && ! static::is_dismissed( 'review' ) && ! empty( $this->options['first_activation'] ) && time() > $this->options['first_activation'] + 15 * DAY_IN_SECONDS ) {
162 184 $this->review_notice();
163 185 }
164 186
187 + $allowed_screen = sanitize_title( __( 'Languages', 'polylang' ) ) . '_page_mlang_strings';
188 + if (
189 + ( ! empty( $this->options['previous_version'] ) && version_compare( $this->options['previous_version'], '3.7.0', '<' ) )
190 + && $this->can_display_notice( 'empty-strings-translations', (array) $allowed_screen )
191 + && ! static::is_dismissed( 'empty-strings-translations' )
192 + ) {
193 + $this->empty_strings_translations_notice();
194 + }
195 +
165 196 // Custom notices
166 - foreach ( $this->get_notices() as $notice => $html ) {
167 - if ( $this->can_display_notice( $notice ) && ! $this->is_dismissed( $notice ) ) {
197 + foreach ( static::get_notices() as $notice => $html ) {
198 + if ( $this->can_display_notice( $notice ) && ! static::is_dismissed( $notice ) ) {
168 199 ?>
169 200 <div class="pll-notice notice notice-info">
170 201 <?php
171 202 $this->dismiss_button( $notice );
@@ -183,8 +214,9 @@
183 214 *
184 215 * @since 2.3.9
185 216 *
186 217 * @param string $name Notice name
218 + * @return void
187 219 */
188 220 public function dismiss_button( $name ) {
189 221 printf(
190 222 '<a class="notice-dismiss" href="%s"><span class="screen-reader-text">%s</span></a>',
@@ -197,8 +229,10 @@
197 229 /**
198 230 * Displays a notice if WooCommerce is activated without Polylang for WooCommerce
199 231 *
200 232 * @since 2.3.9
233 + *
234 + * @return void
201 235 */
202 236 private function pllwc_notice() {
203 237 ?>
204 238 <div class="pll-notice notice notice-warning">
@@ -207,9 +241,9 @@
207 241 <?php
208 242 printf(
209 243 /* translators: %1$s is link start tag, %2$s is link end tag. */
210 244 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/">',
245 + '<a href="https://polylang.pro/pricing/polylang-for-woocommerce/">',
212 246 '</a>'
213 247 );
214 248 ?>
215 249 </p>
@@ -220,8 +254,10 @@
220 254 /**
221 255 * Displays a notice asking for a review
222 256 *
223 257 * @since 2.3.9
258 + *
259 + * @return void
224 260 */
225 261 private function review_notice() {
226 262 ?>
227 263 <div class="pll-notice notice notice-info">
@@ -234,8 +270,26 @@
234 270 '<a href="https://wordpress.org/support/plugin/polylang/reviews/?rate=5#new-post">',
235 271 '</a>'
236 272 );
237 273 ?>
274 + </p>
275 + </div>
276 + <?php
277 + }
278 +
279 + /**
280 + * Displays a notice about the empty strings translations.
281 + *
282 + * @since 3.7
283 + *
284 + * @return void
285 + */
286 + private function empty_strings_translations_notice() {
287 + ?>
288 + <div class="pll-notice notice notice-info">
289 + <?php $this->dismiss_button( 'empty-strings-translations' ); ?>
290 + <p>
291 + <?php esc_html_e( 'Translations matching the original string are shown as empty in the table. Untranslated content remains unchanged.', 'polylang' ); ?>
238 292 </p>
239 293 </div>
240 294 <?php
241 295 }