options.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  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>' . __( 'Cheatin&#8217; uh?' ) . '</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 ( is_multisite() ) {
  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 ) && hash_equals( $new_admin_details[ 'hash' ], $_GET[ 'adminhash' ] ) && !empty($new_admin_details[ 'newemail' ]) ) {
  53. update_option( 'admin_email', $new_admin_details[ 'newemail' ] );
  54. delete_option( 'adminhash' );
  55. delete_option( 'new_admin_email' );
  56. $redirect = 'options-general.php?updated=true';
  57. }
  58. wp_redirect( admin_url( $redirect ) );
  59. exit;
  60. } elseif ( ! empty( $_GET['dismiss'] ) && 'new_admin_email' == $_GET['dismiss'] ) {
  61. check_admin_referer( 'dismiss-' . get_current_blog_id() . '-new_admin_email' );
  62. delete_option( 'adminhash' );
  63. delete_option( 'new_admin_email' );
  64. wp_redirect( admin_url( 'options-general.php?updated=true' ) );
  65. exit;
  66. }
  67. }
  68. if ( is_multisite() && ! is_super_admin() && 'update' != $action ) {
  69. wp_die(
  70. '<h1>' . __( 'Cheatin&#8217; uh?' ) . '</h1>' .
  71. '<p>' . __( 'Sorry, you are not allowed to delete these items.' ) . '</p>',
  72. 403
  73. );
  74. }
  75. $whitelist_options = array(
  76. 'general' => array( 'blogname', 'blogdescription', 'gmt_offset', 'date_format', 'time_format', 'start_of_week', 'timezone_string', 'WPLANG' ),
  77. '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' ),
  78. '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' ),
  79. 'reading' => array( 'posts_per_page', 'posts_per_rss', 'rss_use_excerpt', 'show_on_front', 'page_on_front', 'page_for_posts', 'blog_public' ),
  80. 'writing' => array( 'default_category', 'default_email_category', 'default_link_category', 'default_post_format' )
  81. );
  82. $whitelist_options['misc'] = $whitelist_options['options'] = $whitelist_options['privacy'] = array();
  83. $mail_options = array('mailserver_url', 'mailserver_port', 'mailserver_login', 'mailserver_pass');
  84. if ( ! in_array( get_option( 'blog_charset' ), array( 'utf8', 'utf-8', 'UTF8', 'UTF-8' ) ) )
  85. $whitelist_options['reading'][] = 'blog_charset';
  86. if ( get_site_option( 'initial_db_version' ) < 32453 ) {
  87. $whitelist_options['writing'][] = 'use_smilies';
  88. $whitelist_options['writing'][] = 'use_balanceTags';
  89. }
  90. if ( !is_multisite() ) {
  91. if ( !defined( 'WP_SITEURL' ) )
  92. $whitelist_options['general'][] = 'siteurl';
  93. if ( !defined( 'WP_HOME' ) )
  94. $whitelist_options['general'][] = 'home';
  95. $whitelist_options['general'][] = 'admin_email';
  96. $whitelist_options['general'][] = 'users_can_register';
  97. $whitelist_options['general'][] = 'default_role';
  98. $whitelist_options['writing'] = array_merge($whitelist_options['writing'], $mail_options);
  99. $whitelist_options['writing'][] = 'ping_sites';
  100. $whitelist_options['media'][] = 'uploads_use_yearmonth_folders';
  101. // If upload_url_path and upload_path are both default values, they're locked.
  102. if ( get_option( 'upload_url_path' ) || ( get_option('upload_path') != 'wp-content/uploads' && get_option('upload_path') ) ) {
  103. $whitelist_options['media'][] = 'upload_path';
  104. $whitelist_options['media'][] = 'upload_url_path';
  105. }
  106. } else {
  107. $whitelist_options['general'][] = 'new_admin_email';
  108. /**
  109. * Filters whether the post-by-email functionality is enabled.
  110. *
  111. * @since 3.0.0
  112. *
  113. * @param bool $enabled Whether post-by-email configuration is enabled. Default true.
  114. */
  115. if ( apply_filters( 'enable_post_by_email_configuration', true ) )
  116. $whitelist_options['writing'] = array_merge($whitelist_options['writing'], $mail_options);
  117. }
  118. /**
  119. * Filters the options white list.
  120. *
  121. * @since 2.7.0
  122. *
  123. * @param array White list options.
  124. */
  125. $whitelist_options = apply_filters( 'whitelist_options', $whitelist_options );
  126. /*
  127. * If $_GET['action'] == 'update' we are saving settings sent from a settings page
  128. */
  129. if ( 'update' == $action ) {
  130. if ( 'options' == $option_page && !isset( $_POST['option_page'] ) ) { // This is for back compat and will eventually be removed.
  131. $unregistered = true;
  132. check_admin_referer( 'update-options' );
  133. } else {
  134. $unregistered = false;
  135. check_admin_referer( $option_page . '-options' );
  136. }
  137. if ( !isset( $whitelist_options[ $option_page ] ) )
  138. wp_die( __( '<strong>ERROR</strong>: options page not found.' ) );
  139. if ( 'options' == $option_page ) {
  140. if ( is_multisite() && ! is_super_admin() )
  141. wp_die( __( 'Sorry, you are not allowed to modify unregistered settings for this site.' ) );
  142. $options = explode( ',', wp_unslash( $_POST[ 'page_options' ] ) );
  143. } else {
  144. $options = $whitelist_options[ $option_page ];
  145. }
  146. if ( 'general' == $option_page ) {
  147. // Handle custom date/time formats.
  148. if ( !empty($_POST['date_format']) && isset($_POST['date_format_custom']) && '\c\u\s\t\o\m' == wp_unslash( $_POST['date_format'] ) )
  149. $_POST['date_format'] = $_POST['date_format_custom'];
  150. if ( !empty($_POST['time_format']) && isset($_POST['time_format_custom']) && '\c\u\s\t\o\m' == wp_unslash( $_POST['time_format'] ) )
  151. $_POST['time_format'] = $_POST['time_format_custom'];
  152. // Map UTC+- timezones to gmt_offsets and set timezone_string to empty.
  153. if ( !empty($_POST['timezone_string']) && preg_match('/^UTC[+-]/', $_POST['timezone_string']) ) {
  154. $_POST['gmt_offset'] = $_POST['timezone_string'];
  155. $_POST['gmt_offset'] = preg_replace('/UTC\+?/', '', $_POST['gmt_offset']);
  156. $_POST['timezone_string'] = '';
  157. }
  158. // Handle translation install.
  159. if ( ! empty( $_POST['WPLANG'] ) && ( ! is_multisite() || is_super_admin() ) ) { // @todo: Skip if already installed
  160. require_once( ABSPATH . 'wp-admin/includes/translation-install.php' );
  161. if ( wp_can_install_language_pack() ) {
  162. $language = wp_download_language_pack( $_POST['WPLANG'] );
  163. if ( $language ) {
  164. $_POST['WPLANG'] = $language;
  165. }
  166. }
  167. }
  168. }
  169. if ( $options ) {
  170. $user_language_old = get_user_locale();
  171. foreach ( $options as $option ) {
  172. if ( $unregistered ) {
  173. _deprecated_argument( 'options.php', '2.7.0',
  174. sprintf(
  175. /* translators: %s: the option/setting */
  176. __( 'The %s setting is unregistered. Unregistered settings are deprecated. See https://codex.wordpress.org/Settings_API' ),
  177. '<code>' . $option . '</code>'
  178. )
  179. );
  180. }
  181. $option = trim( $option );
  182. $value = null;
  183. if ( isset( $_POST[ $option ] ) ) {
  184. $value = $_POST[ $option ];
  185. if ( ! is_array( $value ) ) {
  186. $value = trim( $value );
  187. }
  188. $value = wp_unslash( $value );
  189. }
  190. update_option( $option, $value );
  191. }
  192. /*
  193. * Switch translation in case WPLANG was changed.
  194. * The global $locale is used in get_locale() which is
  195. * used as a fallback in get_user_locale().
  196. */
  197. unset( $GLOBALS['locale'] );
  198. $user_language_new = get_user_locale();
  199. if ( $user_language_old !== $user_language_new ) {
  200. load_default_textdomain( $user_language_new );
  201. }
  202. }
  203. /**
  204. * Handle settings errors and return to options page
  205. */
  206. // If no settings errors were registered add a general 'updated' message.
  207. if ( !count( get_settings_errors() ) )
  208. add_settings_error('general', 'settings_updated', __('Settings saved.'), 'updated');
  209. set_transient('settings_errors', get_settings_errors(), 30);
  210. /**
  211. * Redirect back to the settings page that was submitted
  212. */
  213. $goback = add_query_arg( 'settings-updated', 'true', wp_get_referer() );
  214. wp_redirect( $goback );
  215. exit;
  216. }
  217. include( ABSPATH . 'wp-admin/admin-header.php' ); ?>
  218. <div class="wrap">
  219. <h1><?php esc_html_e( 'All Settings' ); ?></h1>
  220. <form name="form" action="options.php" method="post" id="all-options">
  221. <?php wp_nonce_field('options-options') ?>
  222. <input type="hidden" name="action" value="update" />
  223. <input type="hidden" name="option_page" value="options" />
  224. <table class="form-table">
  225. <?php
  226. $options = $wpdb->get_results( "SELECT * FROM $wpdb->options ORDER BY option_name" );
  227. foreach ( (array) $options as $option ) :
  228. $disabled = false;
  229. if ( $option->option_name == '' )
  230. continue;
  231. if ( is_serialized( $option->option_value ) ) {
  232. if ( is_serialized_string( $option->option_value ) ) {
  233. // This is a serialized string, so we should display it.
  234. $value = maybe_unserialize( $option->option_value );
  235. $options_to_update[] = $option->option_name;
  236. $class = 'all-options';
  237. } else {
  238. $value = 'SERIALIZED DATA';
  239. $disabled = true;
  240. $class = 'all-options disabled';
  241. }
  242. } else {
  243. $value = $option->option_value;
  244. $options_to_update[] = $option->option_name;
  245. $class = 'all-options';
  246. }
  247. $name = esc_attr( $option->option_name );
  248. ?>
  249. <tr>
  250. <th scope="row"><label for="<?php echo $name ?>"><?php echo esc_html( $option->option_name ); ?></label></th>
  251. <td>
  252. <?php if ( strpos( $value, "\n" ) !== false ) : ?>
  253. <textarea class="<?php echo $class ?>" name="<?php echo $name ?>" id="<?php echo $name ?>" cols="30" rows="5"><?php
  254. echo esc_textarea( $value );
  255. ?></textarea>
  256. <?php else: ?>
  257. <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 ) ?> />
  258. <?php endif ?></td>
  259. </tr>
  260. <?php endforeach; ?>
  261. </table>
  262. <input type="hidden" name="page_options" value="<?php echo esc_attr( implode( ',', $options_to_update ) ); ?>" />
  263. <?php submit_button( __( 'Save Changes' ), 'primary', 'Update' ); ?>
  264. </form>
  265. </div>
  266. <?php
  267. include( ABSPATH . 'wp-admin/admin-footer.php' );