[wp-trac] [WordPress Trac] #57791: Create function to output admin notices

WordPress Trac noreply at wordpress.org
Fri Jun 9 06:54:36 UTC 2023


#57791: Create function to output admin notices
-------------------------------------------------+-------------------------
 Reporter:  joedolson                            |       Owner:  (none)
     Type:  enhancement                          |      Status:  new
 Priority:  normal                               |   Milestone:  Awaiting
                                                 |  Review
Component:  Administration                       |     Version:
 Severity:  normal                               |  Resolution:
 Keywords:  has-patch has-unit-tests dev-        |     Focuses:
  feedback                                       |  administration
-------------------------------------------------+-------------------------

Comment (by costdev):

 Since the new action is `wp_admin_notice`, it makes sense it only appears
 in that function, and a `wp_get_admin_notice()` function would contain
 filters to modify the `$args` and `$markup` for the notice.

 @joedolson @sabernhardt With that in mind, what do you think of this?

 {{{#!php
 <?php

 function wp_admin_notice( $message, $args ) {
     do_action( 'wp_admin_notice', $message, $args );

     echo wp_get_admin_notice( $message, $args );
 }

 function wp_get_admin_notice( $message, $args ) {
     $defaults = array( '...' );
     $args     = wp_parse_args( $args, $defaults );
     $args     = apply_filters( 'wp_admin_notice_args', $args, $message );

     // Create $markup.

     return apply_filters( 'wp_admin_notice_markup', $markup, $message,
 $args );
 }
 }}}

 In this case, `settings_errors()` would still use `wp_admin_notice()` so
 that the `wp_admin_notice` action is triggered for each notice.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/57791#comment:14>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list