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