wp/wp-admin/options.php
changeset 9 177826044cd9
parent 7 cf61fcea0001
child 16 a86126ab1dd4
equal deleted inserted replaced
8:c7c34916027a 9:177826044cd9
    16  */
    16  */
    17 
    17 
    18 /** WordPress Administration Bootstrap */
    18 /** WordPress Administration Bootstrap */
    19 require_once( dirname( __FILE__ ) . '/admin.php' );
    19 require_once( dirname( __FILE__ ) . '/admin.php' );
    20 
    20 
    21 $title = __('Settings');
    21 $title       = __( 'Settings' );
    22 $this_file = 'options.php';
    22 $this_file   = 'options.php';
    23 $parent_file = 'options-general.php';
    23 $parent_file = 'options-general.php';
    24 
    24 
    25 wp_reset_vars(array('action', 'option_page'));
    25 wp_reset_vars( array( 'action', 'option_page' ) );
    26 
    26 
    27 $capability = 'manage_options';
    27 $capability = 'manage_options';
    28 
    28 
    29 // This is for back compat and will eventually be removed.
    29 // This is for back compat and will eventually be removed.
    30 if ( empty($option_page) ) {
    30 if ( empty( $option_page ) ) {
    31 	$option_page = 'options';
    31 	$option_page = 'options';
    32 } else {
    32 } else {
    33 
    33 
    34 	/**
    34 	/**
    35 	 * Filters the capability required when using the Settings API.
    35 	 * Filters the capability required when using the Settings API.
    51 		403
    51 		403
    52 	);
    52 	);
    53 }
    53 }
    54 
    54 
    55 // Handle admin email change requests
    55 // Handle admin email change requests
    56 if ( ! empty( $_GET[ 'adminhash' ] ) ) {
    56 if ( ! empty( $_GET['adminhash'] ) ) {
    57 	$new_admin_details = get_option( 'adminhash' );
    57 	$new_admin_details = get_option( 'adminhash' );
    58 	$redirect = 'options-general.php?updated=false';
    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' ] ) ) {
    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' ] );
    60 		update_option( 'admin_email', $new_admin_details['newemail'] );
    61 		delete_option( 'adminhash' );
    61 		delete_option( 'adminhash' );
    62 		delete_option( 'new_admin_email' );
    62 		delete_option( 'new_admin_email' );
    63 		$redirect = 'options-general.php?updated=true';
    63 		$redirect = 'options-general.php?updated=true';
    64 	}
    64 	}
    65 	wp_redirect( admin_url( $redirect ) );
    65 	wp_redirect( admin_url( $redirect ) );
    78 		'<p>' . __( 'Sorry, you are not allowed to delete these items.' ) . '</p>',
    78 		'<p>' . __( 'Sorry, you are not allowed to delete these items.' ) . '</p>',
    79 		403
    79 		403
    80 	);
    80 	);
    81 }
    81 }
    82 
    82 
    83 $whitelist_options = array(
    83 $whitelist_options         = array(
    84 	'general' => array(
    84 	'general'    => array(
    85 		'blogname',
    85 		'blogname',
    86 		'blogdescription',
    86 		'blogdescription',
    87 		'gmt_offset',
    87 		'gmt_offset',
    88 		'date_format',
    88 		'date_format',
    89 		'time_format',
    89 		'time_format',
   116 		'default_comments_page',
   116 		'default_comments_page',
   117 		'comment_order',
   117 		'comment_order',
   118 		'comment_registration',
   118 		'comment_registration',
   119 		'show_comments_cookies_opt_in',
   119 		'show_comments_cookies_opt_in',
   120 	),
   120 	),
   121 	'media' => array(
   121 	'media'      => array(
   122 		'thumbnail_size_w',
   122 		'thumbnail_size_w',
   123 		'thumbnail_size_h',
   123 		'thumbnail_size_h',
   124 		'thumbnail_crop',
   124 		'thumbnail_crop',
   125 		'medium_size_w',
   125 		'medium_size_w',
   126 		'medium_size_h',
   126 		'medium_size_h',
   128 		'large_size_h',
   128 		'large_size_h',
   129 		'image_default_size',
   129 		'image_default_size',
   130 		'image_default_align',
   130 		'image_default_align',
   131 		'image_default_link_type',
   131 		'image_default_link_type',
   132 	),
   132 	),
   133 	'reading' => array(
   133 	'reading'    => array(
   134 		'posts_per_page',
   134 		'posts_per_page',
   135 		'posts_per_rss',
   135 		'posts_per_rss',
   136 		'rss_use_excerpt',
   136 		'rss_use_excerpt',
   137 		'show_on_front',
   137 		'show_on_front',
   138 		'page_on_front',
   138 		'page_on_front',
   139 		'page_for_posts',
   139 		'page_for_posts',
   140 		'blog_public',
   140 		'blog_public',
   141 	),
   141 	),
   142 	'writing' => array(
   142 	'writing'    => array(
   143 		'default_category',
   143 		'default_category',
   144 		'default_email_category',
   144 		'default_email_category',
   145 		'default_link_category',
   145 		'default_link_category',
   146 		'default_post_format',
   146 		'default_post_format',
   147 	),
   147 	),
   148 );
   148 );
   149 $whitelist_options['misc'] = $whitelist_options['options'] = $whitelist_options['privacy'] = array();
   149 $whitelist_options['misc'] = $whitelist_options['options'] = $whitelist_options['privacy'] = array();
   150 
   150 
   151 $mail_options = array('mailserver_url', 'mailserver_port', 'mailserver_login', 'mailserver_pass');
   151 $mail_options = array( 'mailserver_url', 'mailserver_port', 'mailserver_login', 'mailserver_pass' );
   152 
   152 
   153 if ( ! in_array( get_option( 'blog_charset' ), array( 'utf8', 'utf-8', 'UTF8', 'UTF-8' ) ) )
   153 if ( ! in_array( get_option( 'blog_charset' ), array( 'utf8', 'utf-8', 'UTF8', 'UTF-8' ) ) ) {
   154 	$whitelist_options['reading'][] = 'blog_charset';
   154 	$whitelist_options['reading'][] = 'blog_charset';
       
   155 }
   155 
   156 
   156 if ( get_site_option( 'initial_db_version' ) < 32453 ) {
   157 if ( get_site_option( 'initial_db_version' ) < 32453 ) {
   157 	$whitelist_options['writing'][] = 'use_smilies';
   158 	$whitelist_options['writing'][] = 'use_smilies';
   158 	$whitelist_options['writing'][] = 'use_balanceTags';
   159 	$whitelist_options['writing'][] = 'use_balanceTags';
   159 }
   160 }
   160 
   161 
   161 if ( !is_multisite() ) {
   162 if ( ! is_multisite() ) {
   162 	if ( !defined( 'WP_SITEURL' ) )
   163 	if ( ! defined( 'WP_SITEURL' ) ) {
   163 		$whitelist_options['general'][] = 'siteurl';
   164 		$whitelist_options['general'][] = 'siteurl';
   164 	if ( !defined( 'WP_HOME' ) )
   165 	}
       
   166 	if ( ! defined( 'WP_HOME' ) ) {
   165 		$whitelist_options['general'][] = 'home';
   167 		$whitelist_options['general'][] = 'home';
       
   168 	}
   166 
   169 
   167 	$whitelist_options['general'][] = 'users_can_register';
   170 	$whitelist_options['general'][] = 'users_can_register';
   168 	$whitelist_options['general'][] = 'default_role';
   171 	$whitelist_options['general'][] = 'default_role';
   169 
   172 
   170 	$whitelist_options['writing'] = array_merge($whitelist_options['writing'], $mail_options);
   173 	$whitelist_options['writing']   = array_merge( $whitelist_options['writing'], $mail_options );
   171 	$whitelist_options['writing'][] = 'ping_sites';
   174 	$whitelist_options['writing'][] = 'ping_sites';
   172 
   175 
   173 	$whitelist_options['media'][] = 'uploads_use_yearmonth_folders';
   176 	$whitelist_options['media'][] = 'uploads_use_yearmonth_folders';
   174 
   177 
   175 	// If upload_url_path and upload_path are both default values, they're locked.
   178 	// If upload_url_path and upload_path are both default values, they're locked.
   176 	if ( get_option( 'upload_url_path' ) || ( get_option('upload_path') != 'wp-content/uploads' && get_option('upload_path') ) ) {
   179 	if ( get_option( 'upload_url_path' ) || ( get_option( 'upload_path' ) != 'wp-content/uploads' && get_option( 'upload_path' ) ) ) {
   177 		$whitelist_options['media'][] = 'upload_path';
   180 		$whitelist_options['media'][] = 'upload_path';
   178 		$whitelist_options['media'][] = 'upload_url_path';
   181 		$whitelist_options['media'][] = 'upload_url_path';
   179 	}
   182 	}
   180 } else {
   183 } else {
   181 	/**
   184 	/**
   183 	 *
   186 	 *
   184 	 * @since 3.0.0
   187 	 * @since 3.0.0
   185 	 *
   188 	 *
   186 	 * @param bool $enabled Whether post-by-email configuration is enabled. Default true.
   189 	 * @param bool $enabled Whether post-by-email configuration is enabled. Default true.
   187 	 */
   190 	 */
   188 	if ( apply_filters( 'enable_post_by_email_configuration', true ) )
   191 	if ( apply_filters( 'enable_post_by_email_configuration', true ) ) {
   189 		$whitelist_options['writing'] = array_merge($whitelist_options['writing'], $mail_options);
   192 		$whitelist_options['writing'] = array_merge( $whitelist_options['writing'], $mail_options );
       
   193 	}
   190 }
   194 }
   191 
   195 
   192 /**
   196 /**
   193  * Filters the options white list.
   197  * Filters the options white list.
   194  *
   198  *
   200 
   204 
   201 /*
   205 /*
   202  * If $_GET['action'] == 'update' we are saving settings sent from a settings page
   206  * If $_GET['action'] == 'update' we are saving settings sent from a settings page
   203  */
   207  */
   204 if ( 'update' == $action ) {
   208 if ( 'update' == $action ) {
   205 	if ( 'options' == $option_page && !isset( $_POST['option_page'] ) ) { // This is for back compat and will eventually be removed.
   209 	if ( 'options' == $option_page && ! isset( $_POST['option_page'] ) ) { // This is for back compat and will eventually be removed.
   206 		$unregistered = true;
   210 		$unregistered = true;
   207 		check_admin_referer( 'update-options' );
   211 		check_admin_referer( 'update-options' );
   208 	} else {
   212 	} else {
   209 		$unregistered = false;
   213 		$unregistered = false;
   210 		check_admin_referer( $option_page . '-options' );
   214 		check_admin_referer( $option_page . '-options' );
   211 	}
   215 	}
   212 
   216 
   213 	if ( !isset( $whitelist_options[ $option_page ] ) )
   217 	if ( ! isset( $whitelist_options[ $option_page ] ) ) {
   214 		wp_die( __( '<strong>ERROR</strong>: options page not found.' ) );
   218 		wp_die( __( '<strong>ERROR</strong>: options page not found.' ) );
       
   219 	}
   215 
   220 
   216 	if ( 'options' == $option_page ) {
   221 	if ( 'options' == $option_page ) {
   217 		if ( is_multisite() && ! current_user_can( 'manage_network_options' ) ) {
   222 		if ( is_multisite() && ! current_user_can( 'manage_network_options' ) ) {
   218 			wp_die( __( 'Sorry, you are not allowed to modify unregistered settings for this site.' ) );
   223 			wp_die( __( 'Sorry, you are not allowed to modify unregistered settings for this site.' ) );
   219 		}
   224 		}
   220 		$options = explode( ',', wp_unslash( $_POST[ 'page_options' ] ) );
   225 		$options = explode( ',', wp_unslash( $_POST['page_options'] ) );
   221 	} else {
   226 	} else {
   222 		$options = $whitelist_options[ $option_page ];
   227 		$options = $whitelist_options[ $option_page ];
   223 	}
   228 	}
   224 
   229 
   225 	if ( 'general' == $option_page ) {
   230 	if ( 'general' == $option_page ) {
   226 		// Handle custom date/time formats.
   231 		// Handle custom date/time formats.
   227 		if ( !empty($_POST['date_format']) && isset($_POST['date_format_custom']) && '\c\u\s\t\o\m' == wp_unslash( $_POST['date_format'] ) )
   232 		if ( ! empty( $_POST['date_format'] ) && isset( $_POST['date_format_custom'] ) && '\c\u\s\t\o\m' == wp_unslash( $_POST['date_format'] ) ) {
   228 			$_POST['date_format'] = $_POST['date_format_custom'];
   233 			$_POST['date_format'] = $_POST['date_format_custom'];
   229 		if ( !empty($_POST['time_format']) && isset($_POST['time_format_custom']) && '\c\u\s\t\o\m' == wp_unslash( $_POST['time_format'] ) )
   234 		}
       
   235 		if ( ! empty( $_POST['time_format'] ) && isset( $_POST['time_format_custom'] ) && '\c\u\s\t\o\m' == wp_unslash( $_POST['time_format'] ) ) {
   230 			$_POST['time_format'] = $_POST['time_format_custom'];
   236 			$_POST['time_format'] = $_POST['time_format_custom'];
       
   237 		}
   231 		// Map UTC+- timezones to gmt_offsets and set timezone_string to empty.
   238 		// Map UTC+- timezones to gmt_offsets and set timezone_string to empty.
   232 		if ( !empty($_POST['timezone_string']) && preg_match('/^UTC[+-]/', $_POST['timezone_string']) ) {
   239 		if ( ! empty( $_POST['timezone_string'] ) && preg_match( '/^UTC[+-]/', $_POST['timezone_string'] ) ) {
   233 			$_POST['gmt_offset'] = $_POST['timezone_string'];
   240 			$_POST['gmt_offset']      = $_POST['timezone_string'];
   234 			$_POST['gmt_offset'] = preg_replace('/UTC\+?/', '', $_POST['gmt_offset']);
   241 			$_POST['gmt_offset']      = preg_replace( '/UTC\+?/', '', $_POST['gmt_offset'] );
   235 			$_POST['timezone_string'] = '';
   242 			$_POST['timezone_string'] = '';
   236 		}
   243 		}
   237 
   244 
   238 		// Handle translation installation.
   245 		// Handle translation installation.
   239 		if ( ! empty( $_POST['WPLANG'] ) && current_user_can( 'install_languages' ) ) {
   246 		if ( ! empty( $_POST['WPLANG'] ) && current_user_can( 'install_languages' ) ) {
   251 	if ( $options ) {
   258 	if ( $options ) {
   252 		$user_language_old = get_user_locale();
   259 		$user_language_old = get_user_locale();
   253 
   260 
   254 		foreach ( $options as $option ) {
   261 		foreach ( $options as $option ) {
   255 			if ( $unregistered ) {
   262 			if ( $unregistered ) {
   256 				_deprecated_argument( 'options.php', '2.7.0',
   263 				_deprecated_argument(
       
   264 					'options.php',
       
   265 					'2.7.0',
   257 					sprintf(
   266 					sprintf(
   258 						/* translators: %s: the option/setting */
   267 						/* translators: %s: the option/setting */
   259 						__( 'The %s setting is unregistered. Unregistered settings are deprecated. See https://codex.wordpress.org/Settings_API' ),
   268 						__( 'The %s setting is unregistered. Unregistered settings are deprecated. See https://codex.wordpress.org/Settings_API' ),
   260 						'<code>' . $option . '</code>'
   269 						'<code>' . $option . '</code>'
   261 					)
   270 					)
   262 				);
   271 				);
   263 			}
   272 			}
   264 
   273 
   265 			$option = trim( $option );
   274 			$option = trim( $option );
   266 			$value = null;
   275 			$value  = null;
   267 			if ( isset( $_POST[ $option ] ) ) {
   276 			if ( isset( $_POST[ $option ] ) ) {
   268 				$value = $_POST[ $option ];
   277 				$value = $_POST[ $option ];
   269 				if ( ! is_array( $value ) ) {
   278 				if ( ! is_array( $value ) ) {
   270 					$value = trim( $value );
   279 					$value = trim( $value );
   271 				}
   280 				}
   279 		 * The global $locale is used in get_locale() which is
   288 		 * The global $locale is used in get_locale() which is
   280 		 * used as a fallback in get_user_locale().
   289 		 * used as a fallback in get_user_locale().
   281 		 */
   290 		 */
   282 		unset( $GLOBALS['locale'] );
   291 		unset( $GLOBALS['locale'] );
   283 		$user_language_new = get_user_locale();
   292 		$user_language_new = get_user_locale();
   284 		if ( $user_language_old !== $user_language_new  ) {
   293 		if ( $user_language_old !== $user_language_new ) {
   285 			load_default_textdomain( $user_language_new );
   294 			load_default_textdomain( $user_language_new );
   286 		}
   295 		}
   287 	}
   296 	}
   288 
   297 
   289 	/**
   298 	/**
   290 	 * Handle settings errors and return to options page
   299 	 * Handle settings errors and return to options page
   291 	 */
   300 	 */
   292 	// If no settings errors were registered add a general 'updated' message.
   301 	// If no settings errors were registered add a general 'updated' message.
   293 	if ( !count( get_settings_errors() ) )
   302 	if ( ! count( get_settings_errors() ) ) {
   294 		add_settings_error('general', 'settings_updated', __('Settings saved.'), 'updated');
   303 		add_settings_error( 'general', 'settings_updated', __( 'Settings saved.' ), 'updated' );
   295 	set_transient('settings_errors', get_settings_errors(), 30);
   304 	}
       
   305 	set_transient( 'settings_errors', get_settings_errors(), 30 );
   296 
   306 
   297 	/**
   307 	/**
   298 	 * Redirect back to the settings page that was submitted
   308 	 * Redirect back to the settings page that was submitted
   299 	 */
   309 	 */
   300 	$goback = add_query_arg( 'settings-updated', 'true',  wp_get_referer() );
   310 	$goback = add_query_arg( 'settings-updated', 'true', wp_get_referer() );
   301 	wp_redirect( $goback );
   311 	wp_redirect( $goback );
   302 	exit;
   312 	exit;
   303 }
   313 }
   304 
   314 
   305 include( ABSPATH . 'wp-admin/admin-header.php' ); ?>
   315 include( ABSPATH . 'wp-admin/admin-header.php' ); ?>
   306 
   316 
   307 <div class="wrap">
   317 <div class="wrap">
   308   <h1><?php esc_html_e( 'All Settings' ); ?></h1>
   318 	<h1><?php esc_html_e( 'All Settings' ); ?></h1>
   309   <form name="form" action="options.php" method="post" id="all-options">
   319 	<form name="form" action="options.php" method="post" id="all-options">
   310   <?php wp_nonce_field('options-options') ?>
   320 		<?php wp_nonce_field( 'options-options' ); ?>
   311   <input type="hidden" name="action" value="update" />
   321 		<input type="hidden" name="action" value="update" />
   312   <input type="hidden" name="option_page" value="options" />
   322 		<input type="hidden" name="option_page" value="options" />
   313   <table class="form-table">
   323 		<table class="form-table" role="presentation">
   314 <?php
   324 <?php
   315 $options = $wpdb->get_results( "SELECT * FROM $wpdb->options ORDER BY option_name" );
   325 $options = $wpdb->get_results( "SELECT * FROM $wpdb->options ORDER BY option_name" );
   316 
   326 
   317 foreach ( (array) $options as $option ) :
   327 foreach ( (array) $options as $option ) :
   318 	$disabled = false;
   328 	$disabled = false;
   319 	if ( $option->option_name == '' )
   329 	if ( $option->option_name == '' ) {
   320 		continue;
   330 		continue;
       
   331 	}
   321 	if ( is_serialized( $option->option_value ) ) {
   332 	if ( is_serialized( $option->option_value ) ) {
   322 		if ( is_serialized_string( $option->option_value ) ) {
   333 		if ( is_serialized_string( $option->option_value ) ) {
   323 			// This is a serialized string, so we should display it.
   334 			// This is a serialized string, so we should display it.
   324 			$value = maybe_unserialize( $option->option_value );
   335 			$value               = maybe_unserialize( $option->option_value );
   325 			$options_to_update[] = $option->option_name;
   336 			$options_to_update[] = $option->option_name;
   326 			$class = 'all-options';
   337 			$class               = 'all-options';
   327 		} else {
   338 		} else {
   328 			$value = 'SERIALIZED DATA';
   339 			$value    = 'SERIALIZED DATA';
   329 			$disabled = true;
   340 			$disabled = true;
   330 			$class = 'all-options disabled';
   341 			$class    = 'all-options disabled';
   331 		}
   342 		}
   332 	} else {
   343 	} else {
   333 		$value = $option->option_value;
   344 		$value               = $option->option_value;
   334 		$options_to_update[] = $option->option_name;
   345 		$options_to_update[] = $option->option_name;
   335 		$class = 'all-options';
   346 		$class               = 'all-options';
   336 	}
   347 	}
   337 	$name = esc_attr( $option->option_name );
   348 	$name = esc_attr( $option->option_name );
   338 	?>
   349 	?>
   339 <tr>
   350 <tr>
   340 	<th scope="row"><label for="<?php echo $name ?>"><?php echo esc_html( $option->option_name ); ?></label></th>
   351 	<th scope="row"><label for="<?php echo $name; ?>"><?php echo esc_html( $option->option_name ); ?></label></th>
   341 <td>
   352 <td>
   342 <?php if ( strpos( $value, "\n" ) !== false ) : ?>
   353 	<?php if ( strpos( $value, "\n" ) !== false ) : ?>
   343 	<textarea class="<?php echo $class ?>" name="<?php echo $name ?>" id="<?php echo $name ?>" cols="30" rows="5"><?php
   354 		<textarea class="<?php echo $class; ?>" name="<?php echo $name; ?>" id="<?php echo $name; ?>" cols="30" rows="5"><?php echo esc_textarea( $value ); ?></textarea>
   344 		echo esc_textarea( $value );
   355 	<?php else : ?>
   345 	?></textarea>
   356 		<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 ); ?> />
   346 	<?php else: ?>
       
   347 		<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 ) ?> />
       
   348 	<?php endif ?></td>
   357 	<?php endif ?></td>
   349 </tr>
   358 </tr>
   350 <?php endforeach; ?>
   359 <?php endforeach; ?>
   351   </table>
   360 </table>
   352 
   361 
   353 <input type="hidden" name="page_options" value="<?php echo esc_attr( implode( ',', $options_to_update ) ); ?>" />
   362 <input type="hidden" name="page_options" value="<?php echo esc_attr( implode( ',', $options_to_update ) ); ?>" />
   354 
   363 
   355 <?php submit_button( __( 'Save Changes' ), 'primary', 'Update' ); ?>
   364 <?php submit_button( __( 'Save Changes' ), 'primary', 'Update' ); ?>
   356 
   365 
   357   </form>
   366 </form>
   358 </div>
   367 </div>
   359 
   368 
   360 <?php
   369 <?php
   361 include( ABSPATH . 'wp-admin/admin-footer.php' );
   370 include( ABSPATH . 'wp-admin/admin-footer.php' );