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