Make WordPress Core

Changeset 56409

Timestamp:
08/17/2023 09:01:17 PM (12 months ago)
Author:
joedolson
Message:

Administration: Apply admin notice functions in multisite.

Use wp_get_admin_notice and wp_admin_notice to handle multisite settings notices.

Props costdev.
See #57791.

Location:
trunk/src/wp-admin
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/class-wp-ms-themes-list-table.php

    r55971 r56409  
    860860        echo apply_filters( 'theme_auto_update_setting_html', $html, $stylesheet, $theme );
    861861
    862         echo '<div class="notice notice-error notice-alt inline hidden"><p></p></div>';
     862        wp_admin_notice(
     863            '',
     864            array(
     865                'type'               => 'error',
     866                'additional_classes' => array( 'notice-alt', 'inline', 'hidden' ),
     867            )
     868        );
    863869    }
    864870
  • trunk/src/wp-admin/includes/network.php

    r55703 r56409  
    126126    $active_plugins = get_option( 'active_plugins' );
    127127    if ( ! empty( $active_plugins ) ) {
    128         echo '<div class="notice notice-warning"><p><strong>' . __( 'Warning:' ) . '</strong> ' . sprintf(
    129             /* translators: %s: URL to Plugins screen. */
    130             __( 'Please <a href="%s">deactivate your plugins</a> before enabling the Network feature.' ),
    131             admin_url( 'plugins.php?plugin_status=active' )
    132         ) . '</p></div>';
     128        wp_admin_notice(
     129            '<strong>' . __( 'Warning:' ) . '</strong> ' . sprintf(
     130                /* translators: %s: URL to Plugins screen. */
     131                __( 'Please <a href="%s">deactivate your plugins</a> before enabling the Network feature.' ),
     132                admin_url( 'plugins.php?plugin_status=active' )
     133            ),
     134            array( 'type' => 'warning' )
     135        );
    133136        echo '<p>' . __( 'Once the network is created, you may reactivate your plugins.' ) . '</p>';
    134137        echo '</div>';
     
    439442        <h3><?php esc_html_e( 'Enabling the Network' ); ?></h3>
    440443        <p><?php _e( 'Complete the following steps to enable the features for creating a network of sites.' ); ?></p>
    441         <div class="notice notice-warning inline"><p>
    442444        <?php
     445
     446
     447
     448
     449
     450
    443451        if ( file_exists( $home_path . '.htaccess' ) ) {
    444             echo '<strong>' . __( 'Caution:' ) . '</strong> ';
    445             printf(
     452            $notice_message .= sprintf(
    446453                /* translators: 1: wp-config.php, 2: .htaccess */
    447454                __( 'You should back up your existing %1$s and %2$s files.' ),
     
    450457            );
    451458        } elseif ( file_exists( $home_path . 'web.config' ) ) {
    452             echo '<strong>' . __( 'Caution:' ) . '</strong> ';
    453             printf(
     459            $notice_message .= sprintf(
    454460                /* translators: 1: wp-config.php, 2: web.config */
    455461                __( 'You should back up your existing %1$s and %2$s files.' ),
     
    458464            );
    459465        } else {
    460             echo '<strong>' . __( 'Caution:' ) . '</strong> ';
    461             printf(
     466            $notice_message .= sprintf(
    462467                /* translators: %s: wp-config.php */
    463468                __( 'You should back up your existing %s file.' ),
     
    465470            );
    466471        }
    467         ?>
    468         </p></div>
    469         <?php
     472
     473        wp_admin_notice( $notice_message, $notice_args );
    470474    }
    471475    ?>
  • trunk/src/wp-admin/my-sites.php

    r55917 r56409  
    5656require_once ABSPATH . 'wp-admin/admin-header.php';
    5757
    58 if ( $updated ) { ?>
    59     <div id="message" class="notice notice-success is-dismissible"><p><strong><?php _e( 'Settings saved.' ); ?></strong></p></div>
    60 <?php } ?>
     58if ( $updated ) {
     59    wp_admin_notice(
     60        '<strong>' . __( 'Settings saved.' ) . '</strong>',
     61        array(
     62            'type'        => 'success',
     63            'dismissible' => true,
     64            'id'          => 'message',
     65        )
     66    );
     67}
     68?>
    6169
    6270<div class="wrap">
     
    7583
    7684if ( empty( $blogs ) ) :
     85
     86
     87
     88
     89
     90
     91
    7792    ?>
    78     <div class="notice notice-error is-dismissible"><p><strong><?php _e( 'You must be a member of at least one site to use this page.' ); ?></strong></p></div>
    7993    <?php
    8094else :
  • trunk/src/wp-admin/network/settings.php

    r55877 r56409  
    139139
    140140if ( isset( $_GET['updated'] ) ) {
    141     ?>
    142     <div id="message" class="notice notice-success is-dismissible"><p><?php _e( 'Settings saved.' ); ?></p></div>
    143     <?php
     141    wp_admin_notice(
     142        __( 'Settings saved.' ),
     143        array(
     144            'type'        => 'success',
     145            'dismissible' => true,
     146            'id'          => 'message',
     147        )
     148    );
    144149}
    145150?>
     
    168173                    $new_admin_email = get_site_option( 'new_admin_email' );
    169174                    if ( $new_admin_email && get_site_option( 'admin_email' ) !== $new_admin_email ) :
    170                         ?>
    171                         <div class="notice notice-warning is-dismissible inline">
    172                         <p>
    173                         <?php
    174                             printf(
    175                                 /* translators: %s: New network admin email. */
    176                                 __( 'There is a pending change of the network admin email to %s.' ),
    177                                 '<code>' . esc_html( $new_admin_email ) . '</code>'
    178                             );
    179                             printf(
    180                                 ' <a href="%1$s">%2$s</a>',
    181                                 esc_url( wp_nonce_url( network_admin_url( 'settings.php?dismiss=new_network_admin_email' ), 'dismiss_new_network_admin_email' ) ),
    182                                 __( 'Cancel' )
    183                             );
    184                         ?>
    185                         </p>
    186                         </div>
    187                     <?php endif; ?>
     175                        $notice_message = sprintf(
     176                            /* translators: %s: New network admin email. */
     177                            __( 'There is a pending change of the network admin email to %s.' ),
     178                            '<code>' . esc_html( $new_admin_email ) . '</code>'
     179                        );
     180
     181                        $notice_message .= sprintf(
     182                            ' <a href="%1$s">%2$s</a>',
     183                            esc_url( wp_nonce_url( network_admin_url( 'settings.php?dismiss=new_network_admin_email' ), 'dismiss_new_network_admin_email' ) ),
     184                            __( 'Cancel' )
     185                        );
     186
     187                        wp_admin_notice(
     188                            $notice_message,
     189                            array(
     190                                'type'               => 'warning',
     191                                'dismissible'        => true,
     192                                'additional_classes' => array( 'inline' ),
     193                            )
     194                        );
     195                    endif;
     196                    ?>
    188197                </td>
    189198            </tr>
  • trunk/src/wp-admin/network/site-info.php

    r55418 r56409  
    147147
    148148if ( ! empty( $messages ) ) {
     149
     150
     151
     152
     153
     154
    149155    foreach ( $messages as $msg ) {
    150         echo '<div id="message" class="notice notice-success is-dismissible"><p>' . $msg . '</p></div>';
     156        ;
    151157    }
    152158}
  • trunk/src/wp-admin/network/site-new.php

    r55894 r56409  
    193193<?php
    194194if ( ! empty( $messages ) ) {
     195
     196
     197
     198
     199
     200
    195201    foreach ( $messages as $msg ) {
    196         echo '<div id="message" class="notice notice-success is-dismissible"><p>' . $msg . '</p></div>';
     202        ;
    197203    }
    198204}
  • trunk/src/wp-admin/network/site-settings.php

    r55988 r56409  
    105105
    106106if ( ! empty( $messages ) ) {
     107
     108
     109
     110
     111
     112
    107113    foreach ( $messages as $msg ) {
    108         echo '<div id="message" class="notice notice-success is-dismissible"><p>' . $msg . '</p></div>';
     114        ;
    109115    }
    110116}
  • trunk/src/wp-admin/network/site-themes.php

    r55618 r56409  
    197197        $message = _n( '%s theme enabled.', '%s themes enabled.', $enabled );
    198198    }
    199     echo '<div id="message" class="notice notice-success is-dismissible"><p>' . sprintf( $message, number_format_i18n( $enabled ) ) . '</p></div>';
     199
     200    wp_admin_notice(
     201        sprintf( $message, number_format_i18n( $enabled ) ),
     202        array(
     203            'type'        => 'success',
     204            'dismissible' => true,
     205            'id'          => 'message',
     206        )
     207    );
    200208} elseif ( isset( $_GET['disabled'] ) ) {
    201209    $disabled = absint( $_GET['disabled'] );
     
    206214        $message = _n( '%s theme disabled.', '%s themes disabled.', $disabled );
    207215    }
    208     echo '<div id="message" class="notice notice-success is-dismissible"><p>' . sprintf( $message, number_format_i18n( $disabled ) ) . '</p></div>';
     216
     217    wp_admin_notice(
     218        sprintf( $message, number_format_i18n( $disabled ) ),
     219        array(
     220            'type'        => 'success',
     221            'dismissible' => true,
     222            'id'          => 'message',
     223        )
     224    );
    209225} elseif ( isset( $_GET['error'] ) && 'none' === $_GET['error'] ) {
    210     echo '<div id="message" class="notice notice-error is-dismissible"><p>' . __( 'No theme selected.' ) . '</p></div>';
     226    wp_admin_notice(
     227        __( 'No theme selected.' ),
     228        array(
     229            'type'        => 'error',
     230            'dismissible' => true,
     231            'id'          => 'message',
     232        )
     233    );
    211234}
    212235?>
  • trunk/src/wp-admin/network/site-users.php

    r55618 r56409  
    235235
    236236if ( isset( $_GET['update'] ) ) :
     237
     238
     239
    237240    switch ( $_GET['update'] ) {
    238241        case 'adduser':
    239             echo '<div id="message" class="notice notice-success is-dismissible"><p>' . __( 'User added.' ) . '</p></div>';
     242            $type    = 'success';
     243            $message = __( 'User added.' );
    240244            break;
    241245        case 'err_add_member':
    242             echo '<div id="message" class="notice notice-error  is-dismissible"><p>' . __( 'User is already a member of this site.' ) . '</p></div>';
     246            ;
    243247            break;
    244248        case 'err_add_fail':
    245             echo '<div id="message" class="notice notice-error is-dismissible"><p>' . __( 'User could not be added to this site.' ) . '</p></div>';
     249            ;
    246250            break;
    247251        case 'err_add_notfound':
    248             echo '<div id="message" class="notice notice-error is-dismissible"><p>' . __( 'Enter the username of an existing user.' ) . '</p></div>';
     252            ;
    249253            break;
    250254        case 'promote':
    251             echo '<div id="message" class="notice notice-success is-dismissible"><p>' . __( 'Changed roles.' ) . '</p></div>';
     255            $type    = 'success';
     256            $message = __( 'Changed roles.' );
    252257            break;
    253258        case 'err_promote':
    254             echo '<div id="message" class="notice notice-error is-dismissible"><p>' . __( 'Select a user to change role.' ) . '</p></div>';
     259            ;
    255260            break;
    256261        case 'remove':
    257             echo '<div id="message" class="notice notice-success is-dismissible"><p>' . __( 'User removed from this site.' ) . '</p></div>';
     262            $type    = 'success';
     263            $message = __( 'User removed from this site.' );
    258264            break;
    259265        case 'err_remove':
    260             echo '<div id="message" class="notice notice-error is-dismissible"><p>' . __( 'Select a user to remove.' ) . '</p></div>';
     266            ;
    261267            break;
    262268        case 'newuser':
    263             echo '<div id="message" class="notice notice-success is-dismissible"><p>' . __( 'User created.' ) . '</p></div>';
     269            $type    = 'success';
     270            $message = __( 'User created.' );
    264271            break;
    265272        case 'err_new':
    266             echo '<div id="message" class="notice notice-error is-dismissible"><p>' . __( 'Enter the username and email.' ) . '</p></div>';
     273            ;
    267274            break;
    268275        case 'err_new_dup':
    269             echo '<div id="message" class="notice notice-error is-dismissible"><p>' . __( 'Duplicated username or email address.' ) . '</p></div>';
     276            ;
    270277            break;
    271278    }
     279
     280
     281
     282
     283
     284
     285
     286
     287
    272288endif;
    273289?>
  • trunk/src/wp-admin/network/sites.php

    r55876 r56409  
    359359
    360360    if ( ! empty( $msg ) ) {
    361         $msg = '<div id="message" class="notice notice-success is-dismissible"><p>' . $msg . '</p></div>';
     361        $msg = wp_get_admin_notice(
     362            $msg,
     363            array(
     364                'type'        => 'success',
     365                'dismissible' => true,
     366                'id'          => 'message',
     367            )
     368        );
    362369    }
    363370}
  • trunk/src/wp-admin/network/themes.php

    r55988 r56409  
    368368
    369369<?php
     370
     371
     372
    370373if ( isset( $_GET['enabled'] ) ) {
    371374    $enabled = absint( $_GET['enabled'] );
     
    373376        $message = __( 'Theme enabled.' );
    374377    } else {
    375         /* translators: %s: Number of themes. */
    376         $message = _n( '%s theme enabled.', '%s themes enabled.', $enabled );
    377     }
    378     echo '<div id="message" class="notice notice-success is-dismissible"><p>' . sprintf( $message, number_format_i18n( $enabled ) ) . '</p></div>';
     378        $message = sprintf(
     379            /* translators: %s: Number of themes. */
     380            _n( '%s theme enabled.', '%s themes enabled.', $enabled ),
     381            number_format_i18n( $enabled )
     382        );
     383    }
    379384} elseif ( isset( $_GET['disabled'] ) ) {
    380385    $disabled = absint( $_GET['disabled'] );
     
    382387        $message = __( 'Theme disabled.' );
    383388    } else {
    384         /* translators: %s: Number of themes. */
    385         $message = _n( '%s theme disabled.', '%s themes disabled.', $disabled );
    386     }
    387     echo '<div id="message" class="notice notice-success is-dismissible"><p>' . sprintf( $message, number_format_i18n( $disabled ) ) . '</p></div>';
     389        $message = sprintf(
     390            /* translators: %s: Number of themes. */
     391            _n( '%s theme disabled.', '%s themes disabled.', $disabled ),
     392            number_format_i18n( $disabled )
     393        );
     394    }
    388395} elseif ( isset( $_GET['deleted'] ) ) {
    389396    $deleted = absint( $_GET['deleted'] );
     
    391398        $message = __( 'Theme deleted.' );
    392399    } else {
    393         /* translators: %s: Number of themes. */
    394         $message = _n( '%s theme deleted.', '%s themes deleted.', $deleted );
    395     }
    396     echo '<div id="message" class="notice notice-success is-dismissible"><p>' . sprintf( $message, number_format_i18n( $deleted ) ) . '</p></div>';
     400        $message = sprintf(
     401            /* translators: %s: Number of themes. */
     402            _n( '%s theme deleted.', '%s themes deleted.', $deleted ),
     403            number_format_i18n( $deleted )
     404        );
     405    }
    397406} elseif ( isset( $_GET['enabled-auto-update'] ) ) {
    398407    $enabled = absint( $_GET['enabled-auto-update'] );
     
    400409        $message = __( 'Theme will be auto-updated.' );
    401410    } else {
    402         /* translators: %s: Number of themes. */
    403         $message = _n( '%s theme will be auto-updated.', '%s themes will be auto-updated.', $enabled );
    404     }
    405     echo '<div id="message" class="notice notice-success is-dismissible"><p>' . sprintf( $message, number_format_i18n( $enabled ) ) . '</p></div>';
     411        $message = sprintf(
     412            /* translators: %s: Number of themes. */
     413            _n( '%s theme will be auto-updated.', '%s themes will be auto-updated.', $enabled ),
     414            number_format_i18n( $enabled )
     415        );
     416    }
    406417} elseif ( isset( $_GET['disabled-auto-update'] ) ) {
    407418    $disabled = absint( $_GET['disabled-auto-update'] );
     
    409420        $message = __( 'Theme will no longer be auto-updated.' );
    410421    } else {
    411         /* translators: %s: Number of themes. */
    412         $message = _n( '%s theme will no longer be auto-updated.', '%s themes will no longer be auto-updated.', $disabled );
    413     }
    414     echo '<div id="message" class="notice notice-success is-dismissible"><p>' . sprintf( $message, number_format_i18n( $disabled ) ) . '</p></div>';
     422        $message = sprintf(
     423            /* translators: %s: Number of themes. */
     424            _n( '%s theme will no longer be auto-updated.', '%s themes will no longer be auto-updated.', $disabled ),
     425            number_format_i18n( $disabled )
     426        );
     427    }
    415428} elseif ( isset( $_GET['error'] ) && 'none' === $_GET['error'] ) {
    416     echo '<div id="message" class="notice notice-error is-dismissible"><p>' . __( 'No theme selected.' ) . '</p></div>';
     429    $message = __( 'No theme selected.' );
     430    $type    = 'error';
    417431} elseif ( isset( $_GET['error'] ) && 'main' === $_GET['error'] ) {
    418     echo '<div id="message" class="notice notice-error is-dismissible"><p>' . __( 'You cannot delete a theme while it is active on the main site.' ) . '</p></div>';
    419 }
    420 
     432    $message = __( 'You cannot delete a theme while it is active on the main site.' );
     433    $type    = 'error';
     434}
     435
     436if ( '' !== $message ) {
     437    wp_admin_notice(
     438        $message,
     439        array(
     440            'type'        => $type,
     441            'dismissible' => true,
     442            'id'          => 'message',
     443        )
     444    );
     445}
    421446?>
    422447
  • trunk/src/wp-admin/network/user-new.php

    r55618 r56409  
    108108<?php
    109109if ( '' !== $message ) {
    110     echo '<div id="message" class="notice notice-success is-dismissible"><p>' . $message . '</p></div>';
     110    wp_admin_notice(
     111        $message,
     112        array(
     113            'type'        => 'success',
     114            'dismissible' => true,
     115            'id'          => 'message',
     116        )
     117    );
    111118}
    112119
    113120if ( isset( $add_user_errors ) && is_wp_error( $add_user_errors ) ) {
    114     ?>
    115     <div id="message" class="notice notice-error is-dismissible">
    116         <?php
    117         foreach ( $add_user_errors->get_error_messages() as $error ) {
    118             echo "<p>$error</p>";
    119         }
    120         ?>
    121     </div>
    122 <?php } ?>
     121    $error_messages = '';
     122    foreach ( $add_user_errors->get_error_messages() as $error ) {
     123        $error_messages .= "<p>$error</p>";
     124    }
     125
     126    wp_admin_notice(
     127        $error_messages,
     128        array(
     129            'type'           => 'error',
     130            'dismissible'    => true,
     131            'id'             => 'message',
     132            'paragraph_wrap' => false,
     133        )
     134    );
     135}
     136?>
    123137    <form action="<?php echo esc_url( network_admin_url( 'user-new.php?action=add-user' ) ); ?>" id="adduser" method="post" novalidate="novalidate">
    124138        <p><?php echo wp_required_field_message(); ?></p>
  • trunk/src/wp-admin/network/users.php

    r55877 r56409  
    255255
    256256if ( isset( $_REQUEST['updated'] ) && 'true' === $_REQUEST['updated'] && ! empty( $_REQUEST['action'] ) ) {
    257     ?>
    258     <div id="message" class="notice notice-success is-dismissible"><p>
    259         <?php
    260         switch ( $_REQUEST['action'] ) {
    261             case 'delete':
    262                 _e( 'User deleted.' );
    263                 break;
    264             case 'all_spam':
    265                 _e( 'Users marked as spam.' );
    266                 break;
    267             case 'all_notspam':
    268                 _e( 'Users removed from spam.' );
    269                 break;
    270             case 'all_delete':
    271                 _e( 'Users deleted.' );
    272                 break;
    273             case 'add':
    274                 _e( 'User added.' );
    275                 break;
    276         }
    277         ?>
    278     </p></div>
    279     <?php
     257    $message = '';
     258    switch ( $_REQUEST['action'] ) {
     259        case 'delete':
     260            $message = __( 'User deleted.' );
     261            break;
     262        case 'all_spam':
     263            $message = __( 'Users marked as spam.' );
     264            break;
     265        case 'all_notspam':
     266            $message = __( 'Users removed from spam.' );
     267            break;
     268        case 'all_delete':
     269            $message = __( 'Users deleted.' );
     270            break;
     271        case 'add':
     272            $message = __( 'User added.' );
     273            break;
     274    }
     275
     276    wp_admin_notice(
     277        $message,
     278        array(
     279            'type'        => 'success',
     280            'dismissible' => true,
     281            'id'          => 'message',
     282        )
     283    );
    280284}
    281285?>
Note: See TracChangeset for help on using the changeset viewer.