Make WordPress Core


Ignore:
Timestamp:
11/30/2017 11:09:33 PM (6 years ago)
Author:
pento
Message:

Code is Poetry.
WordPress' code just... wasn't.
This is now dealt with.

Props jrf, pento, netweb, GaryJ, jdgrimes, westonruter, Greg Sherwood from PHPCS, and everyone who's ever contributed to WPCS and PHPCS.
Fixes #41057.

File:
1 edited

Legend:

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

    r42228 r42343  
    1818}
    1919
    20 get_current_screen()->add_help_tab( array(
    21     'id'      => 'overview',
    22     'title'   => __('Overview'),
    23     'content' =>
    24         '<p>' . __('This screen is for Super Admins to add new sites to the network. This is not affected by the registration settings.') . '</p>' .
    25         '<p>' . __('If the admin email for the new site does not exist in the database, a new user will also be created.') . '</p>'
    26 ) );
     20get_current_screen()->add_help_tab(
     21    array(
     22        'id'      => 'overview',
     23        'title'   => __( 'Overview' ),
     24        'content' =>
     25            '<p>' . __( 'This screen is for Super Admins to add new sites to the network. This is not affected by the registration settings.' ) . '</p>' .
     26            '<p>' . __( 'If the admin email for the new site does not exist in the database, a new user will also be created.' ) . '</p>',
     27    )
     28);
    2729
    2830get_current_screen()->set_help_sidebar(
    29     '<p><strong>' . __('For more information:') . '</strong></p>' .
    30     '<p>' . __('<a href="https://codex.wordpress.org/Network_Admin_Sites_Screen">Documentation on Site Management</a>') . '</p>' .
    31     '<p>' . __('<a href="https://wordpress.org/support/forum/multisite/">Support Forums</a>') . '</p>'
     31    '<p><strong>' . __( 'For more information:' ) . '</strong></p>' .
     32    '<p>' . __( '<a href="https://codex.wordpress.org/Network_Admin_Sites_Screen">Documentation on Site Management</a>' ) . '</p>' .
     33    '<p>' . __( '<a href="https://wordpress.org/support/forum/multisite/">Support Forums</a>' ) . '</p>'
    3234);
    3335
    34 if ( isset($_REQUEST['action']) && 'add-site' == $_REQUEST['action'] ) {
     36if ( isset( $_REQUEST['action'] ) && 'add-site' == $_REQUEST['action'] ) {
    3537    check_admin_referer( 'add-blog', '_wpnonce_add-blog' );
    3638
    37     if ( ! is_array( $_POST['blog'] ) )
     39    if ( ! is_array( $_POST['blog'] ) ) {
    3840        wp_die( __( 'Can&#8217;t create an empty site.' ) );
    39 
    40     $blog = $_POST['blog'];
     41    }
     42
     43    $blog   = $_POST['blog'];
    4144    $domain = '';
    42     if ( preg_match( '|^([a-zA-Z0-9-])+$|', $blog['domain'] ) )
     45    if ( preg_match( '|^([a-zA-Z0-9-])+$|', $blog['domain'] ) ) {
    4346        $domain = strtolower( $blog['domain'] );
     47    }
    4448
    4549    // If not a subdomain installation, make sure the domain isn't a reserved word
     
    5054            wp_die(
    5155                /* translators: %s: reserved names list */
    52                 sprintf( __( 'The following words are reserved for use by WordPress functions and cannot be used as blog names: %s' ),
     56                sprintf(
     57                    __( 'The following words are reserved for use by WordPress functions and cannot be used as blog names: %s' ),
    5358                    '<code>' . implode( '</code>, <code>', $subdirectory_reserved_names ) . '</code>'
    5459                )
     
    6065
    6166    $meta = array(
    62         'public' => 1
     67        'public' => 1,
    6368    );
    6469
     
    7782    }
    7883
    79     if ( empty( $domain ) )
     84    if ( empty( $domain ) ) {
    8085        wp_die( __( 'Missing or invalid site address.' ) );
     86    }
    8187
    8288    if ( isset( $blog['email'] ) && '' === trim( $blog['email'] ) ) {
     
    98104
    99105    $password = 'N/A';
    100     $user_id = email_exists($email);
    101     if ( !$user_id ) { // Create a new user with a random password
     106    $user_id  = email_exists( $email );
     107    if ( ! $user_id ) { // Create a new user with a random password
    102108        /**
    103109         * Fires immediately before a new user is created via the network site-new.php page.
     
    114120        }
    115121        $password = wp_generate_password( 12, false );
    116         $user_id = wpmu_create_user( $domain, $password, $email );
     122        $user_id  = wpmu_create_user( $domain, $password, $email );
    117123        if ( false === $user_id ) {
    118124            wp_die( __( 'There was an error creating the user.' ) );
     
    133139    $wpdb->show_errors();
    134140    if ( ! is_wp_error( $id ) ) {
    135         if ( ! is_super_admin( $user_id ) && !get_user_option( 'primary_blog', $user_id ) ) {
     141        if ( ! is_super_admin( $user_id ) && ! get_user_option( 'primary_blog', $user_id ) ) {
    136142            update_user_option( $user_id, 'primary_blog', $id, true );
    137143        }
     
    146152            sprintf(
    147153                /* translators: 1: user login, 2: site url, 3: site name/title */
    148                 __( 'New site created by %1$s
     154                __(
     155                    'New site created by %1$s
    149156
    150157Address: %2$s
    151 Name: %3$s' ),
     158Name: %3$s'
     159                ),
    152160                $current_user->user_login,
    153161                get_site_url( $id ),
     
    161169        );
    162170        wpmu_welcome_notification( $id, $user_id, $password, $title, array( 'public' => 1 ) );
    163         wp_redirect( add_query_arg( array( 'update' => 'added', 'id' => $id ), 'site-new.php' ) );
     171        wp_redirect(
     172            add_query_arg(
     173                array(
     174                    'update' => 'added',
     175                    'id'     => $id,
     176                ), 'site-new.php'
     177            )
     178        );
    164179        exit;
    165180    } else {
     
    168183}
    169184
    170 if ( isset($_GET['update']) ) {
     185if ( isset( $_GET['update'] ) ) {
    171186    $messages = array();
    172     if ( 'added' == $_GET['update'] )
     187    if ( 'added' == $_GET['update'] ) {
    173188        $messages[] = sprintf(
    174189            /* translators: 1: dashboard url, 2: network admin edit url */
     
    177192            network_admin_url( 'site-info.php?id=' . absint( $_GET['id'] ) )
    178193        );
    179 }
    180 
    181 $title = __('Add New Site');
     194    }
     195}
     196
     197$title       = __( 'Add New Site' );
    182198$parent_file = 'sites.php';
    183199
     
    192208<?php
    193209if ( ! empty( $messages ) ) {
    194     foreach ( $messages as $msg )
     210    foreach ( $messages as $msg ) {
    195211        echo '<div id="message" class="updated notice is-dismissible"><p>' . $msg . '</p></div>';
    196 } ?>
     212    }
     213}
     214?>
    197215<form method="post" action="<?php echo network_admin_url( 'site-new.php?action=add-site' ); ?>" novalidate="novalidate">
    198 <?php wp_nonce_field( 'add-blog', '_wpnonce_add-blog' ) ?>
     216<?php wp_nonce_field( 'add-blog', '_wpnonce_add-blog' ); ?>
    199217    <table class="form-table">
    200218        <tr class="form-field form-required">
    201             <th scope="row"><label for="site-address"><?php _e( 'Site Address (URL)' ) ?></label></th>
     219            <th scope="row"><label for="site-address"><?php _e( 'Site Address (URL)' ); ?></label></th>
    202220            <td>
    203221            <?php if ( is_subdomain_install() ) { ?>
    204222                <input name="blog[domain]" type="text" class="regular-text" id="site-address" aria-describedby="site-address-desc" autocapitalize="none" autocorrect="off"/><span class="no-break">.<?php echo preg_replace( '|^www\.|', '', get_network()->domain ); ?></span>
    205             <?php } else {
    206                 echo get_network()->domain . get_network()->path ?><input name="blog[domain]" type="text" class="regular-text" id="site-address" aria-describedby="site-address-desc"  autocapitalize="none" autocorrect="off" />
    207             <?php }
     223            <?php
     224} else {
     225    echo get_network()->domain . get_network()->path
     226    ?>
     227                <input name="blog[domain]" type="text" class="regular-text" id="site-address" aria-describedby="site-address-desc"  autocapitalize="none" autocorrect="off" />
     228<?php
     229}
    208230            echo '<p class="description" id="site-address-desc">' . __( 'Only lowercase letters (a-z), numbers, and hyphens are allowed.' ) . '</p>';
    209231            ?>
     
    211233        </tr>
    212234        <tr class="form-field form-required">
    213             <th scope="row"><label for="site-title"><?php _e( 'Site Title' ) ?></label></th>
     235            <th scope="row"><label for="site-title"><?php _e( 'Site Title' ); ?></label></th>
    214236            <td><input name="blog[title]" type="text" class="regular-text" id="site-title" /></td>
    215237        </tr>
     
    231253                    }
    232254
    233                     wp_dropdown_languages( array(
    234                         'name'                        => 'WPLANG',
    235                         'id'                          => 'site-language',
    236                         'selected'                    => $lang,
    237                         'languages'                   => $languages,
    238                         'translations'                => $translations,
    239                         'show_available_translations' => current_user_can( 'install_languages' ),
    240                     ) );
     255                    wp_dropdown_languages(
     256                        array(
     257                            'name'                        => 'WPLANG',
     258                            'id'                          => 'site-language',
     259                            'selected'                    => $lang,
     260                            'languages'                   => $languages,
     261                            'translations'                => $translations,
     262                            'show_available_translations' => current_user_can( 'install_languages' ),
     263                        )
     264                    );
    241265                    ?>
    242266                </td>
     
    244268        <?php endif; // Languages. ?>
    245269        <tr class="form-field form-required">
    246             <th scope="row"><label for="admin-email"><?php _e( 'Admin Email' ) ?></label></th>
     270            <th scope="row"><label for="admin-email"><?php _e( 'Admin Email' ); ?></label></th>
    247271            <td><input name="blog[email]" type="email" class="regular-text wp-suggest-user" id="admin-email" data-autocomplete-type="search" data-autocomplete-field="user_email" /></td>
    248272        </tr>
    249273        <tr class="form-field">
    250             <td colspan="2"><?php _e( 'A new user will be created if the above email address is not in the database.' ) ?><br /><?php _e( 'The username and a link to set the password will be mailed to this email address.' ) ?></td>
     274            <td colspan="2"><?php _e( 'A new user will be created if the above email address is not in the database.' ); ?><br /><?php _e( 'The username and a link to set the password will be mailed to this email address.' ); ?></td>
    251275        </tr>
    252276    </table>
Note: See TracChangeset for help on using the changeset viewer.