@@ -215,11 +215,20 @@ function __construct() {
215215 static function activation_check () {
216216 if ( ! self ::compatible_version () ) {
217217 deactivate_plugins ( self ::$ plugin_basename );
218- wp_die ( __ ( 'The plugin "UNFC Normalize" is not compatible with your system and can \'t be activated. ' , 'unfc-normalize ' ) );
218+ /* translators: %s: url to admin plugins page. */
219+ wp_die ( sprintf (
220+ __ ( 'The plugin "UNFC Normalize" is not compatible with your system and can \'t be activated. <a href="%s">Return to Plugins page.</a> ' , 'unfc-normalize ' ),
221+ esc_url ( self_admin_url ( 'plugins.php ' ) )
222+ ) );
219223 } else {
220224 if ( ! self ::tested_wp_version () ) {
221- $ admin_notices_filter = is_network_admin () ? 'network_admin_notices ' : ( is_user_admin () ? 'user_admin_notices ' : 'admin_notices ' );
222- add_action ( $ admin_notices_filter , array ( __CLASS__ , 'untested_notice ' ) );
225+ global $ wp_version ;
226+ $ admin_notices = array ( array ( 'warning ' , sprintf (
227+ /* translators: %1$s: lowest WordPress version tested; %2$s: highest WordPress version tested; %3$s: user's current WordPress version. */
228+ __ ( '<strong>Warning: untested!</strong> The plugin "UNFC Normalize" has only been tested on WordPress Versions %1$s to %2$s. You have WordPress Version %3$s. ' , 'unfc-normalize ' ),
229+ UNFC_WP_AT_LEAST_VERSION , UNFC_WP_UP_TO_VERSION , $ wp_version
230+ ) ) );
231+ self ::add_admin_notices ( $ admin_notices );
223232 }
224233 }
225234 }
@@ -236,6 +245,54 @@ function is_blog_utf8() {
236245 */
237246 function admin_init () {
238247 $ this ->check_version ();
248+ $ admin_notices_action = is_network_admin () ? 'network_admin_notices ' : ( is_user_admin () ? 'user_admin_notices ' : 'admin_notices ' );
249+ add_action ( $ admin_notices_action , array ( __CLASS__ , 'admin_notices ' ) );
250+ }
251+
252+ /**
253+ * Called on 'network_admin_notices', 'user_admin_notices' or 'admin_notices' action.
254+ * Output any messages.
255+ */
256+ static function admin_notices () {
257+
258+ $ admin_notices = get_transient ( 'unfc_admin_notices ' );
259+ if ( false !== $ admin_notices ) {
260+ delete_transient ( 'unfc_admin_notices ' );
261+ }
262+ if ( $ admin_notices ) {
263+
264+ foreach ( $ admin_notices as $ admin_notice ) {
265+ list ( $ type , $ notice ) = $ admin_notice ;
266+ if ( 'error ' === $ type ) {
267+ ?>
268+ <div class="notice error is-dismissible">
269+ <p><?php echo $ notice ; ?> </p>
270+ </div>
271+ <?php
272+ } elseif ( 'updated ' === $ type ) {
273+ ?>
274+ <div class="notice updated is-dismissible">
275+ <p><?php echo $ notice ; ?> </p>
276+ </div>
277+ <?php
278+ } else {
279+ ?>
280+ <div class="notice notice-<?php echo $ type ; ?> is-dismissible">
281+ <p><?php echo $ notice ; ?> </p>
282+ </div>
283+ <?php
284+ }
285+ }
286+ }
287+ }
288+
289+ /**
290+ * Add any admin notices as transient.
291+ */
292+ static function add_admin_notices ( $ admin_notices ) {
293+ if ( $ admin_notices ) {
294+ set_transient ( 'unfc_admin_notices ' , $ admin_notices , 5 * MINUTE_IN_SECONDS );
295+ }
239296 }
240297
241298 /**
@@ -246,8 +303,8 @@ function check_version() {
246303 if ( ! self ::compatible_version () ) {
247304 if ( is_plugin_active ( self ::$ plugin_basename ) ) {
248305 deactivate_plugins ( self ::$ plugin_basename );
249- $ admin_notices_filter = is_network_admin () ? 'network_admin_notices ' : ( is_user_admin () ? 'user_admin_notices ' : 'admin_notices ' );
250- add_action ( $ admin_notices_filter , array ( $ this , 'disabled_notice ' ) );
306+ $ admin_notices_action = is_network_admin () ? 'network_admin_notices ' : ( is_user_admin () ? 'user_admin_notices ' : 'admin_notices ' );
307+ add_action ( $ admin_notices_action , array ( $ this , 'disabled_notice ' ) );
251308 if ( isset ( $ _GET ['activate ' ] ) ) {
252309 unset( $ _GET ['activate ' ] );
253310 }
@@ -261,7 +318,7 @@ function check_version() {
261318 * Called on 'network_admin_notices', 'user_admin_notices' or 'admin_notices' action.
262319 */
263320 function disabled_notice () {
264- $ error_message = '<div id="message" class="updated is-dismissible"> ' ;
321+ $ error_message = '<div id="message" class="notice error is-dismissible"> ' ;
265322 $ error_message .= '<p><strong> ' . __ ( 'Plugin deactivated! ' , 'unfc-normalize ' ) . '</strong> ' ;
266323 $ error_message .= esc_html__ ( 'The plugin "UNFC Normalize" is not compatible with your system and has been deactivated. ' , 'unfc-normalize ' );
267324 $ error_message .= '</p></div> ' ;
@@ -277,30 +334,6 @@ static function compatible_version() {
277334 return ! self ::$ not_compat ; // For testing.
278335 }
279336
280- /**
281- * Called on 'network_admin_notices', 'user_admin_notices' or 'admin_notices' action.
282- */
283- static function untested_notice () {
284- global $ wp_version ;
285- $ untested_wp = ! self ::tested_wp_version ();
286- ?>
287- <div class="notice notice-warning is-dismissible">
288- <p>
289- <strong><?php _e ( 'Warning: untested! ' , 'unfc-normalize ' ); ?> </strong>
290- </p>
291- <?php if ( $ untested_wp ) { ?>
292- <p>
293- <?php printf (
294- /* translators: %1$s: lowest WordPress version tested; %2$s: highest WordPress version tested; %3$s: user's current WordPress version. */
295- __ ( 'The plugin "UNFC Normalize" has only been tested on WordPress Versions %1$s to %2$s. You have WordPress Version %3$s. ' , 'unfc-normalize ' ),
296- UNFC_WP_AT_LEAST_VERSION , UNFC_WP_UP_TO_VERSION , $ wp_version
297- ); ?>
298- </p>
299- <?php } ?>
300- </div>
301- <?php
302- }
303-
304337 /**
305338 * Whether tested with this version of WP
306339 */
@@ -981,7 +1014,7 @@ function load_db_check() {
9811014 $ redirect = add_query_arg ( array ( 'unfc_trans ' => $ transient_key ), $ redirect );
9821015 }
9831016
984- $ this -> db_check_add_admin_notices ( $ admin_notices );
1017+ self :: add_admin_notices ( $ admin_notices );
9851018
9861019 wp_redirect ( esc_url_raw ( $ redirect ) );
9871020 if ( defined ( 'UNFC_TESTING ' ) && UNFC_TESTING ) { // Allow for testing.
@@ -1005,7 +1038,7 @@ function load_db_check() {
10051038
10061039 $ this ->db_check_normalize_all ( $ admin_notices );
10071040
1008- $ this -> db_check_add_admin_notices ( $ admin_notices );
1041+ self :: add_admin_notices ( $ admin_notices );
10091042
10101043 wp_redirect ( esc_url_raw ( $ redirect ) );
10111044 if ( defined ( 'UNFC_TESTING ' ) && UNFC_TESTING ) { // Allow for testing.
@@ -1029,7 +1062,7 @@ function load_db_check() {
10291062 $ redirect = add_query_arg ( array ( 'unfc_trans ' => $ transient_key ), $ redirect );
10301063 }
10311064
1032- $ this -> db_check_add_admin_notices ( $ admin_notices );
1065+ self :: add_admin_notices ( $ admin_notices );
10331066
10341067 wp_redirect ( esc_url_raw ( $ redirect ) );
10351068 if ( defined ( 'UNFC_TESTING ' ) && UNFC_TESTING ) { // Allow for testing.
@@ -1067,7 +1100,7 @@ function load_db_check() {
10671100 }
10681101 }
10691102
1070- $ this -> db_check_add_admin_notices ( $ admin_notices );
1103+ self :: add_admin_notices ( $ admin_notices );
10711104
10721105 wp_redirect ( esc_url_raw ( $ redirect ) );
10731106 if ( defined ( 'UNFC_TESTING ' ) && UNFC_TESTING ) { // Allow for testing.
@@ -1101,7 +1134,7 @@ function load_db_check() {
11011134 }
11021135 }
11031136
1104- $ this -> db_check_add_admin_notices ( $ admin_notices );
1137+ self :: add_admin_notices ( $ admin_notices );
11051138
11061139 wp_redirect ( esc_url_raw ( $ redirect ) );
11071140 if ( defined ( 'UNFC_TESTING ' ) && UNFC_TESTING ) { // Allow for testing.
@@ -1125,7 +1158,7 @@ function load_db_check() {
11251158 $ redirect = add_query_arg ( array ( 'unfc_trans ' => $ transient_key ), $ redirect );
11261159 }
11271160
1128- $ this -> db_check_add_admin_notices ( $ admin_notices );
1161+ self :: add_admin_notices ( $ admin_notices );
11291162
11301163 wp_redirect ( esc_url_raw ( $ redirect ) );
11311164 if ( defined ( 'UNFC_TESTING ' ) && UNFC_TESTING ) { // Allow for testing.
@@ -1144,12 +1177,9 @@ function load_db_check() {
11441177 } else {
11451178 // If have invalid transient...
11461179 if ( $ this ->db_check_transient ( false /*start_with*/ , false /*dont_get*/ , true /*dont_set*/ ) ) {
1147- $ this -> db_check_add_admin_notices ( array ( array ( 'error ' , $ this ->db_check_error_msg ( UNFC_DB_CHECK_TRANS_ERROR ) ) ) );
1180+ self :: add_admin_notices ( array ( array ( 'error ' , $ this ->db_check_error_msg ( UNFC_DB_CHECK_TRANS_ERROR ) ) ) );
11481181 }
11491182 }
1150-
1151- $ admin_notices_filter = is_network_admin () ? 'network_admin_notices ' : ( is_user_admin () ? 'user_admin_notices ' : 'admin_notices ' );
1152- add_action ( $ admin_notices_filter , array ( $ this , 'admin_notices ' ) );
11531183 }
11541184 }
11551185
@@ -1467,52 +1497,6 @@ function db_check_transient( $starts_with = false, $dont_get = false, $dont_set
14671497 return false ;
14681498 }
14691499
1470- /**
1471- * Called on 'network_admin_notices', 'user_admin_notices' or 'admin_notices' action.
1472- * Output any messages.
1473- */
1474- function admin_notices () {
1475-
1476- $ admin_notices = get_transient ( 'unfc_admin_notices ' );
1477- if ( false !== $ admin_notices ) {
1478- delete_transient ( 'unfc_admin_notices ' );
1479- }
1480- if ( $ admin_notices ) {
1481-
1482- foreach ( $ admin_notices as $ admin_notice ) {
1483- list ( $ type , $ notice ) = $ admin_notice ;
1484- if ( 'error ' === $ type ) {
1485- ?>
1486- <div class="notice error is-dismissible">
1487- <p><?php echo $ notice ; ?> </p>
1488- </div>
1489- <?php
1490- } elseif ( 'updated ' === $ type ) {
1491- ?>
1492- <div class="notice updated is-dismissible">
1493- <p><?php echo $ notice ; ?> </p>
1494- </div>
1495- <?php
1496- } else {
1497- ?>
1498- <div class="notice notice-<?php echo $ type ; ?> is-dismissible">
1499- <p><?php echo $ notice ; ?> </p>
1500- </div>
1501- <?php
1502- }
1503- }
1504- }
1505- }
1506-
1507- /**
1508- * Add any admin notices as transient.
1509- */
1510- function db_check_add_admin_notices ( $ admin_notices ) {
1511- if ( $ admin_notices ) {
1512- set_transient ( 'unfc_admin_notices ' , $ admin_notices , 5 * MINUTE_IN_SECONDS );
1513- }
1514- }
1515-
15161500 /**
15171501 * Return error message.
15181502 */
0 commit comments