home *** CD-ROM | disk | FTP | other *** search
/ HTML Examples / WP.iso / wordpress / wp-admin / options.php < prev    next >
Encoding:
PHP Script  |  2018-01-24  |  11.2 KB  |  303 lines

  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( dirname( __FILE__ ) . '/admin.php' );
  20.  
  21. $title = __('Settings');
  22. $this_file = 'options.php';
  23. $parent_file = 'options-general.php';
  24.  
  25. wp_reset_vars(array('action', 'option_page'));
  26.  
  27. $capability = 'manage_options';
  28.  
  29. // This is for back compat and will eventually be removed.
  30. if ( empty($option_page) ) {
  31.     $option_page = 'options';
  32. } else {
  33.  
  34.     /**
  35.      * Filters the capability required when using the Settings API.
  36.      *
  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.
  39.      *
  40.      * @since 3.2.0
  41.      *
  42.      * @param string $capability The capability used for the page, which is manage_options by default.
  43.      */
  44.     $capability = apply_filters( "option_page_capability_{$option_page}", $capability );
  45. }
  46.  
  47. if ( ! current_user_can( $capability ) ) {
  48.     wp_die(
  49.         '<h1>' . __( 'Cheatin’ uh?' ) . '</h1>' .
  50.         '<p>' . __( 'Sorry, you are not allowed to manage these options.' ) . '</p>',
  51.         403
  52.     );
  53. }
  54.  
  55. // Handle admin email change requests
  56. if ( ! empty( $_GET[ 'adminhash' ] ) ) {
  57.     $new_admin_details = get_option( 'adminhash' );
  58.     $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' ] ) ) {
  60.         update_option( 'admin_email', $new_admin_details[ 'newemail' ] );
  61.         delete_option( 'adminhash' );
  62.         delete_option( 'new_admin_email' );
  63.         $redirect = 'options-general.php?updated=true';
  64.     }
  65.     wp_redirect( admin_url( $redirect ) );
  66.     exit;
  67. } elseif ( ! empty( $_GET['dismiss'] ) && 'new_admin_email' == $_GET['dismiss'] ) {
  68.     check_admin_referer( 'dismiss-' . get_current_blog_id() . '-new_admin_email' );
  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>' . __( 'Cheatin’ uh?' ) . '</h1>' .
  78.         '<p>' . __( 'Sorry, you are not allowed to delete these items.' ) . '</p>',
  79.         403
  80.     );
  81. }
  82.  
  83. $whitelist_options = array(
  84.     'general' => array( 'blogname', 'blogdescription', 'gmt_offset', 'date_format', 'time_format', 'start_of_week', 'timezone_string', 'WPLANG', 'new_admin_email' ),
  85.     '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' ),
  86.     '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' ),
  87.     'reading' => array( 'posts_per_page', 'posts_per_rss', 'rss_use_excerpt', 'show_on_front', 'page_on_front', 'page_for_posts', 'blog_public' ),
  88.     'writing' => array( 'default_category', 'default_email_category', 'default_link_category', 'default_post_format' )
  89. );
  90. $whitelist_options['misc'] = $whitelist_options['options'] = $whitelist_options['privacy'] = array();
  91.  
  92. $mail_options = array('mailserver_url', 'mailserver_port', 'mailserver_login', 'mailserver_pass');
  93.  
  94. if ( ! in_array( get_option( 'blog_charset' ), array( 'utf8', 'utf-8', 'UTF8', 'UTF-8' ) ) )
  95.     $whitelist_options['reading'][] = 'blog_charset';
  96.  
  97. if ( get_site_option( 'initial_db_version' ) < 32453 ) {
  98.     $whitelist_options['writing'][] = 'use_smilies';
  99.     $whitelist_options['writing'][] = 'use_balanceTags';
  100. }
  101.  
  102. if ( !is_multisite() ) {
  103.     if ( !defined( 'WP_SITEURL' ) )
  104.         $whitelist_options['general'][] = 'siteurl';
  105.     if ( !defined( 'WP_HOME' ) )
  106.         $whitelist_options['general'][] = 'home';
  107.  
  108.     $whitelist_options['general'][] = 'users_can_register';
  109.     $whitelist_options['general'][] = 'default_role';
  110.  
  111.     $whitelist_options['writing'] = array_merge($whitelist_options['writing'], $mail_options);
  112.     $whitelist_options['writing'][] = 'ping_sites';
  113.  
  114.     $whitelist_options['media'][] = 'uploads_use_yearmonth_folders';
  115.  
  116.     // If upload_url_path and upload_path are both default values, they're locked.
  117.     if ( get_option( 'upload_url_path' ) || ( get_option('upload_path') != 'wp-content/uploads' && get_option('upload_path') ) ) {
  118.         $whitelist_options['media'][] = 'upload_path';
  119.         $whitelist_options['media'][] = 'upload_url_path';
  120.     }
  121. } else {
  122.     /**
  123.      * Filters whether the post-by-email functionality is enabled.
  124.      *
  125.      * @since 3.0.0
  126.      *
  127.      * @param bool $enabled Whether post-by-email configuration is enabled. Default true.
  128.      */
  129.     if ( apply_filters( 'enable_post_by_email_configuration', true ) )
  130.         $whitelist_options['writing'] = array_merge($whitelist_options['writing'], $mail_options);
  131. }
  132.  
  133. /**
  134.  * Filters the options white list.
  135.  *
  136.  * @since 2.7.0
  137.  *
  138.  * @param array $whitelist_options White list options.
  139.  */
  140. $whitelist_options = apply_filters( 'whitelist_options', $whitelist_options );
  141.  
  142. /*
  143.  * If $_GET['action'] == 'update' we are saving settings sent from a settings page
  144.  */
  145. if ( 'update' == $action ) {
  146.     if ( 'options' == $option_page && !isset( $_POST['option_page'] ) ) { // This is for back compat and will eventually be removed.
  147.         $unregistered = true;
  148.         check_admin_referer( 'update-options' );
  149.     } else {
  150.         $unregistered = false;
  151.         check_admin_referer( $option_page . '-options' );
  152.     }
  153.  
  154.     if ( !isset( $whitelist_options[ $option_page ] ) )
  155.         wp_die( __( '<strong>ERROR</strong>: options page not found.' ) );
  156.  
  157.     if ( 'options' == $option_page ) {
  158.         if ( is_multisite() && ! current_user_can( 'manage_network_options' ) ) {
  159.             wp_die( __( 'Sorry, you are not allowed to modify unregistered settings for this site.' ) );
  160.         }
  161.         $options = explode( ',', wp_unslash( $_POST[ 'page_options' ] ) );
  162.     } else {
  163.         $options = $whitelist_options[ $option_page ];
  164.     }
  165.  
  166.     if ( 'general' == $option_page ) {
  167.         // Handle custom date/time formats.
  168.         if ( !empty($_POST['date_format']) && isset($_POST['date_format_custom']) && '\c\u\s\t\o\m' == wp_unslash( $_POST['date_format'] ) )
  169.             $_POST['date_format'] = $_POST['date_format_custom'];
  170.         if ( !empty($_POST['time_format']) && isset($_POST['time_format_custom']) && '\c\u\s\t\o\m' == wp_unslash( $_POST['time_format'] ) )
  171.             $_POST['time_format'] = $_POST['time_format_custom'];
  172.         // Map UTC+- timezones to gmt_offsets and set timezone_string to empty.
  173.         if ( !empty($_POST['timezone_string']) && preg_match('/^UTC[+-]/', $_POST['timezone_string']) ) {
  174.             $_POST['gmt_offset'] = $_POST['timezone_string'];
  175.             $_POST['gmt_offset'] = preg_replace('/UTC\+?/', '', $_POST['gmt_offset']);
  176.             $_POST['timezone_string'] = '';
  177.         }
  178.  
  179.         // Handle translation installation.
  180.         if ( ! empty( $_POST['WPLANG'] ) && current_user_can( 'install_languages' ) ) {
  181.             require_once( ABSPATH . 'wp-admin/includes/translation-install.php' );
  182.  
  183.             if ( wp_can_install_language_pack() ) {
  184.                 $language = wp_download_language_pack( $_POST['WPLANG'] );
  185.                 if ( $language ) {
  186.                     $_POST['WPLANG'] = $language;
  187.                 }
  188.             }
  189.         }
  190.     }
  191.  
  192.     if ( $options ) {
  193.         $user_language_old = get_user_locale();
  194.  
  195.         foreach ( $options as $option ) {
  196.             if ( $unregistered ) {
  197.                 _deprecated_argument( 'options.php', '2.7.0',
  198.                     sprintf(
  199.                         /* translators: %s: the option/setting */
  200.                         __( 'The %s setting is unregistered. Unregistered settings are deprecated. See https://codex.wordpress.org/Settings_API' ),
  201.                         '<code>' . $option . '</code>'
  202.                     )
  203.                 );
  204.             }
  205.  
  206.             $option = trim( $option );
  207.             $value = null;
  208.             if ( isset( $_POST[ $option ] ) ) {
  209.                 $value = $_POST[ $option ];
  210.                 if ( ! is_array( $value ) ) {
  211.                     $value = trim( $value );
  212.                 }
  213.                 $value = wp_unslash( $value );
  214.             }
  215.             update_option( $option, $value );
  216.         }
  217.  
  218.         /*
  219.          * Switch translation in case WPLANG was changed.
  220.          * The global $locale is used in get_locale() which is
  221.          * used as a fallback in get_user_locale().
  222.          */
  223.         unset( $GLOBALS['locale'] );
  224.         $user_language_new = get_user_locale();
  225.         if ( $user_language_old !== $user_language_new  ) {
  226.             load_default_textdomain( $user_language_new );
  227.         }
  228.     }
  229.  
  230.     /**
  231.      * Handle settings errors and return to options page
  232.      */
  233.     // If no settings errors were registered add a general 'updated' message.
  234.     if ( !count( get_settings_errors() ) )
  235.         add_settings_error('general', 'settings_updated', __('Settings saved.'), 'updated');
  236.     set_transient('settings_errors', get_settings_errors(), 30);
  237.  
  238.     /**
  239.      * Redirect back to the settings page that was submitted
  240.      */
  241.     $goback = add_query_arg( 'settings-updated', 'true',  wp_get_referer() );
  242.     wp_redirect( $goback );
  243.     exit;
  244. }
  245.  
  246. include( ABSPATH . 'wp-admin/admin-header.php' ); ?>
  247.  
  248. <div class="wrap">
  249.   <h1><?php esc_html_e( 'All Settings' ); ?></h1>
  250.   <form name="form" action="options.php" method="post" id="all-options">
  251.   <?php wp_nonce_field('options-options') ?>
  252.   <input type="hidden" name="action" value="update" />
  253.   <input type="hidden" name="option_page" value="options" />
  254.   <table class="form-table">
  255. <?php
  256. $options = $wpdb->get_results( "SELECT * FROM $wpdb->options ORDER BY option_name" );
  257.  
  258. foreach ( (array) $options as $option ) :
  259.     $disabled = false;
  260.     if ( $option->option_name == '' )
  261.         continue;
  262.     if ( is_serialized( $option->option_value ) ) {
  263.         if ( is_serialized_string( $option->option_value ) ) {
  264.             // This is a serialized string, so we should display it.
  265.             $value = maybe_unserialize( $option->option_value );
  266.             $options_to_update[] = $option->option_name;
  267.             $class = 'all-options';
  268.         } else {
  269.             $value = 'SERIALIZED DATA';
  270.             $disabled = true;
  271.             $class = 'all-options disabled';
  272.         }
  273.     } else {
  274.         $value = $option->option_value;
  275.         $options_to_update[] = $option->option_name;
  276.         $class = 'all-options';
  277.     }
  278.     $name = esc_attr( $option->option_name );
  279.     ?>
  280. <tr>
  281.     <th scope="row"><label for="<?php echo $name ?>"><?php echo esc_html( $option->option_name ); ?></label></th>
  282. <td>
  283. <?php if ( strpos( $value, "\n" ) !== false ) : ?>
  284.     <textarea class="<?php echo $class ?>" name="<?php echo $name ?>" id="<?php echo $name ?>" cols="30" rows="5"><?php
  285.         echo esc_textarea( $value );
  286.     ?></textarea>
  287.     <?php else: ?>
  288.         <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 ) ?> />
  289.     <?php endif ?></td>
  290. </tr>
  291. <?php endforeach; ?>
  292.   </table>
  293.  
  294. <input type="hidden" name="page_options" value="<?php echo esc_attr( implode( ',', $options_to_update ) ); ?>" />
  295.  
  296. <?php submit_button( __( 'Save Changes' ), 'primary', 'Update' ); ?>
  297.  
  298.   </form>
  299. </div>
  300.  
  301. <?php
  302. include( ABSPATH . 'wp-admin/admin-footer.php' );
  303.