#40173 closed feature request (wontfix)
New function wp_admin_notice
Reported by: | sebastian.pisula | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | |
Component: | Administration | Keywords: | |
Focuses: | Cc: |
Description
I suggest add this function to core WP:
<?php /** * @param string|array $messages * @param string $status Status of message. Options: info, warning, success, error * @param bool $is_dismissible * @param bool $display * * @return string */ function wp_admin_notice( $messages, $status = 'error', $is_dismissible = false, $display = false ) { if ( ! in_array( $status, array( 'info', 'warning', 'success', 'error' ) ) ) { $status = 'error'; } $classes = array( 'notice', 'notice-' . $status ); if ( $is_dismissible ) { $classes[] = 'is-dismissible'; } if ( is_array( $messages ) ) { $messages = implode( "<br/>\n", $messages ); } $html = '<div class="' . implode( ' ', $classes ) . '"><p>' . $messages . '</p></div>'; if ( $display ) { echo $html; } return $html; }
For example we have this line: wp-admin/plugin-editor.php:182:
<div id="message" class="updated notice is-dismissible"><p><?php _e('File edited successfully.') ?></p></div>
We can use this function:
<?php wp_admin_notice( __('File edited successfully.'), 'success', true, true);
Authors of plugin will be can use this function in plugins.
Change History (3)
Note: See
TracTickets for help on using
tickets.
The existing API for admin notices shoulders all of that for you already:
We could definitely do a better job documenting that behavior however and surfacing these possibilities.
What do you think?