Make WordPress Core

Changeset 13627


Ignore:
Timestamp:
03/09/2010 10:57:49 AM (15 years ago)
Author:
dd32
Message:

Cleanup of options.php. Adds concise&early wp_die()'s, reformats some poorly chosen branching. See #12455

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/options.php

    r13545 r13627  
    2323$parent_file = 'options-general.php';
    2424
    25 wp_reset_vars(array('action'));
     25wp_reset_vars(array('action', 'option_page'));
     26
     27if ( empty($option_page) ) // This is for back compat and will eventually be removed.
     28    $option_page = 'options';
     29
     30if ( !current_user_can('manage_options') )
     31    wp_die(__('Cheatin’ uh?'));
     32   
     33if ( is_multisite() && !is_super_admin() && 'update' != $action )
     34    wp_die(__('Cheatin’ uh?'));
    2635
    2736$whitelist_options = array(
     
    3948
    4049if ( !is_multisite() ) {
    41     if ( !defined( 'WP_SITEURL' ) ) $whitelist_options['general'][] = 'siteurl';
    42     if ( !defined( 'WP_HOME' ) ) $whitelist_options['general'][] = 'home';
     50    if ( !defined( 'WP_SITEURL' ) )
     51        $whitelist_options['general'][] = 'siteurl';
     52    if ( !defined( 'WP_HOME' ) )
     53        $whitelist_options['general'][] = 'home';
     54
    4355    $whitelist_options['general'][] = 'admin_email';
    4456    $whitelist_options['general'][] = 'users_can_register';
     
    5668    $whitelist_options[ 'misc' ] = array();
    5769
    58     if ( defined( 'POST_BY_EMAIL' ) )
     70    if ( apply_filters( 'enable_post_by_email_configuration', true ) )
    5971        $whitelist_options['writing'] = array_merge($whitelist_options['writing'], $mail_options);
    6072
     
    6476$whitelist_options = apply_filters( 'whitelist_options', $whitelist_options );
    6577
    66 if ( !current_user_can('manage_options') )
    67     wp_die(__('Cheatin’ uh?'));
    68 
    69 if ( is_multisite() && is_super_admin() && isset($_GET[ 'adminhash' ]) && $_GET[ 'adminhash' ] ) {
     78if ( is_multisite() && is_super_admin() && !empty($_GET[ 'adminhash' ]) ) {
    7079    $new_admin_details = get_option( 'adminhash' );
    71     if ( is_array( $new_admin_details ) && $new_admin_details[ 'hash' ] == $_GET[ 'adminhash' ] && $new_admin_details[ 'newemail' ] != '' ) {
    72         update_option( "admin_email", $new_admin_details[ 'newemail' ] );
    73         delete_option( "adminhash" );
    74         delete_option( "new_admin_email" );
    75         wp_redirect( get_option( "siteurl" ) . "/wp-admin/options-general.php?updated=true" );
    76         exit;
    77     } else {
    78         wp_redirect( get_option( "siteurl" ) . "/wp-admin/options-general.php?updated=false" );
    79         exit;
    80     }
     80    $redirect = admin_url('options-general.php?updated=false');
     81    if ( is_array( $new_admin_details ) && $new_admin_details[ 'hash' ] == $_GET[ 'adminhash' ] && !empty($new_admin_details[ 'newemail' ]) ) {
     82        update_option( 'admin_email', $new_admin_details[ 'newemail' ] );
     83        delete_option( 'adminhash' );
     84        delete_option( 'new_admin_email' );
     85        $redirect = admin_url('options-general.php?updated=true');
     86    }
     87    wp_redirect( $redirect);
     88    exit;
    8189}
    82 
    83 switch($action) {
    8490
    8591/**
    8692 * If $_GET['action'] == 'update' we are saving settings sent from a settings page
    8793 */
    88 case 'update':
    89     if ( isset($_POST[ 'option_page' ]) ) {
    90         $option_page = $_POST[ 'option_page' ];
     94if ( 'update' == $action ) {
     95    if ( 'options' == $option_page && !isset($_POST['option_page']) ) // This is for back compat and will eventually be removed.
     96        check_admin_referer( 'update-options' );
     97    else
    9198        check_admin_referer( $option_page . '-options' );
    92     } else {
    93         // This is for back compat and will eventually be removed.
    94         $option_page = 'options';
    95         check_admin_referer( 'update-options' );
    96     }
    9799
    98100    if ( !isset( $whitelist_options[ $option_page ] ) )
    99101        wp_die( __( 'Error: options page not found.' ) );
    100102
    101     if ( 'options' == $option_page ) {
     103    if ( 'options' == $option_page )
    102104        $options = explode(',', stripslashes( $_POST[ 'page_options' ] ));
    103         if ( !is_super_admin() )
    104             wp_die( __( 'Not allowed here' ) );
    105     } else {
     105    else
    106106        $options = $whitelist_options[ $option_page ];
    107     }
    108107
    109108    // Handle custom date/time formats
     
    127126            if ( isset($_POST[$option]) )
    128127                $value = $_POST[$option];
    129             if ( !is_array($value) ) $value = trim($value);
     128            if ( !is_array($value) )
     129                $value = trim($value);
    130130            $value = stripslashes_deep($value);
    131131            update_option($option, $value);
     
    146146    $goback = add_query_arg( 'updated', 'true',  wp_get_referer() );
    147147    wp_redirect( $goback );
    148     break;
    149 
    150 default:
    151     if ( !is_super_admin() )
    152         wp_die( __( 'Not admin' ) );
    153 
    154     include('admin-header.php'); ?>
     148    exit;
     149}
     150
     151include('admin-header.php'); ?>
    155152
    156153<div class="wrap">
     
    206203<?php
    207204include('admin-footer.php');
    208 break;
    209 } // end switch
    210 
    211205?>
Note: See TracChangeset for help on using the changeset viewer.