Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix admin notice class. #509

Merged
merged 1 commit into from
Jan 5, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 25 additions & 6 deletions class-tgm-plugin-activation.php
Original file line number Diff line number Diff line change
Expand Up @@ -1180,12 +1180,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.
Expand All @@ -1194,6 +1189,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
*
Expand Down
2 changes: 1 addition & 1 deletion example.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
),
*/
);
Expand Down