Make WordPress Core


Ignore:
Timestamp:
09/17/2023 03:21:07 PM (3 years ago)
Author:
costdev
Message:

Administration: Use wp_admin_notice() more in /wp-admin/includes/.

Adds further usages of wp_admin_notice() in /wp-admin/includes/ on .notice-error, .notice-warning, .error, and .updated.

Ongoing task to implement new function across core.

Follow-up to [56408], [56409], [56410], [56518], [56570], [56571], [56572], [56573], [56576], [56589], [56590], [56597].

Props joedolson, mukesh27, costdev.
See #57791.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/network.php

    r56410 r56599  
    114114
    115115    if ( defined( 'DO_NOT_UPGRADE_GLOBAL_TABLES' ) ) {
    116         echo '<div class="error"><p><strong>' . __( 'Error:' ) . '</strong> ' . sprintf(
     116        $cannot_define_constant_message  = '<strong>' . __( 'Error:' ) . '</strong> ';
     117        $cannot_define_constant_message .= sprintf(
    117118            /* translators: %s: DO_NOT_UPGRADE_GLOBAL_TABLES */
    118119            __( 'The constant %s cannot be defined when creating a network.' ),
    119120            '<code>DO_NOT_UPGRADE_GLOBAL_TABLES</code>'
    120         ) . '</p></div>';
     121        );
     122
     123        wp_admin_notice(
     124            $cannot_define_constant_message,
     125            array(
     126                'additional_classes' => array( 'error' ),
     127            )
     128        );
     129
    121130        echo '</div>';
    122131        require_once ABSPATH . 'wp-admin/admin-footer.php';
     
    143152    $has_ports = strstr( $hostname, ':' );
    144153    if ( ( false !== $has_ports && ! in_array( $has_ports, array( ':80', ':443' ), true ) ) ) {
    145         echo '<div class="error"><p><strong>' . __( 'Error:' ) . '</strong> ' . __( 'You cannot install a network of sites with your server address.' ) . '</p></div>';
     154        wp_admin_notice(
     155            '<strong>' . __( 'Error:' ) . '</strong> ' . __( 'You cannot install a network of sites with your server address.' ),
     156            array(
     157                'additional_classes' => array( 'error' ),
     158            )
     159        );
     160
    146161        echo '<p>' . sprintf(
    147162            /* translators: %s: Port number. */
     
    161176    $error_codes = array();
    162177    if ( is_wp_error( $errors ) ) {
    163         echo '<div class="error"><p><strong>' . __( 'Error: The network could not be created.' ) . '</strong></p>';
     178        $network_created_error_message = '<p><strong>' . __( 'Error: The network could not be created.' ) . '</strong></p>';
    164179        foreach ( $errors->get_error_messages() as $error ) {
    165             echo "<p>$error</p>";
    166         }
    167         echo '</div>';
     180            $network_created_error_message .= "<p>$error</p>";
     181        }
     182        wp_admin_notice(
     183            $network_created_error_message,
     184            array(
     185                'additional_classes' => array( 'error' ),
     186                'paragraph_wrap'     => false,
     187            )
     188        );
    168189        $error_codes = $errors->get_error_codes();
    169190    }
     
    196217        $got_mod_rewrite   = got_mod_rewrite();
    197218        if ( $got_mod_rewrite ) { // Dangerous assumptions.
    198             echo '<div class="updated inline"><p><strong>' . __( 'Note:' ) . '</strong> ';
    199             printf(
     219            $message_class = 'updated';
     220            $message       = '<p><strong>' . __( 'Warning:' ) . '</strong> ';
     221            $message      .= '<p>' . sprintf(
    200222                /* translators: %s: mod_rewrite */
    201223                __( 'Please make sure the Apache %s module is installed as it will be used at the end of this installation.' ),
    202224                '<code>mod_rewrite</code>'
    203             );
    204             echo '</p>';
     225            ) . '</p>';
    205226        } elseif ( $is_apache ) {
    206             echo '<div class="error inline"><p><strong>' . __( 'Warning:' ) . '</strong> ';
    207             printf(
     227            $message_class = 'error';
     228            $message       = '<p><strong>' . __( 'Warning:' ) . '</strong> ';
     229            $message      .= sprintf(
    208230                /* translators: %s: mod_rewrite */
    209231                __( 'It looks like the Apache %s module is not installed.' ),
    210232                '<code>mod_rewrite</code>'
    211             );
    212             echo '</p>';
     233            ) . '</p>';
    213234        }
    214235
    215236        if ( $got_mod_rewrite || $is_apache ) { // Protect against mod_rewrite mimicry (but ! Apache).
    216             echo '<p>';
    217             printf(
     237            $message .= '<p>' . sprintf(
    218238                /* translators: 1: mod_rewrite, 2: mod_rewrite documentation URL, 3: Google search for mod_rewrite. */
    219239                __( 'If %1$s is disabled, ask your administrator to enable that module, or look at the <a href="%2$s">Apache documentation</a> or <a href="%3$s">elsewhere</a> for help setting it up.' ),
     
    221241                'https://httpd.apache.org/docs/mod/mod_rewrite.html',
    222242                'https://www.google.com/search?q=apache+mod_rewrite'
     243            ) . '</p>';
     244
     245            wp_admin_notice(
     246                $message,
     247                array(
     248                    'additional_classes' => array( $message_class, 'inline' ),
     249                    'paragraph_wrap'     => false,
     250                )
    223251            );
    224             echo '</p></div>';
    225252        }
    226253    }
     
    264291
    265292    if ( WP_CONTENT_DIR !== ABSPATH . 'wp-content' && ( allow_subdirectory_install() || ! allow_subdomain_install() ) ) {
    266         echo '<div class="error inline"><p><strong>' . __( 'Warning:' ) . '</strong> ' . __( 'Subdirectory networks may not be fully compatible with custom wp-content directories.' ) . '</p></div>';
     293        $subdirectory_warning_message  = '<strong>' . __( 'Warning:' ) . '</strong> ';
     294        $subdirectory_warning_message .= __( 'Subdirectory networks may not be fully compatible with custom wp-content directories.' );
     295        wp_admin_notice(
     296            $subdirectory_warning_message,
     297            array(
     298                'additional_classes' => array( 'error', 'inline' ),
     299            )
     300        );
    267301    }
    268302
     
    410444    // Wildcard DNS message.
    411445    if ( is_wp_error( $errors ) ) {
    412         echo '<div class="error">' . $errors->get_error_message() . '</div>';
     446        wp_admin_notice(
     447            $errors->get_error_message(),
     448            array(
     449                'additional_classes' => array( 'error' ),
     450            )
     451        );
    413452    }
    414453
     
    427466        } else {
    428467            $subdomain_install = (bool) $wpdb->get_var( "SELECT meta_value FROM $wpdb->sitemeta WHERE site_id = 1 AND meta_key = 'subdomain_install'" );
     468
     469            wp_admin_notice(
     470                '<strong>' . __( 'Warning:' ) . '</strong> ' . __( 'An existing WordPress network was detected.' ),
     471                array(
     472                    'additional_classes' => array( 'error' ),
     473                )
     474            );
    429475            ?>
    430     <div class="error"><p><strong><?php _e( 'Warning:' ); ?></strong> <?php _e( 'An existing WordPress network was detected.' ); ?></p></div>
    431476    <p><?php _e( 'Please complete the configuration steps. To create a new network, you will need to empty or remove the network database tables.' ); ?></p>
    432477            <?php
Note: See TracChangeset for help on using the changeset viewer.