Skip to content

Commit a6a0b3a

Browse files
committed
Merge pull request #509 from TGMPA/feature/issue-478-495-notice-class
Fix admin notice class.
2 parents a91014c + 5b057f5 commit a6a0b3a

File tree

2 files changed

+26
-7
lines changed

2 files changed

+26
-7
lines changed

class-tgm-plugin-activation.php

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1169,12 +1169,7 @@ public function notices() {
11691169
}
11701170

11711171
// Register the nag messages and prepare them to be processed.
1172-
if ( ! empty( $this->strings['nag_type'] ) ) {
1173-
add_settings_error( 'tgmpa', 'tgmpa', $rendered, sanitize_html_class( strtolower( $this->strings['nag_type'] ) ) );
1174-
} else {
1175-
$nag_class = version_compare( $this->wp_version, '3.8', '<' ) ? 'updated' : 'update-nag';
1176-
add_settings_error( 'tgmpa', 'tgmpa', $rendered, $nag_class );
1177-
}
1172+
add_settings_error( 'tgmpa', 'tgmpa', $rendered, $this->get_admin_notice_class() );
11781173
}
11791174

11801175
// Admin options pages already output settings_errors, so this is to avoid duplication.
@@ -1183,6 +1178,30 @@ public function notices() {
11831178
}
11841179
}
11851180

1181+
/**
1182+
* Get admin notice class.
1183+
*
1184+
* Work around all the changes to the various admin notice classes between WP 4.4 and 3.7
1185+
* (lowest supported version by TGMPA).
1186+
*
1187+
* @since 2.x.x
1188+
*
1189+
* @return string
1190+
*/
1191+
protected function get_admin_notice_class() {
1192+
if ( ! empty( $this->strings['nag_type'] ) ) {
1193+
return sanitize_html_class( strtolower( $this->strings['nag_type'] ) );
1194+
} else {
1195+
if ( version_compare( $this->wp_version, '4.2', '>=' ) ) {
1196+
return 'notice-warning';
1197+
} elseif ( version_compare( $this->wp_version, '4.1', '>=' ) ) {
1198+
return 'notice';
1199+
} else {
1200+
return 'updated';
1201+
}
1202+
}
1203+
}
1204+
11861205
/**
11871206
* Display settings errors and remove those which have been displayed to avoid duplicate messages showing
11881207
*

example.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ function my_theme_register_required_plugins() {
191191
'complete' => __( 'All plugins installed and activated successfully. %1$s', 'theme-slug' ), // %s = dashboard link.
192192
'contact_admin' => __( 'Please contact the administrator of this site for help.', 'tgmpa' ),
193193
194-
'nag_type' => 'updated', // Determines admin notice type - can only be 'updated', 'update-nag' or 'error'.
194+
'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.
195195
),
196196
*/
197197
);

0 commit comments

Comments
 (0)