web/wp-admin/options.php
changeset 194 32102edaa81b
parent 136 bde1974c263b
child 204 09a1c134465b
equal deleted inserted replaced
193:2f6f6f7551ca 194:32102edaa81b
     1 <?php
     1 <?php
     2 /**
     2 /**
     3  * Options Management Administration Panel.
     3  * Options Management Administration Screen.
     4  *
     4  *
     5  * Just allows for displaying of options.
     5  * If accessed directly in a browser this page shows a list of all saved options
       
     6  * along with editable fields for their values. Serialized data is not supported
       
     7  * and there is no way to remove options via this page. It is not linked to from
       
     8  * anywhere else in the admin.
     6  *
     9  *
     7  * This isn't referenced or linked to, but will show all of the options and
    10  * This file is also the target of the forms in core and custom options pages
     8  * allow editing. The issue is that serialized data is not supported to be
    11  * that use the Settings API. In this case it saves the new option values
     9  * modified. Options can not be removed.
    12  * and returns the user to their page of origin.
    10  *
    13  *
    11  * @package WordPress
    14  * @package WordPress
    12  * @subpackage Administration
    15  * @subpackage Administration
    13  */
    16  */
    14 
    17 
    15 /** WordPress Administration Bootstrap */
    18 /** WordPress Administration Bootstrap */
    16 require_once('admin.php');
    19 require_once('./admin.php');
    17 
    20 
    18 $title = __('Settings');
    21 $title = __('Settings');
    19 $this_file = 'options.php';
    22 $this_file = 'options.php';
    20 $parent_file = 'options-general.php';
    23 $parent_file = 'options-general.php';
    21 
    24 
    22 wp_reset_vars(array('action'));
    25 wp_reset_vars(array('action', 'option_page'));
       
    26 
       
    27 $capability = 'manage_options';
       
    28 
       
    29 if ( empty($option_page) ) // This is for back compat and will eventually be removed.
       
    30 	$option_page = 'options';
       
    31 else
       
    32 	$capability = apply_filters( "option_page_capability_{$option_page}", $capability );
       
    33 
       
    34 if ( !current_user_can( $capability ) )
       
    35 	wp_die(__('Cheatin&#8217; uh?'));
       
    36 
       
    37 // Handle admin email change requests
       
    38 if ( is_multisite() ) {
       
    39 	if ( ! empty($_GET[ 'adminhash' ] ) ) {
       
    40 		$new_admin_details = get_option( 'adminhash' );
       
    41 		$redirect = 'options-general.php?updated=false';
       
    42 		if ( is_array( $new_admin_details ) && $new_admin_details[ 'hash' ] == $_GET[ 'adminhash' ] && !empty($new_admin_details[ 'newemail' ]) ) {
       
    43 			update_option( 'admin_email', $new_admin_details[ 'newemail' ] );
       
    44 			delete_option( 'adminhash' );
       
    45 			delete_option( 'new_admin_email' );
       
    46 			$redirect = 'options-general.php?updated=true';
       
    47 		}
       
    48 		wp_redirect( admin_url( $redirect ) );
       
    49 		exit;
       
    50 	} elseif ( ! empty( $_GET['dismiss'] ) && 'new_admin_email' == $_GET['dismiss'] ) {
       
    51 		delete_option( 'adminhash' );
       
    52 		delete_option( 'new_admin_email' );
       
    53 		wp_redirect( admin_url( 'options-general.php?updated=true' ) );
       
    54 		exit;
       
    55 	}
       
    56 }
       
    57 
       
    58 if ( is_multisite() && !is_super_admin() && 'update' != $action )
       
    59 	wp_die(__('Cheatin&#8217; uh?'));
    23 
    60 
    24 $whitelist_options = array(
    61 $whitelist_options = array(
    25 	'general' => array( 'blogname', 'blogdescription', 'admin_email', 'users_can_register', 'gmt_offset', 'date_format', 'time_format', 'start_of_week', 'default_role', 'timezone_string' ),
    62 	'general' => array( 'blogname', 'blogdescription', 'gmt_offset', 'date_format', 'time_format', 'start_of_week', 'timezone_string' ),
    26 	'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' ),
    63 	'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' ),
    27 	'misc' => array( 'use_linksupdate', 'uploads_use_yearmonth_folders', 'upload_path', 'upload_url_path' ),
       
    28 	'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', 'embed_autourls', 'embed_size_w', 'embed_size_h' ),
    64 	'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', 'embed_autourls', 'embed_size_w', 'embed_size_h' ),
    29 	'privacy' => array( 'blog_public' ),
    65 	'privacy' => array( 'blog_public' ),
    30 	'reading' => array( 'posts_per_page', 'posts_per_rss', 'rss_use_excerpt', 'blog_charset', 'show_on_front', 'page_on_front', 'page_for_posts' ),
    66 	'reading' => array( 'posts_per_page', 'posts_per_rss', 'rss_use_excerpt', 'blog_charset', 'show_on_front', 'page_on_front', 'page_for_posts' ),
    31 	'writing' => array( 'default_post_edit_rows', 'use_smilies', 'ping_sites', 'mailserver_url', 'mailserver_port', 'mailserver_login', 'mailserver_pass', 'default_category', 'default_email_category', 'use_balanceTags', 'default_link_category', 'enable_app', 'enable_xmlrpc' ),
    67 	'writing' => array( 'default_post_edit_rows', 'use_smilies', 'default_category', 'default_email_category', 'use_balanceTags', 'default_link_category', 'default_post_format', 'enable_app', 'enable_xmlrpc' ),
    32 	'options' => array( '' ) );
    68 	'options' => array( '' ) );
    33 if ( !defined( 'WP_SITEURL' ) ) $whitelist_options['general'][] = 'siteurl';
    69 
    34 if ( !defined( 'WP_HOME' ) ) $whitelist_options['general'][] = 'home';
    70 $mail_options = array('mailserver_url', 'mailserver_port', 'mailserver_login', 'mailserver_pass');
       
    71 $uploads_options = array('uploads_use_yearmonth_folders', 'upload_path', 'upload_url_path');
       
    72 
       
    73 if ( !is_multisite() ) {
       
    74 	if ( !defined( 'WP_SITEURL' ) )
       
    75 		$whitelist_options['general'][] = 'siteurl';
       
    76 	if ( !defined( 'WP_HOME' ) )
       
    77 		$whitelist_options['general'][] = 'home';
       
    78 
       
    79 	$whitelist_options['general'][] = 'admin_email';
       
    80 	$whitelist_options['general'][] = 'users_can_register';
       
    81 	$whitelist_options['general'][] = 'default_role';
       
    82 
       
    83 	$whitelist_options['writing'] = array_merge($whitelist_options['writing'], $mail_options);
       
    84 	$whitelist_options['writing'][] = 'ping_sites';
       
    85 
       
    86 	$whitelist_options['media'] = array_merge($whitelist_options['media'], $uploads_options);
       
    87 } else {
       
    88 	$whitelist_options['general'][] = 'new_admin_email';
       
    89 	$whitelist_options['general'][] = 'WPLANG';
       
    90 	$whitelist_options['general'][] = 'language';
       
    91 
       
    92 	if ( apply_filters( 'enable_post_by_email_configuration', true ) )
       
    93 		$whitelist_options['writing'] = array_merge($whitelist_options['writing'], $mail_options);
       
    94 
       
    95 	$whitelist_options[ 'misc' ] = array();
       
    96 }
    35 
    97 
    36 $whitelist_options = apply_filters( 'whitelist_options', $whitelist_options );
    98 $whitelist_options = apply_filters( 'whitelist_options', $whitelist_options );
    37 
    99 
    38 if ( !current_user_can('manage_options') )
   100 /*
    39 	wp_die(__('Cheatin&#8217; uh?'));
   101  * If $_GET['action'] == 'update' we are saving settings sent from a settings page
    40 
   102  */
    41 switch($action) {
   103 if ( 'update' == $action ) {
    42 
   104 	if ( 'options' == $option_page && !isset( $_POST['option_page'] ) ) { // This is for back compat and will eventually be removed.
    43 case 'update':
   105 		$unregistered = true;
    44 	if ( isset($_POST[ 'option_page' ]) ) {
   106 		check_admin_referer( 'update-options' );
    45 		$option_page = $_POST[ 'option_page' ];
   107 	} else {
       
   108 		$unregistered = false;
    46 		check_admin_referer( $option_page . '-options' );
   109 		check_admin_referer( $option_page . '-options' );
    47 	} else {
       
    48 		// This is for back compat and will eventually be removed.
       
    49 		$option_page = 'options';
       
    50 		check_admin_referer( 'update-options' );
       
    51 	}
   110 	}
    52 
   111 
    53 	if ( !isset( $whitelist_options[ $option_page ] ) )
   112 	if ( !isset( $whitelist_options[ $option_page ] ) )
    54 		wp_die( __( 'Error! Options page not found.' ) );
   113 		wp_die( __( '<strong>ERROR</strong>: options page not found.' ) );
    55 
   114 
    56 	if ( 'options' == $option_page ) {
   115 	if ( 'options' == $option_page ) {
    57 		$options = explode(',', stripslashes( $_POST[ 'page_options' ] ));
   116 		if ( is_multisite() && ! is_super_admin() )
       
   117 			wp_die( __( 'You do not have sufficient permissions to modify unregistered settings for this site.' ) );
       
   118 		$options = explode( ',', stripslashes( $_POST[ 'page_options' ] ) );
    58 	} else {
   119 	} else {
    59 		$options = $whitelist_options[ $option_page ];
   120 		$options = $whitelist_options[ $option_page ];
    60 	}
   121 	}
    61 
   122 
    62 	// Handle custom date/time formats
   123 	// Handle custom date/time formats
    73 		}
   134 		}
    74 	}
   135 	}
    75 
   136 
    76 	if ( $options ) {
   137 	if ( $options ) {
    77 		foreach ( $options as $option ) {
   138 		foreach ( $options as $option ) {
       
   139 			if ( $unregistered )
       
   140 				_deprecated_argument( 'options.php', '2.7', sprintf( __( 'The <code>%1$s</code> setting is unregistered. Unregistered settings are deprecated. See http://codex.wordpress.org/Settings_API' ), $option, $option_page ) );
       
   141 
    78 			$option = trim($option);
   142 			$option = trim($option);
    79 			$value = null;
   143 			$value = null;
    80 			if ( isset($_POST[$option]) )
   144 			if ( isset($_POST[$option]) )
    81 				$value = $_POST[$option];
   145 				$value = $_POST[$option];
    82 			if ( !is_array($value) ) $value = trim($value);
   146 			if ( !is_array($value) )
       
   147 				$value = trim($value);
    83 			$value = stripslashes_deep($value);
   148 			$value = stripslashes_deep($value);
    84 			update_option($option, $value);
   149 			update_option($option, $value);
    85 		}
   150 		}
    86 	}
   151 	}
    87 
   152 
    88 	$goback = add_query_arg( 'updated', 'true', wp_get_referer() );
   153 	/**
       
   154 	 * Handle settings errors and return to options page
       
   155 	 */
       
   156 	// If no settings errors were registered add a general 'updated' message.
       
   157 	if ( !count( get_settings_errors() ) )
       
   158 		add_settings_error('general', 'settings_updated', __('Settings saved.'), 'updated');
       
   159 	set_transient('settings_errors', get_settings_errors(), 30);
       
   160 
       
   161 	/**
       
   162 	 * Redirect back to the settings page that was submitted
       
   163 	 */
       
   164 	$goback = add_query_arg( 'settings-updated', 'true',  wp_get_referer() );
    89 	wp_redirect( $goback );
   165 	wp_redirect( $goback );
    90 	break;
   166 	exit;
    91 
   167 }
    92 default:
   168 
    93 	include('admin-header.php'); ?>
   169 include('./admin-header.php'); ?>
    94 
   170 
    95 <div class="wrap">
   171 <div class="wrap">
    96 <?php screen_icon(); ?>
   172 <?php screen_icon(); ?>
    97   <h2><?php _e('All Settings'); ?></h2>
   173   <h2><?php esc_html_e('All Settings'); ?></h2>
    98   <form name="form" action="options.php" method="post" id="all-options">
   174   <form name="form" action="options.php" method="post" id="all-options">
    99   <?php wp_nonce_field('options-options') ?>
   175   <?php wp_nonce_field('options-options') ?>
   100   <input type="hidden" name="action" value="update" />
   176   <input type="hidden" name="action" value="update" />
   101   <input type='hidden' name='option_page' value='options' />
   177   <input type='hidden' name='option_page' value='options' />
   102   <table class="form-table">
   178   <table class="form-table">
   103 <?php
   179 <?php
   104 $options = $wpdb->get_results("SELECT * FROM $wpdb->options ORDER BY option_name");
   180 $options = $wpdb->get_results( "SELECT * FROM $wpdb->options ORDER BY option_name" );
   105 
   181 
   106 foreach ( (array) $options as $option) :
   182 foreach ( (array) $options as $option ) :
   107 	$disabled = '';
   183 	$disabled = false;
   108 	$option->option_name = esc_attr($option->option_name);
   184 	if ( $option->option_name == '' )
   109 	if ( is_serialized($option->option_value) ) {
   185 		continue;
   110 		if ( is_serialized_string($option->option_value) ) {
   186 	if ( is_serialized( $option->option_value ) ) {
       
   187 		if ( is_serialized_string( $option->option_value ) ) {
   111 			// this is a serialized string, so we should display it
   188 			// this is a serialized string, so we should display it
   112 			$value = maybe_unserialize($option->option_value);
   189 			$value = maybe_unserialize( $option->option_value );
   113 			$options_to_update[] = $option->option_name;
   190 			$options_to_update[] = $option->option_name;
   114 			$class = 'all-options';
   191 			$class = 'all-options';
   115 		} else {
   192 		} else {
   116 			$value = 'SERIALIZED DATA';
   193 			$value = 'SERIALIZED DATA';
   117 			$disabled = ' disabled="disabled"';
   194 			$disabled = true;
   118 			$class = 'all-options disabled';
   195 			$class = 'all-options disabled';
   119 		}
   196 		}
   120 	} else {
   197 	} else {
   121 		$value = $option->option_value;
   198 		$value = $option->option_value;
   122 		$options_to_update[] = $option->option_name;
   199 		$options_to_update[] = $option->option_name;
   123 		$class = 'all-options';
   200 		$class = 'all-options';
   124 	}
   201 	}
       
   202 	$name = esc_attr( $option->option_name );
   125 	echo "
   203 	echo "
   126 <tr>
   204 <tr>
   127 	<th scope='row'><label for='$option->option_name'>$option->option_name</label></th>
   205 	<th scope='row'><label for='$name'>" . esc_html( $option->option_name ) . "</label></th>
   128 <td>";
   206 <td>";
   129 
   207 	if ( strpos( $value, "\n" ) !== false )
   130 	if (strpos($value, "\n") !== false) echo "<textarea class='$class' name='$option->option_name' id='$option->option_name' cols='30' rows='5'>" . esc_html($value) . "</textarea>";
   208 		echo "<textarea class='$class' name='$name' id='$name' cols='30' rows='5'>" . esc_textarea( $value ) . "</textarea>";
   131 	else echo "<input class='regular-text $class' type='text' name='$option->option_name' id='$option->option_name' value='" . esc_attr($value) . "'$disabled />";
   209 	else
   132 
   210 		echo "<input class='regular-text $class' type='text' name='$name' id='$name' value='" . esc_attr( $value ) . "'" . disabled( $disabled, true, false ) . " />";
   133 	echo "</td>
   211 	echo "</td>
   134 </tr>";
   212 </tr>";
   135 endforeach;
   213 endforeach;
   136 ?>
   214 ?>
   137   </table>
   215   </table>
   138 <?php $options_to_update = implode(',', $options_to_update); ?>
   216 
   139 <p class="submit"><input type="hidden" name="page_options" value="<?php echo esc_attr($options_to_update); ?>" /><input type="submit" name="Update" value="<?php _e('Save Changes') ?>" class="button-primary" /></p>
   217 <input type="hidden" name="page_options" value="<?php echo esc_attr( implode( ',', $options_to_update ) ); ?>" />
       
   218 
       
   219 <?php submit_button( __( 'Save Changes' ), 'primary', 'Update' ); ?>
       
   220 
   140   </form>
   221   </form>
   141 </div>
   222 </div>
   142 
   223 
   143 
       
   144 <?php
   224 <?php
   145 include('admin-footer.php');
   225 include('./admin-footer.php');
   146 break;
       
   147 } // end switch
       
   148 
       
   149 ?>