[ Index ]

PHP Cross Reference of WordPress

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


Generated: Sun Oct 24 01:00:03 2021 Cross-referenced by PHPXref 0.7.1