options.php 11 KB

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