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

WordPress Trac noreply at wordpress.org
Fri Feb 24 07:29:03 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  |     Focuses:  administration
--------------------------------------+------------------------------

Comment (by costdev):

 @joedolson This makes sense to me.

 Implementing [https://github.com/WordPress/wordpress-develop/pull/4119 PR
 4119]'s function in `settings_errors()` would replace:
 {{{#!php
 <?php

 foreach ( $settings_errors as $key => $details ) {
         if ( 'updated' === $details['type'] ) {
                 $details['type'] = 'success';
         }

         if ( in_array( $details['type'], array( 'error', 'success',
 'warning', 'info' ), true ) ) {
                 $details['type'] = 'notice-' . $details['type'];
         }

         $css_id    = sprintf(
                 'setting-error-%s',
                 esc_attr( $details['code'] )
         );
         $css_class = sprintf(
                 'notice %s settings-error is-dismissible',
                 esc_attr( $details['type'] )
         );

         $output .= "<div id='$css_id' class='$css_class'> \n";
         $output .= "<p><strong>{$details['message']}</strong></p>";
         $output .= "</div> \n";
 }

 echo $output;
 }}}

 with:
 {{{#!php
 foreach ( $settings_errors as $key => $details ) {
         wp_admin_notice(
                 "<strong>{$details['message']}</strong>",
                 array(
                         'type'               => $details['type'],
                         'dismissible'        => true,
                         'id'                 => 'setting-error-' .
 esc_attr( $details['code'] ),
                         'additional_classes' => array( 'settings-error' ),
                 )
         );
 }
 }}}

 We could then take the conditions for `'updated' === $details['type']` and
 the `in_array()` check into `wp_admin_notice()` for consistency throughout
 Core.

 If that works for you, I can:
 - Add the two conditions to `wp_admin_notice()`.
 - (local-only) Implement the above in `settings_errors()` to check if
 there's any BC breaks/test failures.
 - Adjust `wp_admin_notice()`, or existing tests, accordingly if any BC
 breaks are found.

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


More information about the wp-trac mailing list