options.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  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 options for this site.' ) . '</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'] = array();
  140. $whitelist_options['options'] = array();
  141. $whitelist_options['privacy'] = array();
  142. $mail_options = array( 'mailserver_url', 'mailserver_port', 'mailserver_login', 'mailserver_pass' );
  143. if ( ! in_array( get_option( 'blog_charset' ), array( 'utf8', 'utf-8', 'UTF8', 'UTF-8' ) ) ) {
  144. $whitelist_options['reading'][] = 'blog_charset';
  145. }
  146. if ( get_site_option( 'initial_db_version' ) < 32453 ) {
  147. $whitelist_options['writing'][] = 'use_smilies';
  148. $whitelist_options['writing'][] = 'use_balanceTags';
  149. }
  150. if ( ! is_multisite() ) {
  151. if ( ! defined( 'WP_SITEURL' ) ) {
  152. $whitelist_options['general'][] = 'siteurl';
  153. }
  154. if ( ! defined( 'WP_HOME' ) ) {
  155. $whitelist_options['general'][] = 'home';
  156. }
  157. $whitelist_options['general'][] = 'users_can_register';
  158. $whitelist_options['general'][] = 'default_role';
  159. $whitelist_options['writing'] = array_merge( $whitelist_options['writing'], $mail_options );
  160. $whitelist_options['writing'][] = 'ping_sites';
  161. $whitelist_options['media'][] = 'uploads_use_yearmonth_folders';
  162. // If upload_url_path and upload_path are both default values, they're locked.
  163. if ( get_option( 'upload_url_path' ) || ( get_option( 'upload_path' ) != 'wp-content/uploads' && get_option( 'upload_path' ) ) ) {
  164. $whitelist_options['media'][] = 'upload_path';
  165. $whitelist_options['media'][] = 'upload_url_path';
  166. }
  167. } else {
  168. /**
  169. * Filters whether the post-by-email functionality is enabled.
  170. *
  171. * @since 3.0.0
  172. *
  173. * @param bool $enabled Whether post-by-email configuration is enabled. Default true.
  174. */
  175. if ( apply_filters( 'enable_post_by_email_configuration', true ) ) {
  176. $whitelist_options['writing'] = array_merge( $whitelist_options['writing'], $mail_options );
  177. }
  178. }
  179. /**
  180. * Filters the options white list.
  181. *
  182. * @since 2.7.0
  183. *
  184. * @param array $whitelist_options White list options.
  185. */
  186. $whitelist_options = apply_filters( 'whitelist_options', $whitelist_options );
  187. /*
  188. * If $_GET['action'] == 'update' we are saving settings sent from a settings page
  189. */
  190. if ( 'update' == $action ) {
  191. if ( 'options' == $option_page && ! isset( $_POST['option_page'] ) ) { // This is for back compat and will eventually be removed.
  192. $unregistered = true;
  193. check_admin_referer( 'update-options' );
  194. } else {
  195. $unregistered = false;
  196. check_admin_referer( $option_page . '-options' );
  197. }
  198. if ( ! isset( $whitelist_options[ $option_page ] ) ) {
  199. wp_die( __( '<strong>ERROR</strong>: options page not found.' ) );
  200. }
  201. if ( 'options' == $option_page ) {
  202. if ( is_multisite() && ! current_user_can( 'manage_network_options' ) ) {
  203. wp_die( __( 'Sorry, you are not allowed to modify unregistered settings for this site.' ) );
  204. }
  205. $options = explode( ',', wp_unslash( $_POST['page_options'] ) );
  206. } else {
  207. $options = $whitelist_options[ $option_page ];
  208. }
  209. if ( 'general' == $option_page ) {
  210. // Handle custom date/time formats.
  211. if ( ! empty( $_POST['date_format'] ) && isset( $_POST['date_format_custom'] ) && '\c\u\s\t\o\m' == wp_unslash( $_POST['date_format'] ) ) {
  212. $_POST['date_format'] = $_POST['date_format_custom'];
  213. }
  214. if ( ! empty( $_POST['time_format'] ) && isset( $_POST['time_format_custom'] ) && '\c\u\s\t\o\m' == wp_unslash( $_POST['time_format'] ) ) {
  215. $_POST['time_format'] = $_POST['time_format_custom'];
  216. }
  217. // Map UTC+- timezones to gmt_offsets and set timezone_string to empty.
  218. if ( ! empty( $_POST['timezone_string'] ) && preg_match( '/^UTC[+-]/', $_POST['timezone_string'] ) ) {
  219. $_POST['gmt_offset'] = $_POST['timezone_string'];
  220. $_POST['gmt_offset'] = preg_replace( '/UTC\+?/', '', $_POST['gmt_offset'] );
  221. $_POST['timezone_string'] = '';
  222. }
  223. // Handle translation installation.
  224. if ( ! empty( $_POST['WPLANG'] ) && current_user_can( 'install_languages' ) ) {
  225. require_once( ABSPATH . 'wp-admin/includes/translation-install.php' );
  226. if ( wp_can_install_language_pack() ) {
  227. $language = wp_download_language_pack( $_POST['WPLANG'] );
  228. if ( $language ) {
  229. $_POST['WPLANG'] = $language;
  230. }
  231. }
  232. }
  233. }
  234. if ( $options ) {
  235. $user_language_old = get_user_locale();
  236. foreach ( $options as $option ) {
  237. if ( $unregistered ) {
  238. _deprecated_argument(
  239. 'options.php',
  240. '2.7.0',
  241. sprintf(
  242. /* translators: %s: The option/setting. */
  243. __( 'The %s setting is unregistered. Unregistered settings are deprecated. See https://developer.wordpress.org/plugins/settings/settings-api/' ),
  244. '<code>' . $option . '</code>'
  245. )
  246. );
  247. }
  248. $option = trim( $option );
  249. $value = null;
  250. if ( isset( $_POST[ $option ] ) ) {
  251. $value = $_POST[ $option ];
  252. if ( ! is_array( $value ) ) {
  253. $value = trim( $value );
  254. }
  255. $value = wp_unslash( $value );
  256. }
  257. update_option( $option, $value );
  258. }
  259. /*
  260. * Switch translation in case WPLANG was changed.
  261. * The global $locale is used in get_locale() which is
  262. * used as a fallback in get_user_locale().
  263. */
  264. unset( $GLOBALS['locale'] );
  265. $user_language_new = get_user_locale();
  266. if ( $user_language_old !== $user_language_new ) {
  267. load_default_textdomain( $user_language_new );
  268. }
  269. }
  270. /**
  271. * Handle settings errors and return to options page
  272. */
  273. // If no settings errors were registered add a general 'updated' message.
  274. if ( ! count( get_settings_errors() ) ) {
  275. add_settings_error( 'general', 'settings_updated', __( 'Settings saved.' ), 'success' );
  276. }
  277. set_transient( 'settings_errors', get_settings_errors(), 30 );
  278. /**
  279. * Redirect back to the settings page that was submitted
  280. */
  281. $goback = add_query_arg( 'settings-updated', 'true', wp_get_referer() );
  282. wp_redirect( $goback );
  283. exit;
  284. }
  285. include( ABSPATH . 'wp-admin/admin-header.php' ); ?>
  286. <div class="wrap">
  287. <h1><?php esc_html_e( 'All Settings' ); ?></h1>
  288. <div class="notice notice-warning">
  289. <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>
  290. </div>
  291. <form name="form" action="options.php" method="post" id="all-options">
  292. <?php wp_nonce_field( 'options-options' ); ?>
  293. <input type="hidden" name="action" value="update" />
  294. <input type="hidden" name="option_page" value="options" />
  295. <table class="form-table" role="presentation">
  296. <?php
  297. $options = $wpdb->get_results( "SELECT * FROM $wpdb->options ORDER BY option_name" );
  298. foreach ( (array) $options as $option ) :
  299. $disabled = false;
  300. if ( $option->option_name == '' ) {
  301. continue;
  302. }
  303. if ( is_serialized( $option->option_value ) ) {
  304. if ( is_serialized_string( $option->option_value ) ) {
  305. // This is a serialized string, so we should display it.
  306. $value = maybe_unserialize( $option->option_value );
  307. $options_to_update[] = $option->option_name;
  308. $class = 'all-options';
  309. } else {
  310. $value = 'SERIALIZED DATA';
  311. $disabled = true;
  312. $class = 'all-options disabled';
  313. }
  314. } else {
  315. $value = $option->option_value;
  316. $options_to_update[] = $option->option_name;
  317. $class = 'all-options';
  318. }
  319. $name = esc_attr( $option->option_name );
  320. ?>
  321. <tr>
  322. <th scope="row"><label for="<?php echo $name; ?>"><?php echo esc_html( $option->option_name ); ?></label></th>
  323. <td>
  324. <?php if ( strpos( $value, "\n" ) !== false ) : ?>
  325. <textarea class="<?php echo $class; ?>" name="<?php echo $name; ?>" id="<?php echo $name; ?>" cols="30" rows="5"><?php echo esc_textarea( $value ); ?></textarea>
  326. <?php else : ?>
  327. <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 ); ?> />
  328. <?php endif ?></td>
  329. </tr>
  330. <?php endforeach; ?>
  331. </table>
  332. <input type="hidden" name="page_options" value="<?php echo esc_attr( implode( ',', $options_to_update ) ); ?>" />
  333. <?php submit_button( __( 'Save Changes' ), 'primary', 'Update' ); ?>
  334. </form>
  335. </div>
  336. <?php
  337. include( ABSPATH . 'wp-admin/admin-footer.php' );