[wp-trac] [WordPress Trac] #40173: New function wp_admin_notice

WordPress Trac noreply at wordpress.org
Thu Mar 16 13:35:09 UTC 2017


#40173: New function wp_admin_notice
------------------------------+-----------------------------
 Reporter:  sebastian.pisula  |      Owner:
     Type:  feature request   |     Status:  new
 Priority:  normal            |  Milestone:  Awaiting Review
Component:  Administration    |    Version:
 Severity:  normal            |   Keywords:
  Focuses:                    |
------------------------------+-----------------------------
 I suggest add this function to core WP:

 {{{#!php
 <?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
 <?php
 wp_admin_notice( __('File edited successfully.'), 'success', true, true);
 }}}

 Authors of plugin will be can use this function in plugins.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/40173>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list