<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" /><style type="text/css"><!--
#msg dl { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fc0 solid; padding: 6px; }
#msg ul, pre { overflow: auto; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<title>[13627] trunk/wp-admin/options.php: Cleanup of options.php.</title>
</head>
<body>

<div id="msg">
<dl>
<dt>Revision</dt> <dd><a href="http://trac.wordpress.org/changeset/13627">13627</a></dd>
<dt>Author</dt> <dd>dd32</dd>
<dt>Date</dt> <dd>2010-03-09 10:57:49 +0000 (Tue, 09 Mar 2010)</dd>
</dl>

<h3>Log Message</h3>
<pre>Cleanup of options.php. Adds concise&amp;early wp_die()'s, reformats some poorly chosen branching. See <a href="http://trac.wordpress.org/ticket/12455">#12455</a></pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkwpadminoptionsphp">trunk/wp-admin/options.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkwpadminoptionsphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/options.php (13626 => 13627)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/options.php        2010-03-09 10:53:02 UTC (rev 13626)
+++ trunk/wp-admin/options.php        2010-03-09 10:57:49 UTC (rev 13627)
</span><span class="lines">@@ -22,8 +22,17 @@
</span><span class="cx"> $this_file = 'options.php';
</span><span class="cx"> $parent_file = 'options-general.php';
</span><span class="cx"> 
</span><del>-wp_reset_vars(array('action'));
</del><ins>+wp_reset_vars(array('action', 'option_page'));
</ins><span class="cx"> 
</span><ins>+if ( empty($option_page) ) // This is for back compat and will eventually be removed.
+        $option_page = 'options';
+
+if ( !current_user_can('manage_options') )
+        wp_die(__('Cheatin&amp;#8217; uh?'));
+        
+if ( is_multisite() &amp;&amp; !is_super_admin() &amp;&amp; 'update' != $action )
+        wp_die(__('Cheatin&amp;#8217; uh?'));
+
</ins><span class="cx"> $whitelist_options = array(
</span><span class="cx">         'general' =&gt; array( 'blogname', 'blogdescription', 'gmt_offset', 'date_format', 'time_format', 'start_of_week', 'timezone_string' ),
</span><span class="cx">         'discussion' =&gt; 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' ),
</span><span class="lines">@@ -38,8 +47,11 @@
</span><span class="cx"> $uploads_options = array('uploads_use_yearmonth_folders', 'upload_path', 'upload_url_path');
</span><span class="cx"> 
</span><span class="cx"> if ( !is_multisite() ) {
</span><del>-        if ( !defined( 'WP_SITEURL' ) ) $whitelist_options['general'][] = 'siteurl';
-        if ( !defined( 'WP_HOME' ) ) $whitelist_options['general'][] = 'home';
</del><ins>+        if ( !defined( 'WP_SITEURL' ) )
+                $whitelist_options['general'][] = 'siteurl';
+        if ( !defined( 'WP_HOME' ) )
+                $whitelist_options['general'][] = 'home';
+
</ins><span class="cx">         $whitelist_options['general'][] = 'admin_email';
</span><span class="cx">         $whitelist_options['general'][] = 'users_can_register';
</span><span class="cx">         $whitelist_options['general'][] = 'default_role';
</span><span class="lines">@@ -55,7 +67,7 @@
</span><span class="cx"> 
</span><span class="cx">         $whitelist_options[ 'misc' ] = array();
</span><span class="cx"> 
</span><del>-        if ( defined( 'POST_BY_EMAIL' ) )
</del><ins>+        if ( apply_filters( 'enable_post_by_email_configuration', true ) )
</ins><span class="cx">                 $whitelist_options['writing'] = array_merge($whitelist_options['writing'], $mail_options);
</span><span class="cx"> 
</span><span class="cx">         $whitelist_options[ 'misc' ] = array();
</span><span class="lines">@@ -63,48 +75,35 @@
</span><span class="cx"> 
</span><span class="cx"> $whitelist_options = apply_filters( 'whitelist_options', $whitelist_options );
</span><span class="cx"> 
</span><del>-if ( !current_user_can('manage_options') )
-        wp_die(__('Cheatin&amp;#8217; uh?'));
-
-if ( is_multisite() &amp;&amp; is_super_admin() &amp;&amp; isset($_GET[ 'adminhash' ]) &amp;&amp; $_GET[ 'adminhash' ] ) {
</del><ins>+if ( is_multisite() &amp;&amp; is_super_admin() &amp;&amp; !empty($_GET[ 'adminhash' ]) ) {
</ins><span class="cx">         $new_admin_details = get_option( 'adminhash' );
</span><del>-        if ( is_array( $new_admin_details ) &amp;&amp; $new_admin_details[ 'hash' ] == $_GET[ 'adminhash' ] &amp;&amp; $new_admin_details[ 'newemail' ] != '' ) {
-                update_option( &quot;admin_email&quot;, $new_admin_details[ 'newemail' ] );
-                delete_option( &quot;adminhash&quot; );
-                delete_option( &quot;new_admin_email&quot; );
-                wp_redirect( get_option( &quot;siteurl&quot; ) . &quot;/wp-admin/options-general.php?updated=true&quot; );
-                exit;
-        } else {
-                wp_redirect( get_option( &quot;siteurl&quot; ) . &quot;/wp-admin/options-general.php?updated=false&quot; );
-                exit;
</del><ins>+        $redirect = admin_url('options-general.php?updated=false');
+        if ( is_array( $new_admin_details ) &amp;&amp; $new_admin_details[ 'hash' ] == $_GET[ 'adminhash' ] &amp;&amp; !empty($new_admin_details[ 'newemail' ]) ) {
+                update_option( 'admin_email', $new_admin_details[ 'newemail' ] );
+                delete_option( 'adminhash' );
+                delete_option( 'new_admin_email' );
+                $redirect = admin_url('options-general.php?updated=true');
</ins><span class="cx">         }
</span><ins>+        wp_redirect( $redirect);
+        exit;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><del>-switch($action) {
-
</del><span class="cx"> /**
</span><span class="cx">  * If $_GET['action'] == 'update' we are saving settings sent from a settings page
</span><span class="cx">  */
</span><del>-case 'update':
-        if ( isset($_POST[ 'option_page' ]) ) {
-                $option_page = $_POST[ 'option_page' ];
-                check_admin_referer( $option_page . '-options' );
-        } else {
-                // This is for back compat and will eventually be removed.
-                $option_page = 'options';
</del><ins>+if ( 'update' == $action ) {
+        if ( 'options' == $option_page &amp;&amp; !isset($_POST['option_page']) ) // This is for back compat and will eventually be removed.
</ins><span class="cx">                 check_admin_referer( 'update-options' );
</span><del>-        }
</del><ins>+        else
+                check_admin_referer( $option_page . '-options' );
</ins><span class="cx"> 
</span><span class="cx">         if ( !isset( $whitelist_options[ $option_page ] ) )
</span><span class="cx">                 wp_die( __( 'Error: options page not found.' ) );
</span><span class="cx"> 
</span><del>-        if ( 'options' == $option_page ) {
</del><ins>+        if ( 'options' == $option_page )
</ins><span class="cx">                 $options = explode(',', stripslashes( $_POST[ 'page_options' ] ));
</span><del>-                if ( !is_super_admin() )
-                        wp_die( __( 'Not allowed here' ) );
-        } else {
</del><ins>+        else
</ins><span class="cx">                 $options = $whitelist_options[ $option_page ];
</span><del>-        }
</del><span class="cx"> 
</span><span class="cx">         // Handle custom date/time formats
</span><span class="cx">         if ( 'general' == $option_page ) {
</span><span class="lines">@@ -126,7 +125,8 @@
</span><span class="cx">                         $value = null;
</span><span class="cx">                         if ( isset($_POST[$option]) )
</span><span class="cx">                                 $value = $_POST[$option];
</span><del>-                        if ( !is_array($value) ) $value = trim($value);
</del><ins>+                        if ( !is_array($value) )
+                                $value = trim($value);
</ins><span class="cx">                         $value = stripslashes_deep($value);
</span><span class="cx">                         update_option($option, $value);
</span><span class="cx">                 }
</span><span class="lines">@@ -145,14 +145,11 @@
</span><span class="cx">          */
</span><span class="cx">         $goback = add_query_arg( 'updated', 'true',  wp_get_referer() );
</span><span class="cx">         wp_redirect( $goback );
</span><del>-        break;
</del><ins>+        exit;
+}
</ins><span class="cx"> 
</span><del>-default:
-        if ( !is_super_admin() )
-                wp_die( __( 'Not admin' ) );
</del><ins>+include('admin-header.php'); ?&gt;
</ins><span class="cx"> 
</span><del>-        include('admin-header.php'); ?&gt;
-
</del><span class="cx"> &lt;div class=&quot;wrap&quot;&gt;
</span><span class="cx"> &lt;?php screen_icon(); ?&gt;
</span><span class="cx">   &lt;h2&gt;&lt;?php esc_html_e('All Settings'); ?&gt;&lt;/h2&gt;
</span><span class="lines">@@ -205,7 +202,4 @@
</span><span class="cx"> 
</span><span class="cx"> &lt;?php
</span><span class="cx"> include('admin-footer.php');
</span><del>-break;
-} // end switch
-
</del><span class="cx"> ?&gt;
</span></span></pre>
</div>
</div>

</body>
</html>