42 * @param string $capability The capability used for the page, which is manage_options by default. |
42 * @param string $capability The capability used for the page, which is manage_options by default. |
43 */ |
43 */ |
44 $capability = apply_filters( "option_page_capability_{$option_page}", $capability ); |
44 $capability = apply_filters( "option_page_capability_{$option_page}", $capability ); |
45 } |
45 } |
46 |
46 |
47 if ( !current_user_can( $capability ) ) |
47 if ( ! current_user_can( $capability ) ) { |
48 wp_die( __( 'Cheatin’ uh?' ), 403 ); |
48 wp_die( |
|
49 '<h1>' . __( 'You need a higher level of permission.' ) . '</h1>' . |
|
50 '<p>' . __( 'Sorry, you are not allowed to manage these options.' ) . '</p>', |
|
51 403 |
|
52 ); |
|
53 } |
49 |
54 |
50 // Handle admin email change requests |
55 // Handle admin email change requests |
51 if ( is_multisite() ) { |
56 if ( ! empty( $_GET[ 'adminhash' ] ) ) { |
52 if ( ! empty($_GET[ 'adminhash' ] ) ) { |
57 $new_admin_details = get_option( 'adminhash' ); |
53 $new_admin_details = get_option( 'adminhash' ); |
58 $redirect = 'options-general.php?updated=false'; |
54 $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' ] ) ) { |
55 if ( is_array( $new_admin_details ) && $new_admin_details[ 'hash' ] == $_GET[ 'adminhash' ] && !empty($new_admin_details[ 'newemail' ]) ) { |
60 update_option( 'admin_email', $new_admin_details[ 'newemail' ] ); |
56 update_option( 'admin_email', $new_admin_details[ 'newemail' ] ); |
|
57 delete_option( 'adminhash' ); |
|
58 delete_option( 'new_admin_email' ); |
|
59 $redirect = 'options-general.php?updated=true'; |
|
60 } |
|
61 wp_redirect( admin_url( $redirect ) ); |
|
62 exit; |
|
63 } elseif ( ! empty( $_GET['dismiss'] ) && 'new_admin_email' == $_GET['dismiss'] ) { |
|
64 delete_option( 'adminhash' ); |
61 delete_option( 'adminhash' ); |
65 delete_option( 'new_admin_email' ); |
62 delete_option( 'new_admin_email' ); |
66 wp_redirect( admin_url( 'options-general.php?updated=true' ) ); |
63 $redirect = 'options-general.php?updated=true'; |
67 exit; |
64 } |
68 } |
65 wp_redirect( admin_url( $redirect ) ); |
69 } |
66 exit; |
70 |
67 } elseif ( ! empty( $_GET['dismiss'] ) && 'new_admin_email' == $_GET['dismiss'] ) { |
71 if ( is_multisite() && !is_super_admin() && 'update' != $action ) |
68 check_admin_referer( 'dismiss-' . get_current_blog_id() . '-new_admin_email' ); |
72 wp_die( __( 'Cheatin’ uh?' ), 403 ); |
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>' . __( 'You need a higher level of permission.' ) . '</h1>' . |
|
78 '<p>' . __( 'Sorry, you are not allowed to delete these items.' ) . '</p>', |
|
79 403 |
|
80 ); |
|
81 } |
73 |
82 |
74 $whitelist_options = array( |
83 $whitelist_options = array( |
75 'general' => array( 'blogname', 'blogdescription', 'gmt_offset', 'date_format', 'time_format', 'start_of_week', 'timezone_string', 'WPLANG' ), |
84 'general' => array( |
76 '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' ), |
85 'blogname', |
77 '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' ), |
86 'blogdescription', |
78 'reading' => array( 'posts_per_page', 'posts_per_rss', 'rss_use_excerpt', 'show_on_front', 'page_on_front', 'page_for_posts', 'blog_public' ), |
87 'gmt_offset', |
79 'writing' => array( 'use_smilies', 'default_category', 'default_email_category', 'use_balanceTags', 'default_link_category', 'default_post_format' ) |
88 'date_format', |
|
89 'time_format', |
|
90 'start_of_week', |
|
91 'timezone_string', |
|
92 'WPLANG', |
|
93 'new_admin_email', |
|
94 ), |
|
95 'discussion' => array( |
|
96 'default_pingback_flag', |
|
97 'default_ping_status', |
|
98 'default_comment_status', |
|
99 'comments_notify', |
|
100 'moderation_notify', |
|
101 'comment_moderation', |
|
102 'require_name_email', |
|
103 'comment_whitelist', |
|
104 'comment_max_links', |
|
105 'moderation_keys', |
|
106 'blacklist_keys', |
|
107 'show_avatars', |
|
108 'avatar_rating', |
|
109 'avatar_default', |
|
110 'close_comments_for_old_posts', |
|
111 'close_comments_days_old', |
|
112 'thread_comments', |
|
113 'thread_comments_depth', |
|
114 'page_comments', |
|
115 'comments_per_page', |
|
116 'default_comments_page', |
|
117 'comment_order', |
|
118 'comment_registration', |
|
119 'show_comments_cookies_opt_in', |
|
120 ), |
|
121 'media' => array( |
|
122 'thumbnail_size_w', |
|
123 'thumbnail_size_h', |
|
124 'thumbnail_crop', |
|
125 'medium_size_w', |
|
126 'medium_size_h', |
|
127 'large_size_w', |
|
128 'large_size_h', |
|
129 'image_default_size', |
|
130 'image_default_align', |
|
131 'image_default_link_type', |
|
132 ), |
|
133 'reading' => array( |
|
134 'posts_per_page', |
|
135 'posts_per_rss', |
|
136 'rss_use_excerpt', |
|
137 'show_on_front', |
|
138 'page_on_front', |
|
139 'page_for_posts', |
|
140 'blog_public', |
|
141 ), |
|
142 'writing' => array( |
|
143 'default_category', |
|
144 'default_email_category', |
|
145 'default_link_category', |
|
146 'default_post_format', |
|
147 ), |
80 ); |
148 ); |
81 $whitelist_options['misc'] = $whitelist_options['options'] = $whitelist_options['privacy'] = array(); |
149 $whitelist_options['misc'] = $whitelist_options['options'] = $whitelist_options['privacy'] = array(); |
82 |
150 |
83 $mail_options = array('mailserver_url', 'mailserver_port', 'mailserver_login', 'mailserver_pass'); |
151 $mail_options = array('mailserver_url', 'mailserver_port', 'mailserver_login', 'mailserver_pass'); |
84 |
152 |
85 if ( ! in_array( get_option( 'blog_charset' ), array( 'utf8', 'utf-8', 'UTF8', 'UTF-8' ) ) ) |
153 if ( ! in_array( get_option( 'blog_charset' ), array( 'utf8', 'utf-8', 'UTF8', 'UTF-8' ) ) ) |
86 $whitelist_options['reading'][] = 'blog_charset'; |
154 $whitelist_options['reading'][] = 'blog_charset'; |
|
155 |
|
156 if ( get_site_option( 'initial_db_version' ) < 32453 ) { |
|
157 $whitelist_options['writing'][] = 'use_smilies'; |
|
158 $whitelist_options['writing'][] = 'use_balanceTags'; |
|
159 } |
87 |
160 |
88 if ( !is_multisite() ) { |
161 if ( !is_multisite() ) { |
89 if ( !defined( 'WP_SITEURL' ) ) |
162 if ( !defined( 'WP_SITEURL' ) ) |
90 $whitelist_options['general'][] = 'siteurl'; |
163 $whitelist_options['general'][] = 'siteurl'; |
91 if ( !defined( 'WP_HOME' ) ) |
164 if ( !defined( 'WP_HOME' ) ) |
92 $whitelist_options['general'][] = 'home'; |
165 $whitelist_options['general'][] = 'home'; |
93 |
166 |
94 $whitelist_options['general'][] = 'admin_email'; |
|
95 $whitelist_options['general'][] = 'users_can_register'; |
167 $whitelist_options['general'][] = 'users_can_register'; |
96 $whitelist_options['general'][] = 'default_role'; |
168 $whitelist_options['general'][] = 'default_role'; |
97 |
169 |
98 $whitelist_options['writing'] = array_merge($whitelist_options['writing'], $mail_options); |
170 $whitelist_options['writing'] = array_merge($whitelist_options['writing'], $mail_options); |
99 $whitelist_options['writing'][] = 'ping_sites'; |
171 $whitelist_options['writing'][] = 'ping_sites'; |
176 } |
247 } |
177 } |
248 } |
178 } |
249 } |
179 |
250 |
180 if ( $options ) { |
251 if ( $options ) { |
|
252 $user_language_old = get_user_locale(); |
|
253 |
181 foreach ( $options as $option ) { |
254 foreach ( $options as $option ) { |
182 if ( $unregistered ) |
255 if ( $unregistered ) { |
183 _deprecated_argument( 'options.php', '2.7', sprintf( __( 'The <code>%1$s</code> setting is unregistered. Unregistered settings are deprecated. See https://codex.wordpress.org/Settings_API' ), $option, $option_page ) ); |
256 _deprecated_argument( 'options.php', '2.7.0', |
|
257 sprintf( |
|
258 /* translators: %s: the option/setting */ |
|
259 __( 'The %s setting is unregistered. Unregistered settings are deprecated. See https://codex.wordpress.org/Settings_API' ), |
|
260 '<code>' . $option . '</code>' |
|
261 ) |
|
262 ); |
|
263 } |
184 |
264 |
185 $option = trim( $option ); |
265 $option = trim( $option ); |
186 $value = null; |
266 $value = null; |
187 if ( isset( $_POST[ $option ] ) ) { |
267 if ( isset( $_POST[ $option ] ) ) { |
188 $value = $_POST[ $option ]; |
268 $value = $_POST[ $option ]; |
189 if ( ! is_array( $value ) ) |
269 if ( ! is_array( $value ) ) { |
190 $value = trim( $value ); |
270 $value = trim( $value ); |
|
271 } |
191 $value = wp_unslash( $value ); |
272 $value = wp_unslash( $value ); |
192 } |
273 } |
193 update_option( $option, $value ); |
274 update_option( $option, $value ); |
194 } |
275 } |
195 |
276 |
196 // Switch translation in case WPLANG was changed. |
277 /* |
197 $language = get_option( 'WPLANG' ); |
278 * Switch translation in case WPLANG was changed. |
198 if ( $language ) { |
279 * The global $locale is used in get_locale() which is |
199 load_default_textdomain( $language ); |
280 * used as a fallback in get_user_locale(). |
200 } else { |
281 */ |
201 unload_textdomain( 'default' ); |
282 unset( $GLOBALS['locale'] ); |
|
283 $user_language_new = get_user_locale(); |
|
284 if ( $user_language_old !== $user_language_new ) { |
|
285 load_default_textdomain( $user_language_new ); |
202 } |
286 } |
203 } |
287 } |
204 |
288 |
205 /** |
289 /** |
206 * Handle settings errors and return to options page |
290 * Handle settings errors and return to options page |