Make WordPress Core


Ignore:
Timestamp:
11/30/2017 11:09:33 PM (8 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/options-general.php

    r42217 r42343  
    1313require_once( ABSPATH . 'wp-admin/includes/translation-install.php' );
    1414
    15 if ( ! current_user_can( 'manage_options' ) )
     15if ( ! current_user_can( 'manage_options' ) ) {
    1616    wp_die( __( 'Sorry, you are not allowed to manage options for this site.' ) );
    17 
    18 $title = __('General Settings');
     17}
     18
     19$title       = __( 'General Settings' );
    1920$parent_file = 'options-general.php';
    2021/* translators: date and time format for exact current time, mainly about timezones, see https://secure.php.net/date */
    21 $timezone_format = _x('Y-m-d H:i:s', 'timezone date format');
    22 
    23 add_action('admin_head', 'options_general_add_js');
    24 
    25 $options_help = '<p>' . __('The fields on this screen determine some of the basics of your site setup.') . '</p>' .
    26     '<p>' . __('Most themes display the site title at the top of every page, in the title bar of the browser, and as the identifying name for syndicated feeds. The tagline is also displayed by many themes.') . '</p>';
     22$timezone_format = _x( 'Y-m-d H:i:s', 'timezone date format' );
     23
     24add_action( 'admin_head', 'options_general_add_js' );
     25
     26$options_help = '<p>' . __( 'The fields on this screen determine some of the basics of your site setup.' ) . '</p>' .
     27    '<p>' . __( 'Most themes display the site title at the top of every page, in the title bar of the browser, and as the identifying name for syndicated feeds. The tagline is also displayed by many themes.' ) . '</p>';
    2728
    2829if ( ! is_multisite() ) {
    29     $options_help .= '<p>' . __('The WordPress URL and the Site URL can be the same (example.com) or different; for example, having the WordPress core files (example.com/wordpress) in a subdirectory instead of the root directory.') . '</p>' .
    30         '<p>' . __('If you want site visitors to be able to register themselves, as opposed to by the site administrator, check the membership box. A default user role can be set for all new users, whether self-registered or registered by the site admin.') . '</p>';
     30    $options_help .= '<p>' . __( 'The WordPress URL and the Site URL can be the same (example.com) or different; for example, having the WordPress core files (example.com/wordpress) in a subdirectory instead of the root directory.' ) . '</p>' .
     31        '<p>' . __( 'If you want site visitors to be able to register themselves, as opposed to by the site administrator, check the membership box. A default user role can be set for all new users, whether self-registered or registered by the site admin.' ) . '</p>';
    3132}
    3233
     
    3536    '<p>' . __( 'You must click the Save Changes button at the bottom of the screen for new settings to take effect.' ) . '</p>';
    3637
    37 get_current_screen()->add_help_tab( array(
    38     'id'      => 'overview',
    39     'title'   => __('Overview'),
    40     'content' => $options_help,
    41 ) );
     38get_current_screen()->add_help_tab(
     39    array(
     40        'id'      => 'overview',
     41        'title'   => __( 'Overview' ),
     42        'content' => $options_help,
     43    )
     44);
    4245
    4346get_current_screen()->set_help_sidebar(
    44     '<p><strong>' . __('For more information:') . '</strong></p>' .
    45     '<p>' . __('<a href="https://codex.wordpress.org/Settings_General_Screen">Documentation on General Settings</a>') . '</p>' .
    46     '<p>' . __('<a href="https://wordpress.org/support/">Support Forums</a>') . '</p>'
     47    '<p><strong>' . __( 'For more information:' ) . '</strong></p>' .
     48    '<p>' . __( '<a href="https://codex.wordpress.org/Settings_General_Screen">Documentation on General Settings</a>' ) . '</p>' .
     49    '<p>' . __( '<a href="https://wordpress.org/support/">Support Forums</a>' ) . '</p>'
    4750);
    4851
     
    5457
    5558<form method="post" action="options.php" novalidate="novalidate">
    56 <?php settings_fields('general'); ?>
     59<?php settings_fields( 'general' ); ?>
    5760
    5861<table class="form-table">
    5962
    6063<tr>
    61 <th scope="row"><label for="blogname"><?php _e('Site Title') ?></label></th>
    62 <td><input name="blogname" type="text" id="blogname" value="<?php form_option('blogname'); ?>" class="regular-text" /></td>
    63 </tr>
    64 
    65 <tr>
    66 <th scope="row"><label for="blogdescription"><?php _e('Tagline') ?></label></th>
    67 <td><input name="blogdescription" type="text" id="blogdescription" aria-describedby="tagline-description" value="<?php form_option('blogdescription'); ?>" class="regular-text" />
    68 <p class="description" id="tagline-description"><?php _e( 'In a few words, explain what this site is about.' ) ?></p></td>
    69 </tr>
    70 
    71 <?php
    72     if ( !is_multisite() ) {
    73         $wp_site_url_class = $wp_home_class = '';
    74         if ( defined( 'WP_SITEURL' ) ) {
    75             $wp_site_url_class = ' disabled';
    76         }
    77         if ( defined( 'WP_HOME' ) ) {
    78             $wp_home_class = ' disabled';
    79         }
    80 ?>
    81 
    82 <tr>
    83 <th scope="row"><label for="siteurl"><?php _e('WordPress Address (URL)') ?></label></th>
     64<th scope="row"><label for="blogname"><?php _e( 'Site Title' ); ?></label></th>
     65<td><input name="blogname" type="text" id="blogname" value="<?php form_option( 'blogname' ); ?>" class="regular-text" /></td>
     66</tr>
     67
     68<tr>
     69<th scope="row"><label for="blogdescription"><?php _e( 'Tagline' ); ?></label></th>
     70<td><input name="blogdescription" type="text" id="blogdescription" aria-describedby="tagline-description" value="<?php form_option( 'blogdescription' ); ?>" class="regular-text" />
     71<p class="description" id="tagline-description"><?php _e( 'In a few words, explain what this site is about.' ); ?></p></td>
     72</tr>
     73
     74<?php
     75if ( ! is_multisite() ) {
     76    $wp_site_url_class = $wp_home_class = '';
     77    if ( defined( 'WP_SITEURL' ) ) {
     78        $wp_site_url_class = ' disabled';
     79    }
     80    if ( defined( 'WP_HOME' ) ) {
     81        $wp_home_class = ' disabled';
     82    }
     83?>
     84
     85<tr>
     86<th scope="row"><label for="siteurl"><?php _e( 'WordPress Address (URL)' ); ?></label></th>
    8487<td><input name="siteurl" type="url" id="siteurl" value="<?php form_option( 'siteurl' ); ?>"<?php disabled( defined( 'WP_SITEURL' ) ); ?> class="regular-text code<?php echo $wp_site_url_class; ?>" /></td>
    8588</tr>
    8689
    8790<tr>
    88 <th scope="row"><label for="home"><?php _e('Site Address (URL)') ?></label></th>
     91<th scope="row"><label for="home"><?php _e( 'Site Address (URL)' ); ?></label></th>
    8992<td><input name="home" type="url" id="home" aria-describedby="home-description" value="<?php form_option( 'home' ); ?>"<?php disabled( defined( 'WP_HOME' ) ); ?> class="regular-text code<?php echo $wp_home_class; ?>" />
    9093<?php if ( ! defined( 'WP_HOME' ) ) : ?>
    91 <p class="description" id="home-description"><?php
     94<p class="description" id="home-description">
     95<?php
    9296    printf(
    9397        /* translators: %s: Codex URL */
     
    9599        __( 'https://codex.wordpress.org/Giving_WordPress_Its_Own_Directory' )
    96100    );
    97 ?></p>
     101?>
     102</p>
    98103<?php endif; ?>
    99104</td>
     
    108113<?php
    109114$new_admin_email = get_option( 'new_admin_email' );
    110 if ( $new_admin_email && $new_admin_email != get_option( 'admin_email' ) ) : ?>
     115if ( $new_admin_email && $new_admin_email != get_option( 'admin_email' ) ) :
     116?>
    111117    <div class="updated inline">
    112     <p><?php
     118    <p>
     119    <?php
    113120        printf(
    114121            /* translators: %s: new admin email */
     
    121128            __( 'Cancel' )
    122129        );
    123     ?></p>
     130    ?>
     131    </p>
    124132    </div>
    125133<?php endif; ?>
     
    130138
    131139<tr>
    132 <th scope="row"><?php _e('Membership') ?></th>
    133 <td> <fieldset><legend class="screen-reader-text"><span><?php _e('Membership') ?></span></legend><label for="users_can_register">
    134 <input name="users_can_register" type="checkbox" id="users_can_register" value="1" <?php checked('1', get_option('users_can_register')); ?> />
    135 <?php _e('Anyone can register') ?></label>
     140<th scope="row"><?php _e( 'Membership' ); ?></th>
     141<td> <fieldset><legend class="screen-reader-text"><span><?php _e( 'Membership' ); ?></span></legend><label for="users_can_register">
     142<input name="users_can_register" type="checkbox" id="users_can_register" value="1" <?php checked( '1', get_option( 'users_can_register' ) ); ?> />
     143<?php _e( 'Anyone can register' ); ?></label>
    136144</fieldset></td>
    137145</tr>
    138146
    139147<tr>
    140 <th scope="row"><label for="default_role"><?php _e('New User Default Role') ?></label></th>
     148<th scope="row"><label for="default_role"><?php _e( 'New User Default Role' ); ?></label></th>
    141149<td>
    142 <select name="default_role" id="default_role"><?php wp_dropdown_roles( get_option('default_role') ); ?></select>
    143 </td>
    144 </tr>
    145 
    146 <?php }
    147 
    148 $languages = get_available_languages();
     150<select name="default_role" id="default_role"><?php wp_dropdown_roles( get_option( 'default_role' ) ); ?></select>
     151</td>
     152</tr>
     153
     154<?php
     155}
     156
     157$languages    = get_available_languages();
    149158$translations = wp_get_available_translations();
    150159if ( ! is_multisite() && defined( 'WPLANG' ) && '' !== WPLANG && 'en_US' !== WPLANG && ! in_array( WPLANG, $languages ) ) {
     
    162171            }
    163172
    164             wp_dropdown_languages( array(
    165                 'name'         => 'WPLANG',
    166                 'id'           => 'WPLANG',
    167                 'selected'     => $locale,
    168                 'languages'    => $languages,
    169                 'translations' => $translations,
    170                 'show_available_translations' => current_user_can( 'install_languages' ),
    171             ) );
     173            wp_dropdown_languages(
     174                array(
     175                    'name'                        => 'WPLANG',
     176                    'id'                          => 'WPLANG',
     177                    'selected'                    => $locale,
     178                    'languages'                   => $languages,
     179                    'translations'                => $translations,
     180                    'show_available_translations' => current_user_can( 'install_languages' ),
     181                )
     182            );
    172183
    173184            // Add note about deprecated WPLANG constant.
     
    177188                    ?>
    178189                    <p class="description">
    179                         <strong><?php _e( 'Note:' ); ?></strong> <?php printf( __( 'The %s constant in your %s file is no longer needed.' ), '<code>WPLANG</code>', '<code>wp-config.php</code>' ); ?>
     190                        <strong><?php _e( 'Note:' ); ?></strong> <?php printf( __( 'The %1$s constant in your %2$s file is no longer needed.' ), '<code>WPLANG</code>', '<code>wp-config.php</code>' ); ?>
    180191                    </p>
    181192                    <?php
    182193                }
    183                 _deprecated_argument( 'define()', '4.0.0', sprintf( __( 'The %s constant in your %s file is no longer needed.' ), 'WPLANG', 'wp-config.php' ) );
     194                _deprecated_argument( 'define()', '4.0.0', sprintf( __( 'The %1$s constant in your %2$s file is no longer needed.' ), 'WPLANG', 'wp-config.php' ) );
    184195            }
    185196            ?>
     
    191202<tr>
    192203<?php
    193 $current_offset = get_option('gmt_offset');
    194 $tzstring = get_option('timezone_string');
     204$current_offset = get_option( 'gmt_offset' );
     205$tzstring       = get_option( 'timezone_string' );
    195206
    196207$check_zone_info = true;
    197208
    198209// Remove old Etc mappings. Fallback to gmt_offset.
    199 if ( false !== strpos($tzstring,'Etc/GMT') )
     210if ( false !== strpos( $tzstring, 'Etc/GMT' ) ) {
    200211    $tzstring = '';
    201 
    202 if ( empty($tzstring) ) { // Create a UTC+- zone if no timezone string exists
     212}
     213
     214if ( empty( $tzstring ) ) { // Create a UTC+- zone if no timezone string exists
    203215    $check_zone_info = false;
    204     if ( 0 == $current_offset )
     216    if ( 0 == $current_offset ) {
    205217        $tzstring = 'UTC+0';
    206     elseif ($current_offset < 0)
     218    } elseif ( $current_offset < 0 ) {
    207219        $tzstring = 'UTC' . $current_offset;
    208     else
     220    } else {
    209221        $tzstring = 'UTC+' . $current_offset;
    210 }
    211 
    212 ?>
    213 <th scope="row"><label for="timezone_string"><?php _e('Timezone') ?></label></th>
     222    }
     223}
     224
     225?>
     226<th scope="row"><label for="timezone_string"><?php _e( 'Timezone' ); ?></label></th>
    214227<td>
    215228
     
    221234
    222235<p class="timezone-info">
    223     <span id="utc-time"><?php
     236    <span id="utc-time">
     237    <?php
    224238        /* translators: 1: UTC abbreviation, 2: UTC time */
    225         printf( __( 'Universal time (%1$s) is %2$s.' ),
     239        printf(
     240            __( 'Universal time (%1$s) is %2$s.' ),
    226241            '<abbr>' . __( 'UTC' ) . '</abbr>',
    227242            '<code>' . date_i18n( $timezone_format, false, true ) . '</code>'
    228243        );
    229     ?></span>
     244    ?>
     245    </span>
    230246<?php if ( get_option( 'timezone_string' ) || ! empty( $current_offset ) ) : ?>
    231     <span id="local-time"><?php
     247    <span id="local-time">
     248    <?php
    232249        /* translators: %s: local time */
    233         printf( __( 'Local time is %s.' ),
     250        printf(
     251            __( 'Local time is %s.' ),
    234252            '<code>' . date_i18n( $timezone_format ) . '</code>'
    235253        );
    236     ?></span>
     254    ?>
     255    </span>
    237256<?php endif; ?>
    238257</p>
     
    243262    <?php
    244263    // Set TZ so localtime works.
    245     date_default_timezone_set($tzstring);
    246     $now = localtime(time(), true);
    247     if ( $now['tm_isdst'] )
    248         _e('This timezone is currently in daylight saving time.');
    249     else
    250         _e('This timezone is currently in standard time.');
     264    date_default_timezone_set( $tzstring );
     265    $now = localtime( time(), true );
     266    if ( $now['tm_isdst'] ) {
     267        _e( 'This timezone is currently in daylight saving time.' );
     268    } else {
     269        _e( 'This timezone is currently in standard time.' );
     270    }
    251271    ?>
    252272    <br />
     
    254274    $allowed_zones = timezone_identifiers_list();
    255275
    256     if ( in_array( $tzstring, $allowed_zones) ) {
    257         $found = false;
    258         $date_time_zone_selected = new DateTimeZone($tzstring);
    259         $tz_offset = timezone_offset_get($date_time_zone_selected, date_create());
    260         $right_now = time();
    261         foreach ( timezone_transitions_get($date_time_zone_selected) as $tr) {
     276    if ( in_array( $tzstring, $allowed_zones ) ) {
     277        $found                   = false;
     278        $date_time_zone_selected = new DateTimeZone( $tzstring );
     279        $tz_offset               = timezone_offset_get( $date_time_zone_selected, date_create() );
     280        $right_now               = time();
     281        foreach ( timezone_transitions_get( $date_time_zone_selected ) as $tr ) {
    262282            if ( $tr['ts'] > $right_now ) {
    263                 $found = true;
     283                $found = true;
    264284                break;
    265285            }
     
    270290            $message = $tr['isdst'] ?
    271291                /* translators: %s: date and time  */
    272                 __( 'Daylight saving time begins on: %s.') :
     292                __( 'Daylight saving time begins on: %s.' ) :
    273293                /* translators: %s: date and time  */
    274294                __( 'Standard time begins on: %s.' );
    275295            // Add the difference between the current offset and the new offset to ts to get the correct transition time from date_i18n().
    276             printf( $message,
     296            printf(
     297                $message,
    277298                '<code>' . date_i18n(
    278299                    __( 'F j, Y' ) . ' ' . __( 'g:i a' ),
     
    285306    }
    286307    // Set back to UTC.
    287     date_default_timezone_set('UTC');
     308    date_default_timezone_set( 'UTC' );
    288309    ?>
    289310    </span>
     
    294315</tr>
    295316<tr>
    296 <th scope="row"><?php _e('Date Format') ?></th>
     317<th scope="row"><?php _e( 'Date Format' ); ?></th>
    297318<td>
    298     <fieldset><legend class="screen-reader-text"><span><?php _e('Date Format') ?></span></legend>
     319    <fieldset><legend class="screen-reader-text"><span><?php _e( 'Date Format' ); ?></span></legend>
    299320<?php
    300321    /**
    301     * Filters the default date formats.
    302     *
    303     * @since 2.7.0
    304     * @since 4.0.0 Added ISO date standard YYYY-MM-DD format.
    305     *
    306     * @param array $default_date_formats Array of default date formats.
    307     */
     322     * Filters the default date formats.
     323     *
     324     * @since 2.7.0
     325     * @since 4.0.0 Added ISO date standard YYYY-MM-DD format.
     326     *
     327     * @param array $default_date_formats Array of default date formats.
     328     */
    308329    $date_formats = array_unique( apply_filters( 'date_formats', array( __( 'F j, Y' ), 'Y-m-d', 'm/d/Y', 'd/m/Y' ) ) );
    309330
    310331    $custom = true;
    311332
    312     foreach ( $date_formats as $format ) {
    313         echo "\t<label><input type='radio' name='date_format' value='" . esc_attr( $format ) . "'";
    314         if ( get_option('date_format') === $format ) { // checked() uses "==" rather than "==="
    315             echo " checked='checked'";
    316             $custom = false;
    317         }
    318         echo ' /> <span class="date-time-text format-i18n">' . date_i18n( $format ) . '</span><code>' . esc_html( $format ) . "</code></label><br />\n";
    319     }
     333foreach ( $date_formats as $format ) {
     334    echo "\t<label><input type='radio' name='date_format' value='" . esc_attr( $format ) . "'";
     335    if ( get_option( 'date_format' ) === $format ) { // checked() uses "==" rather than "==="
     336        echo " checked='checked'";
     337        $custom = false;
     338    }
     339    echo ' /> <span class="date-time-text format-i18n">' . date_i18n( $format ) . '</span><code>' . esc_html( $format ) . "</code></label><br />\n";
     340}
    320341
    321342    echo '<label><input type="radio" name="date_format" id="date_format_custom_radio" value="\c\u\s\t\o\m"';
     
    332353</tr>
    333354<tr>
    334 <th scope="row"><?php _e('Time Format') ?></th>
     355<th scope="row"><?php _e( 'Time Format' ); ?></th>
    335356<td>
    336     <fieldset><legend class="screen-reader-text"><span><?php _e('Time Format') ?></span></legend>
     357    <fieldset><legend class="screen-reader-text"><span><?php _e( 'Time Format' ); ?></span></legend>
    337358<?php
    338359    /**
    339     * Filters the default time formats.
    340     *
    341     * @since 2.7.0
    342     *
    343     * @param array $default_time_formats Array of default time formats.
    344     */
     360     * Filters the default time formats.
     361     *
     362     * @since 2.7.0
     363     *
     364     * @param array $default_time_formats Array of default time formats.
     365     */
    345366    $time_formats = array_unique( apply_filters( 'time_formats', array( __( 'g:i a' ), 'g:i A', 'H:i' ) ) );
    346367
    347368    $custom = true;
    348369
    349     foreach ( $time_formats as $format ) {
    350         echo "\t<label><input type='radio' name='time_format' value='" . esc_attr( $format ) . "'";
    351         if ( get_option('time_format') === $format ) { // checked() uses "==" rather than "==="
    352             echo " checked='checked'";
    353             $custom = false;
    354         }
    355         echo ' /> <span class="date-time-text format-i18n">' . date_i18n( $format ) . '</span><code>' . esc_html( $format ) . "</code></label><br />\n";
    356     }
     370foreach ( $time_formats as $format ) {
     371    echo "\t<label><input type='radio' name='time_format' value='" . esc_attr( $format ) . "'";
     372    if ( get_option( 'time_format' ) === $format ) { // checked() uses "==" rather than "==="
     373        echo " checked='checked'";
     374        $custom = false;
     375    }
     376    echo ' /> <span class="date-time-text format-i18n">' . date_i18n( $format ) . '</span><code>' . esc_html( $format ) . "</code></label><br />\n";
     377}
    357378
    358379    echo '<label><input type="radio" name="time_format" id="time_format_custom_radio" value="\c\u\s\t\o\m"';
     
    365386        "<span class='spinner'></span>\n" . '</p>';
    366387
    367     echo "\t<p class='date-time-doc'>" . __('<a href="https://codex.wordpress.org/Formatting_Date_and_Time">Documentation on date and time formatting</a>.') . "</p>\n";
     388    echo "\t<p class='date-time-doc'>" . __( '<a href="https://codex.wordpress.org/Formatting_Date_and_Time">Documentation on date and time formatting</a>.' ) . "</p>\n";
    368389?>
    369390    </fieldset>
     
    371392</tr>
    372393<tr>
    373 <th scope="row"><label for="start_of_week"><?php _e('Week Starts On') ?></label></th>
     394<th scope="row"><label for="start_of_week"><?php _e( 'Week Starts On' ); ?></label></th>
    374395<td><select name="start_of_week" id="start_of_week">
    375396<?php
     
    379400global $wp_locale;
    380401
    381 for ($day_index = 0; $day_index <= 6; $day_index++) :
    382     $selected = (get_option('start_of_week') == $day_index) ? 'selected="selected"' : '';
    383     echo "\n\t<option value='" . esc_attr($day_index) . "' $selected>" . $wp_locale->get_weekday($day_index) . '</option>';
     402for ( $day_index = 0; $day_index <= 6; $day_index++ ) :
     403    $selected = ( get_option( 'start_of_week' ) == $day_index ) ? 'selected="selected"' : '';
     404    echo "\n\t<option value='" . esc_attr( $day_index ) . "' $selected>" . $wp_locale->get_weekday( $day_index ) . '</option>';
    384405endfor;
    385406?>
    386407</select></td>
    387408</tr>
    388 <?php do_settings_fields('general', 'default'); ?>
     409<?php do_settings_fields( 'general', 'default' ); ?>
    389410</table>
    390411
    391 <?php do_settings_sections('general'); ?>
     412<?php do_settings_sections( 'general' ); ?>
    392413
    393414<?php submit_button(); ?>
Note: See TracChangeset for help on using the changeset viewer.