wp/wp-admin/options.php
changeset 7 cf61fcea0001
parent 5 5e2f62d02dcd
child 9 177826044cd9
equal deleted inserted replaced
6:490d5cc509ed 7:cf61fcea0001
    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 	 * Filter the capability required when using the Settings API.
    35 	 * Filters the capability required when using the Settings API.
    36 	 *
    36 	 *
    37 	 * By default, the options groups for all registered settings require the manage_options capability.
    37 	 * By default, the options groups for all registered settings require the manage_options capability.
    38 	 * This filter is required to change the capability required for a certain options page.
    38 	 * This filter is required to change the capability required for a certain options page.
    39 	 *
    39 	 *
    40 	 * @since 3.2.0
    40 	 * @since 3.2.0
    42 	 * @param string $capability The capability used for the page, which is manage_options by default.
    42 	 * @param string $capability The capability used for the page, which is manage_options by default.
    43 	 */
    43 	 */
    44 	$capability = apply_filters( "option_page_capability_{$option_page}", $capability );
    44 	$capability = apply_filters( "option_page_capability_{$option_page}", $capability );
    45 }
    45 }
    46 
    46 
    47 if ( !current_user_can( $capability ) )
    47 if ( ! current_user_can( $capability ) ) {
    48 	wp_die( __( 'Cheatin’ uh?' ), 403 );
    48 	wp_die(
       
    49 		'<h1>' . __( 'You need a higher level of permission.' ) . '</h1>' .
       
    50 		'<p>' . __( 'Sorry, you are not allowed to manage these options.' ) . '</p>',
       
    51 		403
       
    52 	);
       
    53 }
    49 
    54 
    50 // Handle admin email change requests
    55 // Handle admin email change requests
    51 if ( is_multisite() ) {
    56 if ( ! empty( $_GET[ 'adminhash' ] ) ) {
    52 	if ( ! empty($_GET[ 'adminhash' ] ) ) {
    57 	$new_admin_details = get_option( 'adminhash' );
    53 		$new_admin_details = get_option( 'adminhash' );
    58 	$redirect = 'options-general.php?updated=false';
    54 		$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' ] ) ) {
    55 		if ( is_array( $new_admin_details ) && $new_admin_details[ 'hash' ] == $_GET[ 'adminhash' ] && !empty($new_admin_details[ 'newemail' ]) ) {
    60 		update_option( 'admin_email', $new_admin_details[ 'newemail' ] );
    56 			update_option( 'admin_email', $new_admin_details[ 'newemail' ] );
       
    57 			delete_option( 'adminhash' );
       
    58 			delete_option( 'new_admin_email' );
       
    59 			$redirect = 'options-general.php?updated=true';
       
    60 		}
       
    61 		wp_redirect( admin_url( $redirect ) );
       
    62 		exit;
       
    63 	} elseif ( ! empty( $_GET['dismiss'] ) && 'new_admin_email' == $_GET['dismiss'] ) {
       
    64 		delete_option( 'adminhash' );
    61 		delete_option( 'adminhash' );
    65 		delete_option( 'new_admin_email' );
    62 		delete_option( 'new_admin_email' );
    66 		wp_redirect( admin_url( 'options-general.php?updated=true' ) );
    63 		$redirect = 'options-general.php?updated=true';
    67 		exit;
    64 	}
    68 	}
    65 	wp_redirect( admin_url( $redirect ) );
    69 }
    66 	exit;
    70 
    67 } elseif ( ! empty( $_GET['dismiss'] ) && 'new_admin_email' == $_GET['dismiss'] ) {
    71 if ( is_multisite() && !is_super_admin() && 'update' != $action )
    68 	check_admin_referer( 'dismiss-' . get_current_blog_id() . '-new_admin_email' );
    72 	wp_die( __( 'Cheatin&#8217; uh?' ), 403 );
    69 	delete_option( 'adminhash' );
       
    70 	delete_option( 'new_admin_email' );
       
    71 	wp_redirect( admin_url( 'options-general.php?updated=true' ) );
       
    72 	exit;
       
    73 }
       
    74 
       
    75 if ( is_multisite() && ! current_user_can( 'manage_network_options' ) && 'update' != $action ) {
       
    76 	wp_die(
       
    77 		'<h1>' . __( 'You need a higher level of permission.' ) . '</h1>' .
       
    78 		'<p>' . __( 'Sorry, you are not allowed to delete these items.' ) . '</p>',
       
    79 		403
       
    80 	);
       
    81 }
    73 
    82 
    74 $whitelist_options = array(
    83 $whitelist_options = array(
    75 	'general' => array( 'blogname', 'blogdescription', 'gmt_offset', 'date_format', 'time_format', 'start_of_week', 'timezone_string', 'WPLANG' ),
    84 	'general' => array(
    76 	'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' ),
    85 		'blogname',
    77 	'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' ),
    86 		'blogdescription',
    78 	'reading' => array( 'posts_per_page', 'posts_per_rss', 'rss_use_excerpt', 'show_on_front', 'page_on_front', 'page_for_posts', 'blog_public' ),
    87 		'gmt_offset',
    79 	'writing' => array( 'use_smilies', 'default_category', 'default_email_category', 'use_balanceTags', 'default_link_category', 'default_post_format' )
    88 		'date_format',
       
    89 		'time_format',
       
    90 		'start_of_week',
       
    91 		'timezone_string',
       
    92 		'WPLANG',
       
    93 		'new_admin_email',
       
    94 	),
       
    95 	'discussion' => array(
       
    96 		'default_pingback_flag',
       
    97 		'default_ping_status',
       
    98 		'default_comment_status',
       
    99 		'comments_notify',
       
   100 		'moderation_notify',
       
   101 		'comment_moderation',
       
   102 		'require_name_email',
       
   103 		'comment_whitelist',
       
   104 		'comment_max_links',
       
   105 		'moderation_keys',
       
   106 		'blacklist_keys',
       
   107 		'show_avatars',
       
   108 		'avatar_rating',
       
   109 		'avatar_default',
       
   110 		'close_comments_for_old_posts',
       
   111 		'close_comments_days_old',
       
   112 		'thread_comments',
       
   113 		'thread_comments_depth',
       
   114 		'page_comments',
       
   115 		'comments_per_page',
       
   116 		'default_comments_page',
       
   117 		'comment_order',
       
   118 		'comment_registration',
       
   119 		'show_comments_cookies_opt_in',
       
   120 	),
       
   121 	'media' => array(
       
   122 		'thumbnail_size_w',
       
   123 		'thumbnail_size_h',
       
   124 		'thumbnail_crop',
       
   125 		'medium_size_w',
       
   126 		'medium_size_h',
       
   127 		'large_size_w',
       
   128 		'large_size_h',
       
   129 		'image_default_size',
       
   130 		'image_default_align',
       
   131 		'image_default_link_type',
       
   132 	),
       
   133 	'reading' => array(
       
   134 		'posts_per_page',
       
   135 		'posts_per_rss',
       
   136 		'rss_use_excerpt',
       
   137 		'show_on_front',
       
   138 		'page_on_front',
       
   139 		'page_for_posts',
       
   140 		'blog_public',
       
   141 	),
       
   142 	'writing' => array(
       
   143 		'default_category',
       
   144 		'default_email_category',
       
   145 		'default_link_category',
       
   146 		'default_post_format',
       
   147 	),
    80 );
   148 );
    81 $whitelist_options['misc'] = $whitelist_options['options'] = $whitelist_options['privacy'] = array();
   149 $whitelist_options['misc'] = $whitelist_options['options'] = $whitelist_options['privacy'] = array();
    82 
   150 
    83 $mail_options = array('mailserver_url', 'mailserver_port', 'mailserver_login', 'mailserver_pass');
   151 $mail_options = array('mailserver_url', 'mailserver_port', 'mailserver_login', 'mailserver_pass');
    84 
   152 
    85 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' ) ) )
    86 	$whitelist_options['reading'][] = 'blog_charset';
   154 	$whitelist_options['reading'][] = 'blog_charset';
       
   155 
       
   156 if ( get_site_option( 'initial_db_version' ) < 32453 ) {
       
   157 	$whitelist_options['writing'][] = 'use_smilies';
       
   158 	$whitelist_options['writing'][] = 'use_balanceTags';
       
   159 }
    87 
   160 
    88 if ( !is_multisite() ) {
   161 if ( !is_multisite() ) {
    89 	if ( !defined( 'WP_SITEURL' ) )
   162 	if ( !defined( 'WP_SITEURL' ) )
    90 		$whitelist_options['general'][] = 'siteurl';
   163 		$whitelist_options['general'][] = 'siteurl';
    91 	if ( !defined( 'WP_HOME' ) )
   164 	if ( !defined( 'WP_HOME' ) )
    92 		$whitelist_options['general'][] = 'home';
   165 		$whitelist_options['general'][] = 'home';
    93 
   166 
    94 	$whitelist_options['general'][] = 'admin_email';
       
    95 	$whitelist_options['general'][] = 'users_can_register';
   167 	$whitelist_options['general'][] = 'users_can_register';
    96 	$whitelist_options['general'][] = 'default_role';
   168 	$whitelist_options['general'][] = 'default_role';
    97 
   169 
    98 	$whitelist_options['writing'] = array_merge($whitelist_options['writing'], $mail_options);
   170 	$whitelist_options['writing'] = array_merge($whitelist_options['writing'], $mail_options);
    99 	$whitelist_options['writing'][] = 'ping_sites';
   171 	$whitelist_options['writing'][] = 'ping_sites';
   104 	if ( get_option( 'upload_url_path' ) || ( get_option('upload_path') != 'wp-content/uploads' && get_option('upload_path') ) ) {
   176 	if ( get_option( 'upload_url_path' ) || ( get_option('upload_path') != 'wp-content/uploads' && get_option('upload_path') ) ) {
   105 		$whitelist_options['media'][] = 'upload_path';
   177 		$whitelist_options['media'][] = 'upload_path';
   106 		$whitelist_options['media'][] = 'upload_url_path';
   178 		$whitelist_options['media'][] = 'upload_url_path';
   107 	}
   179 	}
   108 } else {
   180 } else {
   109 	$whitelist_options['general'][] = 'new_admin_email';
       
   110 
       
   111 	/**
   181 	/**
   112 	 * Filter whether the post-by-email functionality is enabled.
   182 	 * Filters whether the post-by-email functionality is enabled.
   113 	 *
   183 	 *
   114 	 * @since 3.0.0
   184 	 * @since 3.0.0
   115 	 *
   185 	 *
   116 	 * @param bool $enabled Whether post-by-email configuration is enabled. Default true.
   186 	 * @param bool $enabled Whether post-by-email configuration is enabled. Default true.
   117 	 */
   187 	 */
   118 	if ( apply_filters( 'enable_post_by_email_configuration', true ) )
   188 	if ( apply_filters( 'enable_post_by_email_configuration', true ) )
   119 		$whitelist_options['writing'] = array_merge($whitelist_options['writing'], $mail_options);
   189 		$whitelist_options['writing'] = array_merge($whitelist_options['writing'], $mail_options);
   120 }
   190 }
   121 
   191 
   122 /**
   192 /**
   123  * Filter the options white list.
   193  * Filters the options white list.
   124  *
   194  *
   125  * @since 2.7.0
   195  * @since 2.7.0
   126  *
   196  *
   127  * @param array White list options.
   197  * @param array $whitelist_options White list options.
   128  */
   198  */
   129 $whitelist_options = apply_filters( 'whitelist_options', $whitelist_options );
   199 $whitelist_options = apply_filters( 'whitelist_options', $whitelist_options );
   130 
   200 
   131 /*
   201 /*
   132  * If $_GET['action'] == 'update' we are saving settings sent from a settings page
   202  * If $_GET['action'] == 'update' we are saving settings sent from a settings page
   142 
   212 
   143 	if ( !isset( $whitelist_options[ $option_page ] ) )
   213 	if ( !isset( $whitelist_options[ $option_page ] ) )
   144 		wp_die( __( '<strong>ERROR</strong>: options page not found.' ) );
   214 		wp_die( __( '<strong>ERROR</strong>: options page not found.' ) );
   145 
   215 
   146 	if ( 'options' == $option_page ) {
   216 	if ( 'options' == $option_page ) {
   147 		if ( is_multisite() && ! is_super_admin() )
   217 		if ( is_multisite() && ! current_user_can( 'manage_network_options' ) ) {
   148 			wp_die( __( 'You do not have sufficient permissions to modify unregistered settings for this site.' ) );
   218 			wp_die( __( 'Sorry, you are not allowed to modify unregistered settings for this site.' ) );
       
   219 		}
   149 		$options = explode( ',', wp_unslash( $_POST[ 'page_options' ] ) );
   220 		$options = explode( ',', wp_unslash( $_POST[ 'page_options' ] ) );
   150 	} else {
   221 	} else {
   151 		$options = $whitelist_options[ $option_page ];
   222 		$options = $whitelist_options[ $option_page ];
   152 	}
   223 	}
   153 
   224 
   162 			$_POST['gmt_offset'] = $_POST['timezone_string'];
   233 			$_POST['gmt_offset'] = $_POST['timezone_string'];
   163 			$_POST['gmt_offset'] = preg_replace('/UTC\+?/', '', $_POST['gmt_offset']);
   234 			$_POST['gmt_offset'] = preg_replace('/UTC\+?/', '', $_POST['gmt_offset']);
   164 			$_POST['timezone_string'] = '';
   235 			$_POST['timezone_string'] = '';
   165 		}
   236 		}
   166 
   237 
   167 		// Handle translation install.
   238 		// Handle translation installation.
   168 		if ( ! empty( $_POST['WPLANG'] ) && ( ! is_multisite() || is_super_admin() ) ) { // @todo: Skip if already installed
   239 		if ( ! empty( $_POST['WPLANG'] ) && current_user_can( 'install_languages' ) ) {
   169 			require_once( ABSPATH . 'wp-admin/includes/translation-install.php' );
   240 			require_once( ABSPATH . 'wp-admin/includes/translation-install.php' );
   170 
   241 
   171 			if ( wp_can_install_language_pack() ) {
   242 			if ( wp_can_install_language_pack() ) {
   172 				$language = wp_download_language_pack( $_POST['WPLANG'] );
   243 				$language = wp_download_language_pack( $_POST['WPLANG'] );
   173 				if ( $language ) {
   244 				if ( $language ) {
   176 			}
   247 			}
   177 		}
   248 		}
   178 	}
   249 	}
   179 
   250 
   180 	if ( $options ) {
   251 	if ( $options ) {
       
   252 		$user_language_old = get_user_locale();
       
   253 
   181 		foreach ( $options as $option ) {
   254 		foreach ( $options as $option ) {
   182 			if ( $unregistered )
   255 			if ( $unregistered ) {
   183 				_deprecated_argument( 'options.php', '2.7', sprintf( __( 'The <code>%1$s</code> setting is unregistered. Unregistered settings are deprecated. See https://codex.wordpress.org/Settings_API' ), $option, $option_page ) );
   256 				_deprecated_argument( 'options.php', '2.7.0',
       
   257 					sprintf(
       
   258 						/* translators: %s: the option/setting */
       
   259 						__( 'The %s setting is unregistered. Unregistered settings are deprecated. See https://codex.wordpress.org/Settings_API' ),
       
   260 						'<code>' . $option . '</code>'
       
   261 					)
       
   262 				);
       
   263 			}
   184 
   264 
   185 			$option = trim( $option );
   265 			$option = trim( $option );
   186 			$value = null;
   266 			$value = null;
   187 			if ( isset( $_POST[ $option ] ) ) {
   267 			if ( isset( $_POST[ $option ] ) ) {
   188 				$value = $_POST[ $option ];
   268 				$value = $_POST[ $option ];
   189 				if ( ! is_array( $value ) )
   269 				if ( ! is_array( $value ) ) {
   190 					$value = trim( $value );
   270 					$value = trim( $value );
       
   271 				}
   191 				$value = wp_unslash( $value );
   272 				$value = wp_unslash( $value );
   192 			}
   273 			}
   193 			update_option( $option, $value );
   274 			update_option( $option, $value );
   194 		}
   275 		}
   195 
   276 
   196 		// Switch translation in case WPLANG was changed.
   277 		/*
   197 		$language = get_option( 'WPLANG' );
   278 		 * Switch translation in case WPLANG was changed.
   198 		if ( $language ) {
   279 		 * The global $locale is used in get_locale() which is
   199 			load_default_textdomain( $language );
   280 		 * used as a fallback in get_user_locale().
   200 		} else {
   281 		 */
   201 			unload_textdomain( 'default' );
   282 		unset( $GLOBALS['locale'] );
       
   283 		$user_language_new = get_user_locale();
       
   284 		if ( $user_language_old !== $user_language_new  ) {
       
   285 			load_default_textdomain( $user_language_new );
   202 		}
   286 		}
   203 	}
   287 	}
   204 
   288 
   205 	/**
   289 	/**
   206 	 * Handle settings errors and return to options page
   290 	 * Handle settings errors and return to options page
   219 }
   303 }
   220 
   304 
   221 include( ABSPATH . 'wp-admin/admin-header.php' ); ?>
   305 include( ABSPATH . 'wp-admin/admin-header.php' ); ?>
   222 
   306 
   223 <div class="wrap">
   307 <div class="wrap">
   224   <h2><?php esc_html_e('All Settings'); ?></h2>
   308   <h1><?php esc_html_e( 'All Settings' ); ?></h1>
   225   <form name="form" action="options.php" method="post" id="all-options">
   309   <form name="form" action="options.php" method="post" id="all-options">
   226   <?php wp_nonce_field('options-options') ?>
   310   <?php wp_nonce_field('options-options') ?>
   227   <input type="hidden" name="action" value="update" />
   311   <input type="hidden" name="action" value="update" />
   228   <input type="hidden" name="option_page" value="options" />
   312   <input type="hidden" name="option_page" value="options" />
   229   <table class="form-table">
   313   <table class="form-table">