[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

title

Body

[close]

/wp-admin/ -> options.php (source)

   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  } else {
  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       *
  44       * @param string $capability The capability used for the page, which is manage_options by default.
  45       */
  46      $capability = apply_filters( "option_page_capability_{$option_page}", $capability );
  47  }
  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      ),
 129      'media'      => array(
 130          'thumbnail_size_w',
 131          'thumbnail_size_h',
 132          'thumbnail_crop',
 133          'medium_size_w',
 134          'medium_size_h',
 135          'large_size_w',
 136          'large_size_h',
 137          'image_default_size',
 138          'image_default_align',
 139          'image_default_link_type',
 140      ),
 141      'reading'    => array(
 142          'posts_per_page',
 143          'posts_per_rss',
 144          'rss_use_excerpt',
 145          'show_on_front',
 146          'page_on_front',
 147          'page_for_posts',
 148          'blog_public',
 149      ),
 150      'writing'    => array(
 151          'default_category',
 152          'default_email_category',
 153          'default_link_category',
 154          'default_post_format',
 155      ),
 156  );
 157  $allowed_options['misc']    = array();
 158  $allowed_options['options'] = array();
 159  $allowed_options['privacy'] = array();
 160  
 161  $mail_options = array( 'mailserver_url', 'mailserver_port', 'mailserver_login', 'mailserver_pass' );
 162  
 163  if ( ! in_array( get_option( 'blog_charset' ), array( 'utf8', 'utf-8', 'UTF8', 'UTF-8' ), true ) ) {
 164      $allowed_options['reading'][] = 'blog_charset';
 165  }
 166  
 167  if ( get_site_option( 'initial_db_version' ) < 32453 ) {
 168      $allowed_options['writing'][] = 'use_smilies';
 169      $allowed_options['writing'][] = 'use_balanceTags';
 170  }
 171  
 172  if ( ! is_multisite() ) {
 173      if ( ! defined( 'WP_SITEURL' ) ) {
 174          $allowed_options['general'][] = 'siteurl';
 175      }
 176      if ( ! defined( 'WP_HOME' ) ) {
 177          $allowed_options['general'][] = 'home';
 178      }
 179  
 180      $allowed_options['general'][] = 'users_can_register';
 181      $allowed_options['general'][] = 'default_role';
 182  
 183      $allowed_options['writing']   = array_merge( $allowed_options['writing'], $mail_options );
 184      $allowed_options['writing'][] = 'ping_sites';
 185  
 186      $allowed_options['media'][] = 'uploads_use_yearmonth_folders';
 187  
 188      /*
 189       * If upload_url_path is not the default (empty),
 190       * or upload_path is not the default ('wp-content/uploads' or empty),
 191       * they can be edited, otherwise they're locked.
 192       */
 193      if ( get_option( 'upload_url_path' )
 194          || get_option( 'upload_path' ) && 'wp-content/uploads' !== get_option( 'upload_path' )
 195      ) {
 196          $allowed_options['media'][] = 'upload_path';
 197          $allowed_options['media'][] = 'upload_url_path';
 198      }
 199  } else {
 200      /**
 201       * Filters whether the post-by-email functionality is enabled.
 202       *
 203       * @since 3.0.0
 204       *
 205       * @param bool $enabled Whether post-by-email configuration is enabled. Default true.
 206       */
 207      if ( apply_filters( 'enable_post_by_email_configuration', true ) ) {
 208          $allowed_options['writing'] = array_merge( $allowed_options['writing'], $mail_options );
 209      }
 210  }
 211  
 212  /**
 213   * Filters the allowed options list.
 214   *
 215   * @since 2.7.0
 216   * @deprecated 5.5.0 Use {@see 'allowed_options'} instead.
 217   *
 218   * @param array $allowed_options The allowed options list.
 219   */
 220  $allowed_options = apply_filters_deprecated(
 221      'whitelist_options',
 222      array( $allowed_options ),
 223      '5.5.0',
 224      'allowed_options',
 225      __( 'Please consider writing more inclusive code.' )
 226  );
 227  
 228  /**
 229   * Filters the allowed options list.
 230   *
 231   * @since 5.5.0
 232   *
 233   * @param array $allowed_options The allowed options list.
 234   */
 235  $allowed_options = apply_filters( 'allowed_options', $allowed_options );
 236  
 237  if ( 'update' === $action ) { // We are saving settings sent from a settings page.
 238      if ( 'options' === $option_page && ! isset( $_POST['option_page'] ) ) { // This is for back compat and will eventually be removed.
 239          $unregistered = true;
 240          check_admin_referer( 'update-options' );
 241      } else {
 242          $unregistered = false;
 243          check_admin_referer( $option_page . '-options' );
 244      }
 245  
 246      if ( ! isset( $allowed_options[ $option_page ] ) ) {
 247          wp_die(
 248              sprintf(
 249                  /* translators: %s: The options page name. */
 250                  __( '<strong>Error:</strong> The %s options page is not in the allowed options list.' ),
 251                  '<code>' . esc_html( $option_page ) . '</code>'
 252              )
 253          );
 254      }
 255  
 256      if ( 'options' === $option_page ) {
 257          if ( is_multisite() && ! current_user_can( 'manage_network_options' ) ) {
 258              wp_die( __( 'Sorry, you are not allowed to modify unregistered settings for this site.' ) );
 259          }
 260          $options = isset( $_POST['page_options'] ) ? explode( ',', wp_unslash( $_POST['page_options'] ) ) : null;
 261      } else {
 262          $options = $allowed_options[ $option_page ];
 263      }
 264  
 265      if ( 'general' === $option_page ) {
 266          // Handle custom date/time formats.
 267          if ( ! empty( $_POST['date_format'] ) && isset( $_POST['date_format_custom'] )
 268              && '\c\u\s\t\o\m' === wp_unslash( $_POST['date_format'] )
 269          ) {
 270              $_POST['date_format'] = $_POST['date_format_custom'];
 271          }
 272  
 273          if ( ! empty( $_POST['time_format'] ) && isset( $_POST['time_format_custom'] )
 274              && '\c\u\s\t\o\m' === wp_unslash( $_POST['time_format'] )
 275          ) {
 276              $_POST['time_format'] = $_POST['time_format_custom'];
 277          }
 278  
 279          // Map UTC+- timezones to gmt_offsets and set timezone_string to empty.
 280          if ( ! empty( $_POST['timezone_string'] ) && preg_match( '/^UTC[+-]/', $_POST['timezone_string'] ) ) {
 281              $_POST['gmt_offset']      = $_POST['timezone_string'];
 282              $_POST['gmt_offset']      = preg_replace( '/UTC\+?/', '', $_POST['gmt_offset'] );
 283              $_POST['timezone_string'] = '';
 284          } elseif ( isset( $_POST['timezone_string'] ) && ! in_array( $_POST['timezone_string'], timezone_identifiers_list( DateTimeZone::ALL_WITH_BC ), true ) ) {
 285              // Reset to the current value.
 286              $current_timezone_string = get_option( 'timezone_string' );
 287  
 288              if ( ! empty( $current_timezone_string ) ) {
 289                  $_POST['timezone_string'] = $current_timezone_string;
 290              } else {
 291                  $_POST['gmt_offset']      = get_option( 'gmt_offset' );
 292                  $_POST['timezone_string'] = '';
 293              }
 294  
 295              add_settings_error(
 296                  'general',
 297                  'settings_updated',
 298                  __( 'The timezone you have entered is not valid. Please select a valid timezone.' ),
 299                  'error'
 300              );
 301          }
 302  
 303          // Handle translation installation.
 304          if ( ! empty( $_POST['WPLANG'] ) && current_user_can( 'install_languages' ) ) {
 305              require_once  ABSPATH . 'wp-admin/includes/translation-install.php';
 306  
 307              if ( wp_can_install_language_pack() ) {
 308                  $language = wp_download_language_pack( $_POST['WPLANG'] );
 309                  if ( $language ) {
 310                      $_POST['WPLANG'] = $language;
 311                  }
 312              }
 313          }
 314      }
 315  
 316      if ( $options ) {
 317          $user_language_old = get_user_locale();
 318  
 319          foreach ( $options as $option ) {
 320              if ( $unregistered ) {
 321                  _deprecated_argument(
 322                      'options.php',
 323                      '2.7.0',
 324                      sprintf(
 325                          /* translators: %s: The option/setting. */
 326                          __( 'The %s setting is unregistered. Unregistered settings are deprecated. See https://developer.wordpress.org/plugins/settings/settings-api/' ),
 327                          '<code>' . esc_html( $option ) . '</code>'
 328                      )
 329                  );
 330              }
 331  
 332              $option = trim( $option );
 333              $value  = null;
 334              if ( isset( $_POST[ $option ] ) ) {
 335                  $value = $_POST[ $option ];
 336                  if ( ! is_array( $value ) ) {
 337                      $value = trim( $value );
 338                  }
 339                  $value = wp_unslash( $value );
 340              }
 341              update_option( $option, $value );
 342          }
 343  
 344          /*
 345           * Switch translation in case WPLANG was changed.
 346           * The global $locale is used in get_locale() which is
 347           * used as a fallback in get_user_locale().
 348           */
 349          unset( $GLOBALS['locale'] );
 350          $user_language_new = get_user_locale();
 351          if ( $user_language_old !== $user_language_new ) {
 352              load_default_textdomain( $user_language_new );
 353          }
 354      } else {
 355          add_settings_error( 'general', 'settings_updated', __( 'Settings save failed.' ), 'error' );
 356      }
 357  
 358      /*
 359       * Handle settings errors and return to options page.
 360       */
 361  
 362      // If no settings errors were registered add a general 'updated' message.
 363      if ( ! count( get_settings_errors() ) ) {
 364          add_settings_error( 'general', 'settings_updated', __( 'Settings saved.' ), 'success' );
 365      }
 366  
 367      set_transient( 'settings_errors', get_settings_errors(), 30 ); // 30 seconds.
 368  
 369      // Redirect back to the settings page that was submitted.
 370      $goback = add_query_arg( 'settings-updated', 'true', wp_get_referer() );
 371      wp_redirect( $goback );
 372      exit;
 373  }
 374  
 375  require_once  ABSPATH . 'wp-admin/admin-header.php';
 376  ?>
 377  
 378  <div class="wrap">
 379      <h1><?php esc_html_e( 'All Settings' ); ?></h1>
 380  
 381      <?php
 382      wp_admin_notice(
 383          '<strong>' . __( 'Warning:' ) . '</strong> ' . __( 'This page allows direct access to your site settings. You can break things here. Please be cautious!' ),
 384          array(
 385              'type' => 'warning',
 386          )
 387      );
 388      ?>
 389      <form name="form" action="options.php" method="post" id="all-options">
 390          <?php wp_nonce_field( 'options-options' ); ?>
 391          <input type="hidden" name="action" value="update" />
 392          <input type="hidden" name="option_page" value="options" />
 393          <table class="form-table" role="presentation">
 394  <?php
 395  $options = $wpdb->get_results( "SELECT * FROM $wpdb->options ORDER BY option_name" );
 396  
 397  foreach ( (array) $options as $option ) :
 398      $disabled = false;
 399  
 400      if ( '' === $option->option_name ) {
 401          continue;
 402      }
 403  
 404      if ( is_serialized( $option->option_value ) ) {
 405          if ( is_serialized_string( $option->option_value ) ) {
 406              // This is a serialized string, so we should display it.
 407              $value               = maybe_unserialize( $option->option_value );
 408              $options_to_update[] = $option->option_name;
 409              $class               = 'all-options';
 410          } else {
 411              $value    = 'SERIALIZED DATA';
 412              $disabled = true;
 413              $class    = 'all-options disabled';
 414          }
 415      } else {
 416          $value               = $option->option_value;
 417          $options_to_update[] = $option->option_name;
 418          $class               = 'all-options';
 419      }
 420  
 421      $name = esc_attr( $option->option_name );
 422      ?>
 423  <tr>
 424      <th scope="row"><label for="<?php echo $name; ?>"><?php echo esc_html( $option->option_name ); ?></label></th>
 425  <td>
 426      <?php if ( str_contains( $value, "\n" ) ) : ?>
 427          <textarea class="<?php echo $class; ?>" name="<?php echo $name; ?>" id="<?php echo $name; ?>" cols="30" rows="5"><?php echo esc_textarea( $value ); ?></textarea>
 428      <?php else : ?>
 429          <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 ); ?> />
 430      <?php endif; ?></td>
 431  </tr>
 432  <?php endforeach; ?>
 433  </table>
 434  
 435  <input type="hidden" name="page_options" value="<?php echo esc_attr( implode( ',', $options_to_update ) ); ?>" />
 436  
 437  <?php submit_button( __( 'Save Changes' ), 'primary', 'Update' ); ?>
 438  
 439  </form>
 440  </div>
 441  
 442  <?php
 443  require_once  ABSPATH . 'wp-admin/admin-footer.php';


Generated : Thu May 9 08:20:02 2024 Cross-referenced by PHPXref