options.php 13 KB

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