WordPress.org

Make WordPress Core

Ticket #18285: 18285.3.diff

File 18285.3.diff, 14.8 KB (added by ryan, 7 years ago)

options-media.php with no options.php, no options-head.php, and registering its own options.

  • wp-admin/admin.php

     
    108108if ( current_user_can( 'manage_options' ) )
    109109        @ini_set( 'memory_limit', apply_filters( 'admin_memory_limit', WP_MAX_MEMORY_LIMIT ) );
    110110
     111if ( function_exists( '_admin_init' ) )
     112        call_user_func( '_admin_init' );
     113
    111114do_action('admin_init');
    112115
    113116if ( isset($plugin_page) ) {
  • wp-admin/options-media.php

     
    66 * @subpackage Administration
    77 */
    88
    9 /** WordPress Administration Bootstrap */
    10 require_once('./admin.php');
    11 
    12 if ( ! current_user_can( 'manage_options' ) )
    13         wp_die( __( 'You do not have sufficient permissions to manage options for this site.' ) );
    14 
    15 $title = __('Media Settings');
    16 $parent_file = 'options-general.php';
    17 
    18 add_contextual_help($current_screen,
    19         '<p>' . __('You can set maximum sizes for images inserted into your written content; you can also insert an image as Full Size.') . '</p>' .
    20         '<p>' . __('The Embed option allows you embed a video, image, or other media content into your content automatically by typing the URL (of the web page where the file lives) on its own line when you create your content.') . '</p>' .
    21         ( is_multisite() ? '' : '<p>' . __('Uploading Options gives you folder and path choices for storing your files in your installation&#8217;s directory.') . '</p>' ) .
    22         '<p>' . __('You must click the Save Changes button at the bottom of the screen for new settings to take effect.') . '</p>' .
    23         '<p><strong>' . __('For more information:') . '</strong></p>' .
    24         '<p>' . __('<a href="http://codex.wordpress.org/Settings_Media_Screen" target="_blank">Documentation on Media Settings</a>') . '</p>' .
    25         '<p>' . __('<a href="http://wordpress.org/support/" target="_blank">Support Forums</a>') . '</p>'
    26 );
    27 
    28 include('./admin-header.php');
    29 
    30 ?>
    31 
    32 <div class="wrap">
    33 <?php screen_icon(); ?>
    34 <h2><?php echo esc_html( $title ); ?></h2>
    35 
    36 <form action="options.php" method="post">
    37 <?php settings_fields('media'); ?>
    38 
    39 <h3><?php _e('Image sizes') ?></h3>
    40 <p><?php _e('The sizes listed below determine the maximum dimensions in pixels to use when inserting an image into the body of a post.'); ?></p>
    41 
    42 <table class="form-table">
    43 <tr valign="top">
    44 <th scope="row"><?php _e('Thumbnail size') ?></th>
    45 <td>
     9function setting_thumbnail_size() { ?>
    4610<label for="thumbnail_size_w"><?php _e('Width'); ?></label>
    4711<input name="thumbnail_size_w" type="text" id="thumbnail_size_w" value="<?php form_option('thumbnail_size_w'); ?>" class="small-text" />
    4812<label for="thumbnail_size_h"><?php _e('Height'); ?></label>
    4913<input name="thumbnail_size_h" type="text" id="thumbnail_size_h" value="<?php form_option('thumbnail_size_h'); ?>" class="small-text" /><br />
    5014<input name="thumbnail_crop" type="checkbox" id="thumbnail_crop" value="1" <?php checked('1', get_option('thumbnail_crop')); ?>/>
    5115<label for="thumbnail_crop"><?php _e('Crop thumbnail to exact dimensions (normally thumbnails are proportional)'); ?></label>
    52 </td>
    53 </tr>
     16<?php
     17}
    5418
    55 <tr valign="top">
    56 <th scope="row"><?php _e('Medium size') ?></th>
    57 <td><fieldset><legend class="screen-reader-text"><span><?php _e('Medium size'); ?></span></legend>
     19function setting_medium_size() { ?>
     20<fieldset><legend class="screen-reader-text"><span><?php _e('Medium size'); ?></span></legend>
    5821<label for="medium_size_w"><?php _e('Max Width'); ?></label>
    5922<input name="medium_size_w" type="text" id="medium_size_w" value="<?php form_option('medium_size_w'); ?>" class="small-text" />
    6023<label for="medium_size_h"><?php _e('Max Height'); ?></label>
    6124<input name="medium_size_h" type="text" id="medium_size_h" value="<?php form_option('medium_size_h'); ?>" class="small-text" />
    62 </fieldset></td>
    63 </tr>
     25</fieldset>
     26<?php
     27}
    6428
    65 <tr valign="top">
    66 <th scope="row"><?php _e('Large size') ?></th>
    67 <td><fieldset><legend class="screen-reader-text"><span><?php _e('Large size'); ?></span></legend>
     29function setting_large_size() { ?>
     30<fieldset><legend class="screen-reader-text"><span><?php _e('Large size'); ?></span></legend>
    6831<label for="large_size_w"><?php _e('Max Width'); ?></label>
    6932<input name="large_size_w" type="text" id="large_size_w" value="<?php form_option('large_size_w'); ?>" class="small-text" />
    7033<label for="large_size_h"><?php _e('Max Height'); ?></label>
    7134<input name="large_size_h" type="text" id="large_size_h" value="<?php form_option('large_size_h'); ?>" class="small-text" />
    72 </fieldset></td>
    73 </tr>
     35</fieldset>
     36<?php
     37}
    7438
    75 <?php do_settings_fields('media', 'default'); ?>
    76 </table>
    77 
    78 <h3><?php _e('Embeds') ?></h3>
    79 
    80 <table class="form-table">
    81 
    82 <tr valign="top">
    83 <th scope="row"><?php _e('Auto-embeds'); ?></th>
    84 <td><fieldset><legend class="screen-reader-text"><span><?php _e('When possible, embed the media content from a URL directly onto the page. For example: links to Flickr and YouTube.'); ?></span></legend>
     39function setting_auto_embed() { ?>
     40<fieldset><legend class="screen-reader-text"><span><?php _e('When possible, embed the media content from a URL directly onto the page. For example: links to Flickr and YouTube.'); ?></span></legend>
    8541<label for="embed_autourls"><input name="embed_autourls" type="checkbox" id="embed_autourls" value="1" <?php checked( '1', get_option('embed_autourls') ); ?>/> <?php _e('When possible, embed the media content from a URL directly onto the page. For example: links to Flickr and YouTube.'); ?></label>
    86 </fieldset></td>
    87 </tr>
     42</fieldset>
     43<?php
     44}
    8845
    89 <tr valign="top">
    90 <th scope="row"><?php _e('Maximum embed size') ?></th>
    91 <td>
     46function setting_max_embed_size() { ?>
    9247<label for="embed_size_w"><?php _e('Width'); ?></label>
    9348<input name="embed_size_w" type="text" id="embed_size_w" value="<?php form_option('embed_size_w'); ?>" class="small-text" />
    9449<label for="embed_size_h"><?php _e('Height'); ?></label>
    9550<input name="embed_size_h" type="text" id="embed_size_h" value="<?php form_option('embed_size_h'); ?>" class="small-text" />
    9651<?php if ( !empty($content_width) ) echo '<br />' . __("If the width value is left blank, embeds will default to the max width of your theme."); ?>
    97 </td>
    98 </tr>
     52<?php
     53}
    9954
    100 <?php do_settings_fields('media', 'embeds'); ?>
    101 </table>
    102 
    103 <?php if ( !is_multisite() ) : ?>
    104 <h3><?php _e('Uploading Files'); ?></h3>
    105 <table class="form-table">
    106 <tr valign="top">
    107 <th scope="row"><label for="upload_path"><?php _e('Store uploads in this folder'); ?></label></th>
    108 <td><input name="upload_path" type="text" id="upload_path" value="<?php echo esc_attr(get_option('upload_path')); ?>" class="regular-text code" />
     55function setting_upload_path() { ?>
     56<input name="upload_path" type="text" id="upload_path" value="<?php echo esc_attr(get_option('upload_path')); ?>" class="regular-text code" />
    10957<span class="description"><?php _e('Default is <code>wp-content/uploads</code>'); ?></span>
    110 </td>
    111 </tr>
     58<?php
     59}
    11260
    113 <tr valign="top">
    114 <th scope="row"><label for="upload_url_path"><?php _e('Full URL path to files'); ?></label></th>
    115 <td><input name="upload_url_path" type="text" id="upload_url_path" value="<?php echo esc_attr( get_option('upload_url_path')); ?>" class="regular-text code" />
     61function setting_upload_url_patch() { ?>
     62<input name="upload_url_path" type="text" id="upload_url_path" value="<?php echo esc_attr( get_option('upload_url_path')); ?>" class="regular-text code" />
    11663<span class="description"><?php _e('Configuring this is optional. By default, it should be blank.'); ?></span>
    117 </td>
    118 </tr>
     64<?php
     65}
    11966
    120 <tr>
    121 <th scope="row" colspan="2" class="th-full">
     67function setting_upload_use_year_month() { ?>
    12268<label for="uploads_use_yearmonth_folders">
    12369<input name="uploads_use_yearmonth_folders" type="checkbox" id="uploads_use_yearmonth_folders" value="1"<?php checked('1', get_option('uploads_use_yearmonth_folders')); ?> />
    12470<?php _e('Organize my uploads into month- and year-based folders'); ?>
    12571</label>
    126 </th>
    127 </tr>
     72<?php
     73}
    12874
    129 <?php do_settings_fields('media', 'uploads'); ?>
    130 </table>
    131 <?php endif; ?>
     75function section_default() {
     76        echo '<p>' . __('The sizes listed below determine the maximum dimensions in pixels to use when inserting an image into the body of a post.') . '</p>';
     77}
    13278
    133 <?php do_settings_sections('media'); ?>
     79function section_embeds() {}
    13480
    135 <?php submit_button(); ?>
     81function section_uploads() {}
    13682
     83function _admin_init() {
     84        $settings = 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', 'embed_autourls', 'embed_size_w', 'embed_size_h' );
     85        if ( ! is_multisite() )
     86                $settings = array_merge( $settings, array('uploads_use_yearmonth_folders', 'upload_path', 'upload_url_path') );
     87
     88        foreach ( $settings as $setting ) {
     89                register_setting( 'media', $setting );
     90        }
     91
     92        add_settings_section( 'default', __('Image sizes'), 'section_default', 'media' );
     93       
     94        add_settings_field( 'thumbnail-size', __('Thumbnail size'), 'setting_thumbnail_size', 'media', 'default' );
     95        add_settings_field( 'medium-size', __('Medium size'), 'setting_medium_size', 'media', 'default' );
     96        add_settings_field( 'large-size', __('Large size'), 'setting_large_size', 'media', 'default' );
     97       
     98        add_settings_section( 'embeds', __('Embeds'), 'section_embeds', 'media' );
     99       
     100        add_settings_field( 'embed_autourls', __('Auto-embeds'), 'setting_auto_embed', 'media', 'embeds' );
     101        add_settings_field( 'max-embed-size', __('Maximum embed size'), 'setting_max_embed_size', 'media', 'embeds' );
     102       
     103        if ( ! is_multisite() ) {
     104                add_settings_section( 'uploads', __('Uploading Files'), 'section_uploads', 'media' );
     105
     106                add_settings_field( 'upload_path', __('Store uploads in this folder'), 'setting_upload_path', 'media', 'uploads' );
     107                add_settings_field( 'upload_url_path', __('Full URL path to files'), 'setting_upload_url_path', 'media', 'uploads' );
     108                add_settings_field( 'uploads_use_yearmonth_folders', '', 'setting_upload_use_year_month', 'media', 'uploads' );
     109        }
     110}
     111
     112/** WordPress Administration Bootstrap */
     113require_once('./admin.php');
     114
     115if ( ! current_user_can( 'manage_options' ) )
     116        wp_die( __( 'You do not have sufficient permissions to manage options for this site.' ) );
     117
     118wp_reset_vars( array( 'action' ) );
     119
     120$title = __('Media Settings');
     121$parent_file = 'options-general.php';
     122
     123add_contextual_help($current_screen,
     124        '<p>' . __('You can set maximum sizes for images inserted into your written content; you can also insert an image as Full Size.') . '</p>' .
     125        '<p>' . __('The Embed option allows you embed a video, image, or other media content into your content automatically by typing the URL (of the web page where the file lives) on its own line when you create your content.') . '</p>' .
     126        ( is_multisite() ? '' : '<p>' . __('Uploading Options gives you folder and path choices for storing your files in your installation&#8217;s directory.') . '</p>' ) .
     127        '<p>' . __('You must click the Save Changes button at the bottom of the screen for new settings to take effect.') . '</p>' .
     128        '<p><strong>' . __('For more information:') . '</strong></p>' .
     129        '<p>' . __('<a href="http://codex.wordpress.org/Settings_Media_Screen" target="_blank">Documentation on Media Settings</a>') . '</p>' .
     130        '<p>' . __('<a href="http://wordpress.org/support/" target="_blank">Support Forums</a>') . '</p>'
     131);
     132
     133if ( 'update' == $action ) {
     134        check_admin_referer( 'media-options' );
     135
     136        $options = $new_whitelist_options['media']; // Lame
     137
     138        foreach ( (array) $options as $option ) {
     139                $option = trim($option);
     140                $value = null;
     141                if ( isset($_POST[$option]) )
     142                        $value = $_POST[$option];
     143                if ( !is_array($value) )
     144                        $value = trim($value);
     145                $value = stripslashes_deep($value);
     146                update_option($option, $value);
     147        }
     148
     149        if ( !count( get_settings_errors() ) )
     150                add_settings_error('general', 'settings_updated', __('Settings saved.'), 'updated');
     151}
     152
     153$no_options_header = true; // Lame
     154
     155include('./admin-header.php');
     156?>
     157
     158<div class="wrap">
     159<?php screen_icon(); ?>
     160<h2><?php echo esc_html( $title ); ?></h2>
     161<?php settings_errors(); ?>
     162<form action="" method="post">
     163<?php
     164settings_fields( 'media' );
     165do_settings_sections( 'media' );
     166submit_button();
     167?>
    137168</form>
    138 
    139169</div>
    140170
    141 <?php include('./admin-footer.php'); ?>
     171<?php
     172include('./admin-footer.php');
  • wp-admin/admin-header.php

     
    215215
    216216do_action('all_admin_notices');
    217217
    218 if ( $parent_file == 'options-general.php' )
     218if ( empty( $no_options_header ) && $parent_file == 'options-general.php' )
    219219        require(ABSPATH . 'wp-admin/options-head.php');
  • wp-admin/options.php

     
    6161$whitelist_options = array(
    6262        'general' => array( 'blogname', 'blogdescription', 'gmt_offset', 'date_format', 'time_format', 'start_of_week', 'timezone_string' ),
    6363        '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' ),
    64         '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', 'embed_autourls', 'embed_size_w', 'embed_size_h' ),
    6564        'privacy' => array( 'blog_public' ),
    6665        'reading' => array( 'posts_per_page', 'posts_per_rss', 'rss_use_excerpt', 'blog_charset', 'show_on_front', 'page_on_front', 'page_for_posts' ),
    6766        'writing' => array( 'default_post_edit_rows', 'use_smilies', 'default_category', 'default_email_category', 'use_balanceTags', 'default_link_category', 'default_post_format', 'enable_app', 'enable_xmlrpc' ),
    6867        'options' => array( '' ) );
    6968
    7069$mail_options = array('mailserver_url', 'mailserver_port', 'mailserver_login', 'mailserver_pass');
    71 $uploads_options = array('uploads_use_yearmonth_folders', 'upload_path', 'upload_url_path');
    7270
    7371if ( !is_multisite() ) {
    7472        if ( !defined( 'WP_SITEURL' ) )
     
    8280
    8381        $whitelist_options['writing'] = array_merge($whitelist_options['writing'], $mail_options);
    8482        $whitelist_options['writing'][] = 'ping_sites';
    85 
    86         $whitelist_options['media'] = array_merge($whitelist_options['media'], $uploads_options);
    8783} else {
    8884        $whitelist_options['general'][] = 'new_admin_email';
    8985        $whitelist_options['general'][] = 'WPLANG';