暫無描述

options.php 12KB

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