WordPress.org

Make WordPress Core


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

    r42228 r42343  
    1919require_once( dirname( __FILE__ ) . '/admin.php' );
    2020
    21 $title = __('Settings');
    22 $this_file = 'options.php';
     21$title       = __( 'Settings' );
     22$this_file   = 'options.php';
    2323$parent_file = 'options-general.php';
    2424
    25 wp_reset_vars(array('action', 'option_page'));
     25wp_reset_vars( array( 'action', 'option_page' ) );
    2626
    2727$capability = 'manage_options';
    2828
    2929// This is for back compat and will eventually be removed.
    30 if ( empty($option_page) ) {
     30if ( empty( $option_page ) ) {
    3131    $option_page = 'options';
    3232} else {
     
    5454
    5555// Handle admin email change requests
    56 if ( ! empty( $_GET[ 'adminhash' ] ) ) {
     56if ( ! empty( $_GET['adminhash'] ) ) {
    5757    $new_admin_details = get_option( 'adminhash' );
    58     $redirect = 'options-general.php?updated=false';
    59     if ( is_array( $new_admin_details ) && hash_equals( $new_admin_details[ 'hash' ], $_GET[ 'adminhash' ] ) && ! empty( $new_admin_details[ 'newemail' ] ) ) {
    60         update_option( 'admin_email', $new_admin_details[ 'newemail' ] );
     58    $redirect          = 'options-general.php?updated=false';
     59    if ( is_array( $new_admin_details ) && hash_equals( $new_admin_details['hash'], $_GET['adminhash'] ) && ! empty( $new_admin_details['newemail'] ) ) {
     60        update_option( 'admin_email', $new_admin_details['newemail'] );
    6161        delete_option( 'adminhash' );
    6262        delete_option( 'new_admin_email' );
     
    8181}
    8282
    83 $whitelist_options = array(
    84     'general' => array( 'blogname', 'blogdescription', 'gmt_offset', 'date_format', 'time_format', 'start_of_week', 'timezone_string', 'WPLANG', 'new_admin_email' ),
     83$whitelist_options         = array(
     84    'general'    => array( 'blogname', 'blogdescription', 'gmt_offset', 'date_format', 'time_format', 'start_of_week', 'timezone_string', 'WPLANG', 'new_admin_email' ),
    8585    'discussion' => array( 'default_pingback_flag', 'default_ping_status', 'default_comment_status', 'comments_notify', 'moderation_notify', 'comment_moderation', 'require_name_email', 'comment_whitelist', 'comment_max_links', 'moderation_keys', 'blacklist_keys', 'show_avatars', 'avatar_rating', 'avatar_default', 'close_comments_for_old_posts', 'close_comments_days_old', 'thread_comments', 'thread_comments_depth', 'page_comments', 'comments_per_page', 'default_comments_page', 'comment_order', 'comment_registration' ),
    86     'media' => array( 'thumbnail_size_w', 'thumbnail_size_h', 'thumbnail_crop', 'medium_size_w', 'medium_size_h', 'large_size_w', 'large_size_h', 'image_default_size', 'image_default_align', 'image_default_link_type' ),
    87     'reading' => array( 'posts_per_page', 'posts_per_rss', 'rss_use_excerpt', 'show_on_front', 'page_on_front', 'page_for_posts', 'blog_public' ),
    88     'writing' => array( 'default_category', 'default_email_category', 'default_link_category', 'default_post_format' )
     86    'media'      => array( 'thumbnail_size_w', 'thumbnail_size_h', 'thumbnail_crop', 'medium_size_w', 'medium_size_h', 'large_size_w', 'large_size_h', 'image_default_size', 'image_default_align', 'image_default_link_type' ),
     87    'reading'    => array( 'posts_per_page', 'posts_per_rss', 'rss_use_excerpt', 'show_on_front', 'page_on_front', 'page_for_posts', 'blog_public' ),
     88    'writing'    => array( 'default_category', 'default_email_category', 'default_link_category', 'default_post_format' ),
    8989);
    9090$whitelist_options['misc'] = $whitelist_options['options'] = $whitelist_options['privacy'] = array();
    9191
    92 $mail_options = array('mailserver_url', 'mailserver_port', 'mailserver_login', 'mailserver_pass');
    93 
    94 if ( ! in_array( get_option( 'blog_charset' ), array( 'utf8', 'utf-8', 'UTF8', 'UTF-8' ) ) )
     92$mail_options = array( 'mailserver_url', 'mailserver_port', 'mailserver_login', 'mailserver_pass' );
     93
     94if ( ! in_array( get_option( 'blog_charset' ), array( 'utf8', 'utf-8', 'UTF8', 'UTF-8' ) ) ) {
    9595    $whitelist_options['reading'][] = 'blog_charset';
     96}
    9697
    9798if ( get_site_option( 'initial_db_version' ) < 32453 ) {
     
    100101}
    101102
    102 if ( !is_multisite() ) {
    103     if ( !defined( 'WP_SITEURL' ) )
     103if ( ! is_multisite() ) {
     104    if ( ! defined( 'WP_SITEURL' ) ) {
    104105        $whitelist_options['general'][] = 'siteurl';
    105     if ( !defined( 'WP_HOME' ) )
     106    }
     107    if ( ! defined( 'WP_HOME' ) ) {
    106108        $whitelist_options['general'][] = 'home';
     109    }
    107110
    108111    $whitelist_options['general'][] = 'users_can_register';
    109112    $whitelist_options['general'][] = 'default_role';
    110113
    111     $whitelist_options['writing'] = array_merge($whitelist_options['writing'], $mail_options);
     114    $whitelist_options['writing']   = array_merge( $whitelist_options['writing'], $mail_options );
    112115    $whitelist_options['writing'][] = 'ping_sites';
    113116
     
    115118
    116119    // If upload_url_path and upload_path are both default values, they're locked.
    117     if ( get_option( 'upload_url_path' ) || ( get_option('upload_path') != 'wp-content/uploads' && get_option('upload_path') ) ) {
     120    if ( get_option( 'upload_url_path' ) || ( get_option( 'upload_path' ) != 'wp-content/uploads' && get_option( 'upload_path' ) ) ) {
    118121        $whitelist_options['media'][] = 'upload_path';
    119122        $whitelist_options['media'][] = 'upload_url_path';
     
    127130     * @param bool $enabled Whether post-by-email configuration is enabled. Default true.
    128131     */
    129     if ( apply_filters( 'enable_post_by_email_configuration', true ) )
    130         $whitelist_options['writing'] = array_merge($whitelist_options['writing'], $mail_options);
     132    if ( apply_filters( 'enable_post_by_email_configuration', true ) ) {
     133        $whitelist_options['writing'] = array_merge( $whitelist_options['writing'], $mail_options );
     134    }
    131135}
    132136
     
    144148 */
    145149if ( 'update' == $action ) {
    146     if ( 'options' == $option_page && !isset( $_POST['option_page'] ) ) { // This is for back compat and will eventually be removed.
     150    if ( 'options' == $option_page && ! isset( $_POST['option_page'] ) ) { // This is for back compat and will eventually be removed.
    147151        $unregistered = true;
    148152        check_admin_referer( 'update-options' );
     
    152156    }
    153157
    154     if ( !isset( $whitelist_options[ $option_page ] ) )
     158    if ( ! isset( $whitelist_options[ $option_page ] ) ) {
    155159        wp_die( __( '<strong>ERROR</strong>: options page not found.' ) );
     160    }
    156161
    157162    if ( 'options' == $option_page ) {
     
    159164            wp_die( __( 'Sorry, you are not allowed to modify unregistered settings for this site.' ) );
    160165        }
    161         $options = explode( ',', wp_unslash( $_POST[ 'page_options' ] ) );
     166        $options = explode( ',', wp_unslash( $_POST['page_options'] ) );
    162167    } else {
    163168        $options = $whitelist_options[ $option_page ];
     
    166171    if ( 'general' == $option_page ) {
    167172        // Handle custom date/time formats.
    168         if ( !empty($_POST['date_format']) && isset($_POST['date_format_custom']) && '\c\u\s\t\o\m' == wp_unslash( $_POST['date_format'] ) )
     173        if ( ! empty( $_POST['date_format'] ) && isset( $_POST['date_format_custom'] ) && '\c\u\s\t\o\m' == wp_unslash( $_POST['date_format'] ) ) {
    169174            $_POST['date_format'] = $_POST['date_format_custom'];
    170         if ( !empty($_POST['time_format']) && isset($_POST['time_format_custom']) && '\c\u\s\t\o\m' == wp_unslash( $_POST['time_format'] ) )
     175        }
     176        if ( ! empty( $_POST['time_format'] ) && isset( $_POST['time_format_custom'] ) && '\c\u\s\t\o\m' == wp_unslash( $_POST['time_format'] ) ) {
    171177            $_POST['time_format'] = $_POST['time_format_custom'];
     178        }
    172179        // Map UTC+- timezones to gmt_offsets and set timezone_string to empty.
    173         if ( !empty($_POST['timezone_string']) && preg_match('/^UTC[+-]/', $_POST['timezone_string']) ) {
    174             $_POST['gmt_offset'] = $_POST['timezone_string'];
    175             $_POST['gmt_offset'] = preg_replace('/UTC\+?/', '', $_POST['gmt_offset']);
     180        if ( ! empty( $_POST['timezone_string'] ) && preg_match( '/^UTC[+-]/', $_POST['timezone_string'] ) ) {
     181            $_POST['gmt_offset']      = $_POST['timezone_string'];
     182            $_POST['gmt_offset']      = preg_replace( '/UTC\+?/', '', $_POST['gmt_offset'] );
    176183            $_POST['timezone_string'] = '';
    177184        }
     
    193200        foreach ( $options as $option ) {
    194201            if ( $unregistered ) {
    195                 _deprecated_argument( 'options.php', '2.7.0',
     202                _deprecated_argument(
     203                    'options.php', '2.7.0',
    196204                    sprintf(
    197205                        /* translators: %s: the option/setting */
     
    203211
    204212            $option = trim( $option );
    205             $value = null;
     213            $value  = null;
    206214            if ( isset( $_POST[ $option ] ) ) {
    207215                $value = $_POST[ $option ];
     
    221229        unset( $GLOBALS['locale'] );
    222230        $user_language_new = get_user_locale();
    223         if ( $user_language_old !== $user_language_new  ) {
     231        if ( $user_language_old !== $user_language_new ) {
    224232            load_default_textdomain( $user_language_new );
    225233        }
     
    230238     */
    231239    // If no settings errors were registered add a general 'updated' message.
    232     if ( !count( get_settings_errors() ) )
    233         add_settings_error('general', 'settings_updated', __('Settings saved.'), 'updated');
    234     set_transient('settings_errors', get_settings_errors(), 30);
     240    if ( ! count( get_settings_errors() ) ) {
     241        add_settings_error( 'general', 'settings_updated', __( 'Settings saved.' ), 'updated' );
     242    }
     243    set_transient( 'settings_errors', get_settings_errors(), 30 );
    235244
    236245    /**
    237246     * Redirect back to the settings page that was submitted
    238247     */
    239     $goback = add_query_arg( 'settings-updated', 'true',  wp_get_referer() );
     248    $goback = add_query_arg( 'settings-updated', 'true', wp_get_referer() );
    240249    wp_redirect( $goback );
    241250    exit;
     
    247256    <h1><?php esc_html_e( 'All Settings' ); ?></h1>
    248257    <form name="form" action="options.php" method="post" id="all-options">
    249         <?php wp_nonce_field('options-options') ?>
     258        <?php wp_nonce_field( 'options-options' ); ?>
    250259        <input type="hidden" name="action" value="update" />
    251260        <input type="hidden" name="option_page" value="options" />
     
    256265foreach ( (array) $options as $option ) :
    257266    $disabled = false;
    258     if ( $option->option_name == '' )
     267    if ( $option->option_name == '' ) {
    259268        continue;
     269    }
    260270    if ( is_serialized( $option->option_value ) ) {
    261271        if ( is_serialized_string( $option->option_value ) ) {
    262272            // This is a serialized string, so we should display it.
    263             $value = maybe_unserialize( $option->option_value );
     273            $value               = maybe_unserialize( $option->option_value );
    264274            $options_to_update[] = $option->option_name;
    265             $class = 'all-options';
     275            $class               = 'all-options';
    266276        } else {
    267             $value = 'SERIALIZED DATA';
     277            $value    = 'SERIALIZED DATA';
    268278            $disabled = true;
    269             $class = 'all-options disabled';
     279            $class    = 'all-options disabled';
    270280        }
    271281    } else {
    272         $value = $option->option_value;
     282        $value               = $option->option_value;
    273283        $options_to_update[] = $option->option_name;
    274         $class = 'all-options';
     284        $class               = 'all-options';
    275285    }
    276286    $name = esc_attr( $option->option_name );
    277287    ?>
    278288<tr>
    279     <th scope="row"><label for="<?php echo $name ?>"><?php echo esc_html( $option->option_name ); ?></label></th>
     289    <th scope="row"><label for="<?php echo $name; ?>"><?php echo esc_html( $option->option_name ); ?></label></th>
    280290<td>
    281291<?php if ( strpos( $value, "\n" ) !== false ) : ?>
    282     <textarea class="<?php echo $class ?>" name="<?php echo $name ?>" id="<?php echo $name ?>" cols="30" rows="5"><?php
    283         echo esc_textarea( $value );
    284     ?></textarea>
    285     <?php else: ?>
    286         <input class="regular-text <?php echo $class ?>" type="text" name="<?php echo $name ?>" id="<?php echo $name ?>" value="<?php echo esc_attr( $value ) ?>"<?php disabled( $disabled, true ) ?> />
     292    <textarea class="<?php echo $class; ?>" name="<?php echo $name; ?>" id="<?php echo $name; ?>" cols="30" rows="5">
     293                                <?php
     294                                echo esc_textarea( $value );
     295    ?>
     296    </textarea>
     297    <?php else : ?>
     298        <input class="regular-text <?php echo $class; ?>" type="text" name="<?php echo $name; ?>" id="<?php echo $name; ?>" value="<?php echo esc_attr( $value ); ?>"<?php disabled( $disabled, true ); ?> />
    287299    <?php endif ?></td>
    288300</tr>
Note: See TracChangeset for help on using the changeset viewer.