diff --git a/class-tgm-plugin-activation.php b/class-tgm-plugin-activation.php index 66b4c779..0f90d143 100755 --- a/class-tgm-plugin-activation.php +++ b/class-tgm-plugin-activation.php @@ -1169,12 +1169,7 @@ public function notices() { } // Register the nag messages and prepare them to be processed. - if ( ! empty( $this->strings['nag_type'] ) ) { - add_settings_error( 'tgmpa', 'tgmpa', $rendered, sanitize_html_class( strtolower( $this->strings['nag_type'] ) ) ); - } else { - $nag_class = version_compare( $this->wp_version, '3.8', '<' ) ? 'updated' : 'update-nag'; - add_settings_error( 'tgmpa', 'tgmpa', $rendered, $nag_class ); - } + add_settings_error( 'tgmpa', 'tgmpa', $rendered, $this->get_admin_notice_class() ); } // Admin options pages already output settings_errors, so this is to avoid duplication. @@ -1183,6 +1178,30 @@ public function notices() { } } + /** + * Get admin notice class. + * + * Work around all the changes to the various admin notice classes between WP 4.4 and 3.7 + * (lowest supported version by TGMPA). + * + * @since 2.x.x + * + * @return string + */ + protected function get_admin_notice_class() { + if ( ! empty( $this->strings['nag_type'] ) ) { + return sanitize_html_class( strtolower( $this->strings['nag_type'] ) ); + } else { + if ( version_compare( $this->wp_version, '4.2', '>=' ) ) { + return 'notice-warning'; + } elseif ( version_compare( $this->wp_version, '4.1', '>=' ) ) { + return 'notice'; + } else { + return 'updated'; + } + } + } + /** * Display settings errors and remove those which have been displayed to avoid duplicate messages showing * diff --git a/example.php b/example.php index 064a6aab..39979f65 100755 --- a/example.php +++ b/example.php @@ -191,7 +191,7 @@ function my_theme_register_required_plugins() { 'complete' => __( 'All plugins installed and activated successfully. %1$s', 'theme-slug' ), // %s = dashboard link. 'contact_admin' => __( 'Please contact the administrator of this site for help.', 'tgmpa' ), - 'nag_type' => 'updated', // Determines admin notice type - can only be 'updated', 'update-nag' or 'error'. + 'nag_type' => '', // Determines admin notice type - can only be one of the typical WP notice classes, such as 'updated', 'update-nag', 'notice-warning', 'notice-info' or 'error'. Some of which may not work as expected in older WP versions. ), */ );