wp/wp-admin/options.php
changeset 16 a86126ab1dd4
parent 9 177826044cd9
child 18 be944660c56a
equal deleted inserted replaced
15:3d4e9c994f10 16:a86126ab1dd4
    14  * @package WordPress
    14  * @package WordPress
    15  * @subpackage Administration
    15  * @subpackage Administration
    16  */
    16  */
    17 
    17 
    18 /** WordPress Administration Bootstrap */
    18 /** WordPress Administration Bootstrap */
    19 require_once( dirname( __FILE__ ) . '/admin.php' );
    19 require_once __DIR__ . '/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 
    45 }
    45 }
    46 
    46 
    47 if ( ! current_user_can( $capability ) ) {
    47 if ( ! current_user_can( $capability ) ) {
    48 	wp_die(
    48 	wp_die(
    49 		'<h1>' . __( 'You need a higher level of permission.' ) . '</h1>' .
    49 		'<h1>' . __( 'You need a higher level of permission.' ) . '</h1>' .
    50 		'<p>' . __( 'Sorry, you are not allowed to manage these options.' ) . '</p>',
    50 		'<p>' . __( 'Sorry, you are not allowed to manage options for this site.' ) . '</p>',
    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'] );
    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 ) );
    66 	exit;
    66 	exit;
    67 } elseif ( ! empty( $_GET['dismiss'] ) && 'new_admin_email' == $_GET['dismiss'] ) {
    67 } elseif ( ! empty( $_GET['dismiss'] ) && 'new_admin_email' === $_GET['dismiss'] ) {
    68 	check_admin_referer( 'dismiss-' . get_current_blog_id() . '-new_admin_email' );
    68 	check_admin_referer( 'dismiss-' . get_current_blog_id() . '-new_admin_email' );
    69 	delete_option( 'adminhash' );
    69 	delete_option( 'adminhash' );
    70 	delete_option( 'new_admin_email' );
    70 	delete_option( 'new_admin_email' );
    71 	wp_redirect( admin_url( 'options-general.php?updated=true' ) );
    71 	wp_redirect( admin_url( 'options-general.php?updated=true' ) );
    72 	exit;
    72 	exit;
    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 $allowed_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',
    98 		'default_comment_status',
    98 		'default_comment_status',
    99 		'comments_notify',
    99 		'comments_notify',
   100 		'moderation_notify',
   100 		'moderation_notify',
   101 		'comment_moderation',
   101 		'comment_moderation',
   102 		'require_name_email',
   102 		'require_name_email',
   103 		'comment_whitelist',
   103 		'comment_previously_approved',
   104 		'comment_max_links',
   104 		'comment_max_links',
   105 		'moderation_keys',
   105 		'moderation_keys',
   106 		'blacklist_keys',
   106 		'disallowed_keys',
   107 		'show_avatars',
   107 		'show_avatars',
   108 		'avatar_rating',
   108 		'avatar_rating',
   109 		'avatar_default',
   109 		'avatar_default',
   110 		'close_comments_for_old_posts',
   110 		'close_comments_for_old_posts',
   111 		'close_comments_days_old',
   111 		'close_comments_days_old',
   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 $allowed_options['misc']    = array();
       
   150 $allowed_options['options'] = array();
       
   151 $allowed_options['privacy'] = array();
   150 
   152 
   151 $mail_options = array( 'mailserver_url', 'mailserver_port', 'mailserver_login', 'mailserver_pass' );
   153 $mail_options = array( 'mailserver_url', 'mailserver_port', 'mailserver_login', 'mailserver_pass' );
   152 
   154 
   153 if ( ! in_array( get_option( 'blog_charset' ), array( 'utf8', 'utf-8', 'UTF8', 'UTF-8' ) ) ) {
   155 if ( ! in_array( get_option( 'blog_charset' ), array( 'utf8', 'utf-8', 'UTF8', 'UTF-8' ), true ) ) {
   154 	$whitelist_options['reading'][] = 'blog_charset';
   156 	$allowed_options['reading'][] = 'blog_charset';
   155 }
   157 }
   156 
   158 
   157 if ( get_site_option( 'initial_db_version' ) < 32453 ) {
   159 if ( get_site_option( 'initial_db_version' ) < 32453 ) {
   158 	$whitelist_options['writing'][] = 'use_smilies';
   160 	$allowed_options['writing'][] = 'use_smilies';
   159 	$whitelist_options['writing'][] = 'use_balanceTags';
   161 	$allowed_options['writing'][] = 'use_balanceTags';
   160 }
   162 }
   161 
   163 
   162 if ( ! is_multisite() ) {
   164 if ( ! is_multisite() ) {
   163 	if ( ! defined( 'WP_SITEURL' ) ) {
   165 	if ( ! defined( 'WP_SITEURL' ) ) {
   164 		$whitelist_options['general'][] = 'siteurl';
   166 		$allowed_options['general'][] = 'siteurl';
   165 	}
   167 	}
   166 	if ( ! defined( 'WP_HOME' ) ) {
   168 	if ( ! defined( 'WP_HOME' ) ) {
   167 		$whitelist_options['general'][] = 'home';
   169 		$allowed_options['general'][] = 'home';
   168 	}
   170 	}
   169 
   171 
   170 	$whitelist_options['general'][] = 'users_can_register';
   172 	$allowed_options['general'][] = 'users_can_register';
   171 	$whitelist_options['general'][] = 'default_role';
   173 	$allowed_options['general'][] = 'default_role';
   172 
   174 
   173 	$whitelist_options['writing']   = array_merge( $whitelist_options['writing'], $mail_options );
   175 	$allowed_options['writing']   = array_merge( $allowed_options['writing'], $mail_options );
   174 	$whitelist_options['writing'][] = 'ping_sites';
   176 	$allowed_options['writing'][] = 'ping_sites';
   175 
   177 
   176 	$whitelist_options['media'][] = 'uploads_use_yearmonth_folders';
   178 	$allowed_options['media'][] = 'uploads_use_yearmonth_folders';
   177 
   179 
   178 	// If upload_url_path and upload_path are both default values, they're locked.
   180 	/*
       
   181 	 * If upload_url_path is not the default (empty),
       
   182 	 * or upload_path is not the default ('wp-content/uploads' or empty),
       
   183 	 * they can be edited, otherwise they're locked.
       
   184 	 */
   179 	if ( get_option( 'upload_url_path' ) || ( get_option( 'upload_path' ) != 'wp-content/uploads' && get_option( 'upload_path' ) ) ) {
   185 	if ( get_option( 'upload_url_path' ) || ( get_option( 'upload_path' ) != 'wp-content/uploads' && get_option( 'upload_path' ) ) ) {
   180 		$whitelist_options['media'][] = 'upload_path';
   186 		$allowed_options['media'][] = 'upload_path';
   181 		$whitelist_options['media'][] = 'upload_url_path';
   187 		$allowed_options['media'][] = 'upload_url_path';
   182 	}
   188 	}
   183 } else {
   189 } else {
   184 	/**
   190 	/**
   185 	 * Filters whether the post-by-email functionality is enabled.
   191 	 * Filters whether the post-by-email functionality is enabled.
   186 	 *
   192 	 *
   187 	 * @since 3.0.0
   193 	 * @since 3.0.0
   188 	 *
   194 	 *
   189 	 * @param bool $enabled Whether post-by-email configuration is enabled. Default true.
   195 	 * @param bool $enabled Whether post-by-email configuration is enabled. Default true.
   190 	 */
   196 	 */
   191 	if ( apply_filters( 'enable_post_by_email_configuration', true ) ) {
   197 	if ( apply_filters( 'enable_post_by_email_configuration', true ) ) {
   192 		$whitelist_options['writing'] = array_merge( $whitelist_options['writing'], $mail_options );
   198 		$allowed_options['writing'] = array_merge( $allowed_options['writing'], $mail_options );
   193 	}
   199 	}
   194 }
   200 }
   195 
   201 
   196 /**
   202 /**
   197  * Filters the options white list.
   203  * Filters the allowed options list.
   198  *
   204  *
   199  * @since 2.7.0
   205  * @since 2.7.0
   200  *
   206  * @deprecated 5.5.0 Use {@see 'allowed_options'} instead.
   201  * @param array $whitelist_options White list options.
   207  *
       
   208  * @param array $allowed_options The allowed options list.
   202  */
   209  */
   203 $whitelist_options = apply_filters( 'whitelist_options', $whitelist_options );
   210 $allowed_options = apply_filters_deprecated(
   204 
   211 	'whitelist_options',
   205 /*
   212 	array( $allowed_options ),
   206  * If $_GET['action'] == 'update' we are saving settings sent from a settings page
   213 	'5.5.0',
       
   214 	'apply_filters_deprecated',
       
   215 	__( 'Please consider writing more inclusive code.' )
       
   216 );
       
   217 
       
   218 /**
       
   219  * Filters the allowed options list.
       
   220  *
       
   221  * @since 5.5.0
       
   222  *
       
   223  * @param array $allowed_options The allowed options list.
   207  */
   224  */
   208 if ( 'update' == $action ) {
   225 $allowed_options = apply_filters( 'allowed_options', $allowed_options );
   209 	if ( 'options' == $option_page && ! isset( $_POST['option_page'] ) ) { // This is for back compat and will eventually be removed.
   226 
       
   227 if ( 'update' === $action ) { // We are saving settings sent from a settings page.
       
   228 	if ( 'options' === $option_page && ! isset( $_POST['option_page'] ) ) { // This is for back compat and will eventually be removed.
   210 		$unregistered = true;
   229 		$unregistered = true;
   211 		check_admin_referer( 'update-options' );
   230 		check_admin_referer( 'update-options' );
   212 	} else {
   231 	} else {
   213 		$unregistered = false;
   232 		$unregistered = false;
   214 		check_admin_referer( $option_page . '-options' );
   233 		check_admin_referer( $option_page . '-options' );
   215 	}
   234 	}
   216 
   235 
   217 	if ( ! isset( $whitelist_options[ $option_page ] ) ) {
   236 	if ( ! isset( $allowed_options[ $option_page ] ) ) {
   218 		wp_die( __( '<strong>ERROR</strong>: options page not found.' ) );
   237 		wp_die(
   219 	}
   238 			sprintf(
   220 
   239 				/* translators: %s: The options page name. */
   221 	if ( 'options' == $option_page ) {
   240 				__( '<strong>Error</strong>: Options page %s not found in the allowed options list.' ),
       
   241 				'<code>' . esc_html( $option_page ) . '</code>'
       
   242 			)
       
   243 		);
       
   244 	}
       
   245 
       
   246 	if ( 'options' === $option_page ) {
   222 		if ( is_multisite() && ! current_user_can( 'manage_network_options' ) ) {
   247 		if ( is_multisite() && ! current_user_can( 'manage_network_options' ) ) {
   223 			wp_die( __( 'Sorry, you are not allowed to modify unregistered settings for this site.' ) );
   248 			wp_die( __( 'Sorry, you are not allowed to modify unregistered settings for this site.' ) );
   224 		}
   249 		}
   225 		$options = explode( ',', wp_unslash( $_POST['page_options'] ) );
   250 		$options = explode( ',', wp_unslash( $_POST['page_options'] ) );
   226 	} else {
   251 	} else {
   227 		$options = $whitelist_options[ $option_page ];
   252 		$options = $allowed_options[ $option_page ];
   228 	}
   253 	}
   229 
   254 
   230 	if ( 'general' == $option_page ) {
   255 	if ( 'general' === $option_page ) {
   231 		// Handle custom date/time formats.
   256 		// Handle custom date/time formats.
   232 		if ( ! empty( $_POST['date_format'] ) && isset( $_POST['date_format_custom'] ) && '\c\u\s\t\o\m' == wp_unslash( $_POST['date_format'] ) ) {
   257 		if ( ! empty( $_POST['date_format'] ) && isset( $_POST['date_format_custom'] )
       
   258 			&& '\c\u\s\t\o\m' === wp_unslash( $_POST['date_format'] )
       
   259 		) {
   233 			$_POST['date_format'] = $_POST['date_format_custom'];
   260 			$_POST['date_format'] = $_POST['date_format_custom'];
   234 		}
   261 		}
   235 		if ( ! empty( $_POST['time_format'] ) && isset( $_POST['time_format_custom'] ) && '\c\u\s\t\o\m' == wp_unslash( $_POST['time_format'] ) ) {
   262 
       
   263 		if ( ! empty( $_POST['time_format'] ) && isset( $_POST['time_format_custom'] )
       
   264 			&& '\c\u\s\t\o\m' === wp_unslash( $_POST['time_format'] )
       
   265 		) {
   236 			$_POST['time_format'] = $_POST['time_format_custom'];
   266 			$_POST['time_format'] = $_POST['time_format_custom'];
   237 		}
   267 		}
       
   268 
   238 		// Map UTC+- timezones to gmt_offsets and set timezone_string to empty.
   269 		// Map UTC+- timezones to gmt_offsets and set timezone_string to empty.
   239 		if ( ! empty( $_POST['timezone_string'] ) && preg_match( '/^UTC[+-]/', $_POST['timezone_string'] ) ) {
   270 		if ( ! empty( $_POST['timezone_string'] ) && preg_match( '/^UTC[+-]/', $_POST['timezone_string'] ) ) {
   240 			$_POST['gmt_offset']      = $_POST['timezone_string'];
   271 			$_POST['gmt_offset']      = $_POST['timezone_string'];
   241 			$_POST['gmt_offset']      = preg_replace( '/UTC\+?/', '', $_POST['gmt_offset'] );
   272 			$_POST['gmt_offset']      = preg_replace( '/UTC\+?/', '', $_POST['gmt_offset'] );
   242 			$_POST['timezone_string'] = '';
   273 			$_POST['timezone_string'] = '';
   243 		}
   274 		}
   244 
   275 
   245 		// Handle translation installation.
   276 		// Handle translation installation.
   246 		if ( ! empty( $_POST['WPLANG'] ) && current_user_can( 'install_languages' ) ) {
   277 		if ( ! empty( $_POST['WPLANG'] ) && current_user_can( 'install_languages' ) ) {
   247 			require_once( ABSPATH . 'wp-admin/includes/translation-install.php' );
   278 			require_once ABSPATH . 'wp-admin/includes/translation-install.php';
   248 
   279 
   249 			if ( wp_can_install_language_pack() ) {
   280 			if ( wp_can_install_language_pack() ) {
   250 				$language = wp_download_language_pack( $_POST['WPLANG'] );
   281 				$language = wp_download_language_pack( $_POST['WPLANG'] );
   251 				if ( $language ) {
   282 				if ( $language ) {
   252 					$_POST['WPLANG'] = $language;
   283 					$_POST['WPLANG'] = $language;
   262 			if ( $unregistered ) {
   293 			if ( $unregistered ) {
   263 				_deprecated_argument(
   294 				_deprecated_argument(
   264 					'options.php',
   295 					'options.php',
   265 					'2.7.0',
   296 					'2.7.0',
   266 					sprintf(
   297 					sprintf(
   267 						/* translators: %s: the option/setting */
   298 						/* translators: %s: The option/setting. */
   268 						__( 'The %s setting is unregistered. Unregistered settings are deprecated. See https://codex.wordpress.org/Settings_API' ),
   299 						__( 'The %s setting is unregistered. Unregistered settings are deprecated. See https://developer.wordpress.org/plugins/settings/settings-api/' ),
   269 						'<code>' . $option . '</code>'
   300 						'<code>' . esc_html( $option ) . '</code>'
   270 					)
   301 					)
   271 				);
   302 				);
   272 			}
   303 			}
   273 
   304 
   274 			$option = trim( $option );
   305 			$option = trim( $option );
   293 		if ( $user_language_old !== $user_language_new ) {
   324 		if ( $user_language_old !== $user_language_new ) {
   294 			load_default_textdomain( $user_language_new );
   325 			load_default_textdomain( $user_language_new );
   295 		}
   326 		}
   296 	}
   327 	}
   297 
   328 
   298 	/**
   329 	/*
   299 	 * Handle settings errors and return to options page
   330 	 * Handle settings errors and return to options page.
   300 	 */
   331 	 */
       
   332 
   301 	// If no settings errors were registered add a general 'updated' message.
   333 	// If no settings errors were registered add a general 'updated' message.
   302 	if ( ! count( get_settings_errors() ) ) {
   334 	if ( ! count( get_settings_errors() ) ) {
   303 		add_settings_error( 'general', 'settings_updated', __( 'Settings saved.' ), 'updated' );
   335 		add_settings_error( 'general', 'settings_updated', __( 'Settings saved.' ), 'success' );
   304 	}
   336 	}
   305 	set_transient( 'settings_errors', get_settings_errors(), 30 );
   337 	set_transient( 'settings_errors', get_settings_errors(), 30 );
   306 
   338 
   307 	/**
   339 	// Redirect back to the settings page that was submitted.
   308 	 * Redirect back to the settings page that was submitted
       
   309 	 */
       
   310 	$goback = add_query_arg( 'settings-updated', 'true', wp_get_referer() );
   340 	$goback = add_query_arg( 'settings-updated', 'true', wp_get_referer() );
   311 	wp_redirect( $goback );
   341 	wp_redirect( $goback );
   312 	exit;
   342 	exit;
   313 }
   343 }
   314 
   344 
   315 include( ABSPATH . 'wp-admin/admin-header.php' ); ?>
   345 require_once ABSPATH . 'wp-admin/admin-header.php'; ?>
   316 
   346 
   317 <div class="wrap">
   347 <div class="wrap">
   318 	<h1><?php esc_html_e( 'All Settings' ); ?></h1>
   348 	<h1><?php esc_html_e( 'All Settings' ); ?></h1>
       
   349 
       
   350 	<div class="notice notice-warning">
       
   351 		<p><strong><?php _e( 'Warning:' ); ?></strong> <?php _e( 'This page allows direct access to your site settings. You can break things here. Please be cautious!' ); ?></p>
       
   352 	</div>
       
   353 
   319 	<form name="form" action="options.php" method="post" id="all-options">
   354 	<form name="form" action="options.php" method="post" id="all-options">
   320 		<?php wp_nonce_field( 'options-options' ); ?>
   355 		<?php wp_nonce_field( 'options-options' ); ?>
   321 		<input type="hidden" name="action" value="update" />
   356 		<input type="hidden" name="action" value="update" />
   322 		<input type="hidden" name="option_page" value="options" />
   357 		<input type="hidden" name="option_page" value="options" />
   323 		<table class="form-table" role="presentation">
   358 		<table class="form-table" role="presentation">
   324 <?php
   359 <?php
   325 $options = $wpdb->get_results( "SELECT * FROM $wpdb->options ORDER BY option_name" );
   360 $options = $wpdb->get_results( "SELECT * FROM $wpdb->options ORDER BY option_name" );
   326 
   361 
   327 foreach ( (array) $options as $option ) :
   362 foreach ( (array) $options as $option ) :
   328 	$disabled = false;
   363 	$disabled = false;
   329 	if ( $option->option_name == '' ) {
   364 
       
   365 	if ( '' === $option->option_name ) {
   330 		continue;
   366 		continue;
   331 	}
   367 	}
       
   368 
   332 	if ( is_serialized( $option->option_value ) ) {
   369 	if ( is_serialized( $option->option_value ) ) {
   333 		if ( is_serialized_string( $option->option_value ) ) {
   370 		if ( is_serialized_string( $option->option_value ) ) {
   334 			// This is a serialized string, so we should display it.
   371 			// This is a serialized string, so we should display it.
   335 			$value               = maybe_unserialize( $option->option_value );
   372 			$value               = maybe_unserialize( $option->option_value );
   336 			$options_to_update[] = $option->option_name;
   373 			$options_to_update[] = $option->option_name;
   343 	} else {
   380 	} else {
   344 		$value               = $option->option_value;
   381 		$value               = $option->option_value;
   345 		$options_to_update[] = $option->option_name;
   382 		$options_to_update[] = $option->option_name;
   346 		$class               = 'all-options';
   383 		$class               = 'all-options';
   347 	}
   384 	}
       
   385 
   348 	$name = esc_attr( $option->option_name );
   386 	$name = esc_attr( $option->option_name );
   349 	?>
   387 	?>
   350 <tr>
   388 <tr>
   351 	<th scope="row"><label for="<?php echo $name; ?>"><?php echo esc_html( $option->option_name ); ?></label></th>
   389 	<th scope="row"><label for="<?php echo $name; ?>"><?php echo esc_html( $option->option_name ); ?></label></th>
   352 <td>
   390 <td>
   365 
   403 
   366 </form>
   404 </form>
   367 </div>
   405 </div>
   368 
   406 
   369 <?php
   407 <?php
   370 include( ABSPATH . 'wp-admin/admin-footer.php' );
   408 require_once ABSPATH . 'wp-admin/admin-footer.php';