| [ Index ] |
PHP Cross Reference of WordPress Trunk (Updated Daily) |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * Options Management Administration Screen. 4 * 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. 9 * 10 * This file is also the target of the forms in core and custom options pages 11 * that use the Settings API. In this case it saves the new option values 12 * and returns the user to their page of origin. 13 * 14 * @package WordPress 15 * @subpackage Administration 16 */ 17 18 /** WordPress Administration Bootstrap */ 19 require_once __DIR__ . '/admin.php'; 20 21 // Used in the HTML title tag. 22 $title = __( 'Settings' ); 23 $this_file = 'options.php'; 24 $parent_file = 'options-general.php'; 25 26 $action = ! empty( $_REQUEST['action'] ) ? sanitize_text_field( $_REQUEST['action'] ) : ''; 27 $option_page = ! empty( $_REQUEST['option_page'] ) ? sanitize_text_field( $_REQUEST['option_page'] ) : ''; 28 29 $capability = 'manage_options'; 30 31 // This is for back compat and will eventually be removed. 32 if ( empty( $option_page ) ) { 33 $option_page = 'options'; 34 } 35 36 /** 37 * Filters the capability required when using the Settings API. 38 * 39 * By default, the options groups for all registered settings require the manage_options capability. 40 * This filter is required to change the capability required for a certain options page. 41 * 42 * @since 3.2.0 43 * @since 7.0.0 Applied when `wp-admin/options.php` is accessed directly. 44 * 45 * @param string $capability The capability used for the page, which is manage_options by default. 46 */ 47 $capability = apply_filters( "option_page_capability_{$option_page}", $capability ); 48 49 if ( ! current_user_can( $capability ) ) { 50 wp_die( 51 '<h1>' . __( 'You need a higher level of permission.' ) . '</h1>' . 52 '<p>' . __( 'Sorry, you are not allowed to manage options for this site.' ) . '</p>', 53 403 54 ); 55 } 56 57 // Handle admin email change requests. 58 if ( ! empty( $_GET['adminhash'] ) ) { 59 $new_admin_details = get_option( 'adminhash' ); 60 $redirect = 'options-general.php?updated=false'; 61 62 if ( is_array( $new_admin_details ) 63 && hash_equals( $new_admin_details['hash'], $_GET['adminhash'] ) 64 && ! empty( $new_admin_details['newemail'] ) 65 ) { 66 update_option( 'admin_email', $new_admin_details['newemail'] ); 67 delete_option( 'adminhash' ); 68 delete_option( 'new_admin_email' ); 69 $redirect = 'options-general.php?updated=true'; 70 } 71 72 wp_redirect( admin_url( $redirect ) ); 73 exit; 74 } elseif ( ! empty( $_GET['dismiss'] ) && 'new_admin_email' === $_GET['dismiss'] ) { 75 check_admin_referer( 'dismiss-' . get_current_blog_id() . '-new_admin_email' ); 76 delete_option( 'adminhash' ); 77 delete_option( 'new_admin_email' ); 78 wp_redirect( admin_url( 'options-general.php?updated=true' ) ); 79 exit; 80 } 81 82 if ( is_multisite() && ! current_user_can( 'manage_network_options' ) && 'update' !== $action ) { 83 wp_die( 84 '<h1>' . __( 'You need a higher level of permission.' ) . '</h1>' . 85 '<p>' . __( 'Sorry, you are not allowed to delete these items.' ) . '</p>', 86 403 87 ); 88 } 89 90 $allowed_options = array( 91 'general' => array( 92 'blogname', 93 'blogdescription', 94 'site_icon', 95 'gmt_offset', 96 'date_format', 97 'time_format', 98 'start_of_week', 99 'timezone_string', 100 'WPLANG', 101 'new_admin_email', 102 ), 103 'discussion' => array( 104 'default_pingback_flag', 105 'default_ping_status', 106 'default_comment_status', 107 'comments_notify', 108 'moderation_notify', 109 'comment_moderation', 110 'require_name_email', 111 'comment_previously_approved', 112 'comment_max_links', 113 'moderation_keys', 114 'disallowed_keys', 115 'show_avatars', 116 'avatar_rating', 117 'avatar_default', 118 'close_comments_for_old_posts', 119 'close_comments_days_old', 120 'thread_comments', 121 'thread_comments_depth', 122 'page_comments', 123 'comments_per_page', 124 'default_comments_page', 125 'comment_order', 126 'comment_registration', 127 'show_comments_cookies_opt_in', 128 'wp_notes_notify', 129 ), 130 'media' => array( 131 'thumbnail_size_w', 132 'thumbnail_size_h', 133 'thumbnail_crop', 134 'medium_size_w', 135 'medium_size_h', 136 'large_size_w', 137 'large_size_h', 138 'image_default_size', 139 'image_default_align', 140 'image_default_link_type', 141 ), 142 'reading' => array( 143 'posts_per_page', 144 'posts_per_rss', 145 'rss_use_excerpt', 146 'show_on_front', 147 'page_on_front', 148 'page_for_posts', 149 'blog_public', 150 ), 151 'writing' => array( 152 'default_category', 153 'default_email_category', 154 'default_link_category', 155 'default_post_format', 156 ), 157 ); 158 $allowed_options['misc'] = array(); 159 $allowed_options['options'] = array(); 160 $allowed_options['privacy'] = array(); 161 162 /** 163 * Filters whether the post-by-email functionality is enabled. 164 * 165 * @since 3.0.0 166 * 167 * @param bool $enabled Whether post-by-email configuration is enabled. Default true. 168 */ 169 if ( apply_filters( 'enable_post_by_email_configuration', true ) ) { 170 $allowed_options['writing'][] = 'mailserver_url'; 171 $allowed_options['writing'][] = 'mailserver_port'; 172 $allowed_options['writing'][] = 'mailserver_login'; 173 $allowed_options['writing'][] = 'mailserver_pass'; 174 } 175 176 if ( ! is_utf8_charset() ) { 177 $allowed_options['reading'][] = 'blog_charset'; 178 } 179 180 if ( get_site_option( 'initial_db_version' ) < 32453 ) { 181 $allowed_options['writing'][] = 'use_smilies'; 182 $allowed_options['writing'][] = 'use_balanceTags'; 183 } 184 185 if ( ! is_multisite() ) { 186 if ( ! defined( 'WP_SITEURL' ) ) { 187 $allowed_options['general'][] = 'siteurl'; 188 } 189 if ( ! defined( 'WP_HOME' ) ) { 190 $allowed_options['general'][] = 'home'; 191 } 192 193 $allowed_options['general'][] = 'users_can_register'; 194 $allowed_options['general'][] = 'default_role'; 195 196 if ( '1' === get_option( 'blog_public' ) ) { 197 $allowed_options['writing'][] = 'ping_sites'; 198 } 199 200 $allowed_options['media'][] = 'uploads_use_yearmonth_folders'; 201 202 /* 203 * If upload_url_path is not the default (empty), 204 * or upload_path is not the default ('wp-content/uploads' or empty), 205 * they can be edited, otherwise they're locked. 206 */ 207 if ( get_option( 'upload_url_path' ) 208 || get_option( 'upload_path' ) && 'wp-content/uploads' !== get_option( 'upload_path' ) 209 ) { 210 $allowed_options['media'][] = 'upload_path'; 211 $allowed_options['media'][] = 'upload_url_path'; 212 } 213 } 214 215 /** 216 * Filters the allowed options list. 217 * 218 * @since 2.7.0 219 * @deprecated 5.5.0 Use {@see 'allowed_options'} instead. 220 * 221 * @param array $allowed_options The allowed options list. 222 */ 223 $allowed_options = apply_filters_deprecated( 224 'whitelist_options', 225 array( $allowed_options ), 226 '5.5.0', 227 'allowed_options', 228 __( 'Please consider writing more inclusive code.' ) 229 ); 230 231 /** 232 * Filters the allowed options list. 233 * 234 * @since 5.5.0 235 * 236 * @param array $allowed_options The allowed options list. 237 */ 238 $allowed_options = apply_filters( 'allowed_options', $allowed_options ); 239 240 if ( 'update' === $action ) { // We are saving settings sent from a settings page. 241 if ( 'options' === $option_page && ! isset( $_POST['option_page'] ) ) { // This is for back compat and will eventually be removed. 242 $unregistered = true; 243 check_admin_referer( 'update-options' ); 244 } else { 245 $unregistered = false; 246 check_admin_referer( $option_page . '-options' ); 247 } 248 249 if ( ! isset( $allowed_options[ $option_page ] ) ) { 250 wp_die( 251 sprintf( 252 /* translators: %s: The options page name. */ 253 __( '<strong>Error:</strong> The %s options page is not in the allowed options list.' ), 254 '<code>' . esc_html( $option_page ) . '</code>' 255 ) 256 ); 257 } 258 259 if ( 'options' === $option_page ) { 260 if ( is_multisite() && ! current_user_can( 'manage_network_options' ) ) { 261 wp_die( __( 'Sorry, you are not allowed to modify unregistered settings for this site.' ) ); 262 } 263 $options = isset( $_POST['page_options'] ) ? explode( ',', wp_unslash( $_POST['page_options'] ) ) : null; 264 } else { 265 $options = $allowed_options[ $option_page ]; 266 } 267 268 if ( 'general' === $option_page ) { 269 // Handle custom date/time formats. 270 if ( ! empty( $_POST['date_format'] ) && isset( $_POST['date_format_custom'] ) 271 && '\c\u\s\t\o\m' === wp_unslash( $_POST['date_format'] ) 272 ) { 273 $_POST['date_format'] = $_POST['date_format_custom']; 274 } 275 276 if ( ! empty( $_POST['time_format'] ) && isset( $_POST['time_format_custom'] ) 277 && '\c\u\s\t\o\m' === wp_unslash( $_POST['time_format'] ) 278 ) { 279 $_POST['time_format'] = $_POST['time_format_custom']; 280 } 281 282 // Map UTC+- timezones to gmt_offsets and set timezone_string to empty. 283 if ( ! empty( $_POST['timezone_string'] ) && preg_match( '/^UTC[+-]/', $_POST['timezone_string'] ) ) { 284 $_POST['gmt_offset'] = $_POST['timezone_string']; 285 $_POST['gmt_offset'] = preg_replace( '/UTC\+?/', '', $_POST['gmt_offset'] ); 286 $_POST['timezone_string'] = ''; 287 } elseif ( isset( $_POST['timezone_string'] ) && ! in_array( $_POST['timezone_string'], timezone_identifiers_list( DateTimeZone::ALL_WITH_BC ), true ) ) { 288 // Reset to the current value. 289 $current_timezone_string = get_option( 'timezone_string' ); 290 291 if ( ! empty( $current_timezone_string ) ) { 292 $_POST['timezone_string'] = $current_timezone_string; 293 } else { 294 $_POST['gmt_offset'] = get_option( 'gmt_offset' ); 295 $_POST['timezone_string'] = ''; 296 } 297 298 add_settings_error( 299 'general', 300 'settings_updated', 301 __( 'The timezone you have entered is not valid. Please select a valid timezone.' ), 302 'error' 303 ); 304 } 305 306 // Handle translation installation. 307 if ( ! empty( $_POST['WPLANG'] ) && current_user_can( 'install_languages' ) ) { 308 require_once ABSPATH . 'wp-admin/includes/translation-install.php'; 309 310 if ( wp_can_install_language_pack() ) { 311 $language = wp_download_language_pack( $_POST['WPLANG'] ); 312 if ( $language ) { 313 $_POST['WPLANG'] = $language; 314 } 315 } 316 } 317 } 318 319 if ( $options ) { 320 $user_language_old = get_user_locale(); 321 322 foreach ( $options as $option ) { 323 if ( $unregistered ) { 324 _deprecated_argument( 325 'options.php', 326 '2.7.0', 327 sprintf( 328 /* translators: 1: The option/setting, 2: Documentation URL. */ 329 __( 'The %1$s setting is unregistered. Unregistered settings are deprecated. See <a href="%2$s">documentation on the Settings API</a>.' ), 330 '<code>' . esc_html( $option ) . '</code>', 331 __( 'https://developer.wordpress.org/plugins/settings/settings-api/' ) 332 ) 333 ); 334 } 335 336 $option = trim( $option ); 337 $value = null; 338 if ( isset( $_POST[ $option ] ) ) { 339 $value = $_POST[ $option ]; 340 if ( ! is_array( $value ) ) { 341 $value = trim( $value ); 342 } 343 $value = wp_unslash( $value ); 344 } 345 update_option( $option, $value ); 346 } 347 348 /* 349 * Switch translation in case WPLANG was changed. 350 * The global $locale is used in get_locale() which is 351 * used as a fallback in get_user_locale(). 352 */ 353 unset( $GLOBALS['locale'] ); 354 $user_language_new = get_user_locale(); 355 if ( $user_language_old !== $user_language_new ) { 356 load_default_textdomain( $user_language_new ); 357 } 358 } else { 359 add_settings_error( 'general', 'settings_updated', __( 'Settings save failed.' ), 'error' ); 360 } 361 362 /* 363 * Handle settings errors and return to options page. 364 */ 365 366 // If no settings errors were registered add a general 'updated' message. 367 if ( ! count( get_settings_errors() ) ) { 368 add_settings_error( 'general', 'settings_updated', __( 'Settings saved.' ), 'success' ); 369 } 370 371 set_transient( 'settings_errors', get_settings_errors(), 30 ); // 30 seconds. 372 373 // Redirect back to the settings page that was submitted. 374 $goback = add_query_arg( 'settings-updated', 'true', wp_get_referer() ); 375 wp_redirect( $goback ); 376 exit; 377 } 378 379 require_once ABSPATH . 'wp-admin/admin-header.php'; 380 ?> 381 382 <div class="wrap"> 383 <h1><?php esc_html_e( 'All Settings' ); ?></h1> 384 385 <?php 386 wp_admin_notice( 387 '<strong>' . __( 'Warning:' ) . '</strong> ' . __( 'This page allows direct access to your site settings. You can break things here. Please be cautious!' ), 388 array( 389 'type' => 'warning', 390 ) 391 ); 392 ?> 393 <form name="form" action="options.php" method="post" id="all-options"> 394 <?php wp_nonce_field( 'options-options' ); ?> 395 <input type="hidden" name="action" value="update" /> 396 <input type="hidden" name="option_page" value="options" /> 397 <table class="form-table" role="presentation"> 398 <?php 399 $options = $wpdb->get_results( "SELECT * FROM $wpdb->options ORDER BY option_name" ); 400 401 foreach ( (array) $options as $option ) : 402 $disabled = false; 403 404 if ( '' === $option->option_name ) { 405 continue; 406 } 407 408 if ( 'home' === $option->option_name && defined( 'WP_HOME' ) ) { 409 $disabled = true; 410 } 411 412 if ( 'siteurl' === $option->option_name && defined( 'WP_SITEURL' ) ) { 413 $disabled = true; 414 } 415 416 if ( is_serialized( $option->option_value ) ) { 417 if ( is_serialized_string( $option->option_value ) ) { 418 // This is a serialized string, so we should display it. 419 $value = maybe_unserialize( $option->option_value ); 420 $options_to_update[] = $option->option_name; 421 } else { 422 $value = 'SERIALIZED DATA'; 423 $disabled = true; 424 } 425 } elseif ( str_starts_with( $option->option_name, 'connectors_' ) 426 && str_ends_with( $option->option_name, '_api_key' ) 427 ) { 428 // Mask connector API keys and prevent updates from this screen. 429 $value = _wp_connectors_mask_api_key( $option->option_value ); 430 $disabled = true; 431 } else { 432 $value = $option->option_value; 433 $options_to_update[] = $option->option_name; 434 } 435 436 $class = 'all-options'; 437 438 if ( $disabled ) { 439 $class .= ' disabled'; 440 } 441 442 $name = esc_attr( $option->option_name ); 443 ?> 444 <tr> 445 <th scope="row"><label for="<?php echo $name; ?>"><?php echo esc_html( $option->option_name ); ?></label></th> 446 <td> 447 <?php if ( str_contains( $value, "\n" ) ) : ?> 448 <textarea class="<?php echo $class; ?>" name="<?php echo $name; ?>" id="<?php echo $name; ?>" cols="30" rows="5"><?php echo esc_textarea( $value ); ?></textarea> 449 <?php else : ?> 450 <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 ); ?> /> 451 <?php endif; ?></td> 452 </tr> 453 <?php endforeach; ?> 454 </table> 455 456 <input type="hidden" name="page_options" value="<?php echo esc_attr( implode( ',', $options_to_update ) ); ?>" /> 457 458 <?php submit_button( __( 'Save Changes' ), 'primary', 'Update' ); ?> 459 460 </form> 461 </div> 462 463 <?php 464 require_once ABSPATH . 'wp-admin/admin-footer.php';
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated : Mon May 25 08:20:05 2026 | Cross-referenced by PHPXref |