WordPress.org

Make WordPress Core

Ticket #7520: image-default-options-r8652-2.patch

File image-default-options-r8652-2.patch, 11.7 KB (added by tellyworth, 10 years ago)

improved patch works with external images also

  • wp-includes/version.php

     
    1515 *
    1616 * @global int $wp_db_version
    1717 */
    18 $wp_db_version = 8586;
     18$wp_db_version = 8645;
    1919
    2020?>
  • wp-admin/includes/schema.php

     
    262262        add_option('large_size_w', 1024);
    263263        add_option('large_size_h', 1024);
    264264
     265        // 2.7
     266        add_option('large_size_w', 1024);
     267        add_option('large_size_h', 1024);
     268        add_option('image_default_link_type', 'file');
     269        add_option('image_default_size', '');
     270        add_option('image_default_align', '');
     271       
    265272        // Delete unused options
    266273        $unusedoptions = array ('blodotgsping_url', 'bodyterminator', 'emailtestonly', 'phoneemail_separator', 'smilies_directory', 'subjectprefix', 'use_bbcode', 'use_blodotgsping', 'use_phoneemail', 'use_quicktags', 'use_weblogsping', 'weblogs_cache_file', 'use_preview', 'use_htmltrans', 'smilies_directory', 'fileupload_allowedusers', 'use_phoneemail', 'default_post_status', 'default_post_category', 'archive_mode', 'time_difference', 'links_minadminlevel', 'links_use_adminlevels', 'links_rating_type', 'links_rating_char', 'links_rating_ignore_zero', 'links_rating_single_image', 'links_rating_image0', 'links_rating_image1', 'links_rating_image2', 'links_rating_image3', 'links_rating_image4', 'links_rating_image5', 'links_rating_image6', 'links_rating_image7', 'links_rating_image8', 'links_rating_image9', 'weblogs_cacheminutes', 'comment_allowed_tags', 'search_engine_friendly_urls', 'default_geourl_lat', 'default_geourl_lon', 'use_default_geourl', 'weblogs_xml_url', 'new_users_can_blog', '_wpnonce', '_wp_http_referer', 'Update', 'action', 'rich_editing', 'autosave_interval', 'deactivated_plugins');
    267274        foreach ($unusedoptions as $option) :
  • wp-admin/includes/media.php

     
    520520        return wp_iframe( 'media_upload_library_form', $errors );
    521521}
    522522
     523// produce HTML for the image alignment radio buttons with the specified one checked
     524function image_align_input_fields($post, $checked='') {
     525       
     526        $alignments = array('none' => 'None', 'left' => 'Left', 'center' => 'Center', 'right' => 'Right');
     527        if ( !array_key_exists($checked, $alignments) )
     528                $checked = 'none';
     529       
     530        $out = array();
     531        foreach ($alignments as $name => $label) {
     532       
     533                $out[] = "<input type='radio' name='attachments[{$post->ID}][align]' id='image-align-{$name}-{$post->ID}' value='none'".
     534                        ( $checked == $name ? " checked='checked'" : "" ) .
     535                        " /><label for='image-align-{$name}-{$post->ID}' class='align image-align-{$name}-label'>" . __($label) . "</label>";
     536        }
     537        return join("\n", $out);
     538}
     539
     540// produce HTML for the size radio buttons with the specified one checked
    523541function image_size_input_fields($post, $checked='') {
    524542               
    525543                // get a list of the actual pixel dimensions of each possible intermediate version of this image
    526                 $sizes = array();
    527544                $size_names = array('thumbnail' => 'Thumbnail', 'medium' => 'Medium', 'large' => 'Large', 'full' => 'Full size');
    528545               
    529546                foreach ( $size_names as $size => $name) {
     
    555572                );
    556573}
    557574
     575// produce HTML for the Link URL buttons with the default link type as specified
     576function image_link_input_fields($post, $url_type='') {
     577
     578        $file = wp_get_attachment_url($post->ID);
     579        $link = get_attachment_link($post->ID);
     580
     581        $url = '';
     582        if ( $url_type == 'file' )
     583                $url = $file;
     584        elseif ( $url_type == 'post' )
     585                $url = $link;
     586       
     587        return "<input type='text' name='attachments[$post->ID][url]' value='" . attribute_escape($url) . "' /><br />
     588                                <button type='button' class='button url-$post->ID' value=''>" . __('None') . "</button>
     589                                <button type='button' class='button url-$post->ID' value='" . attribute_escape($file) . "'>" . __('File URL') . "</button>
     590                                <button type='button' class='button url-$post->ID' value='" . attribute_escape($link) . "'>" . __('Post URL') . "</button>
     591                                <script type='text/javascript'>
     592                                jQuery('button.url-$post->ID').bind('click', function(){jQuery(this).siblings('input').val(this.value);});
     593                                </script>\n";
     594}
     595
    558596function image_attachment_fields_to_edit($form_fields, $post) {
    559597        if ( substr($post->post_mime_type, 0, 5) == 'image' ) {
    560598                $form_fields['post_title']['required'] = true;
     
    567605                $form_fields['align'] = array(
    568606                        'label' => __('Alignment'),
    569607                        'input' => 'html',
    570                         'html'  => "
    571                                 <input type='radio' name='attachments[$post->ID][align]' id='image-align-none-$post->ID' value='none' checked='checked' />
    572                                 <label for='image-align-none-$post->ID' class='align image-align-none-label'>" . __('None') . "</label>
    573                                 <input type='radio' name='attachments[$post->ID][align]' id='image-align-left-$post->ID' value='left' />
    574                                 <label for='image-align-left-$post->ID' class='align image-align-left-label'>" . __('Left') . "</label>
    575                                 <input type='radio' name='attachments[$post->ID][align]' id='image-align-center-$post->ID' value='center' />
    576                                 <label for='image-align-center-$post->ID' class='align image-align-center-label'>" . __('Center') . "</label>
    577                                 <input type='radio' name='attachments[$post->ID][align]' id='image-align-right-$post->ID' value='right' />
    578                                 <label for='image-align-right-$post->ID' class='align image-align-right-label'>" . __('Right') . "</label>\n",
     608                        'html'  => image_align_input_fields($post, get_option('image_default_align')),
    579609                );
    580                 $form_fields['image-size'] = image_size_input_fields($post);
     610               
     611                $form_fields['image-size'] = image_size_input_fields($post, get_option('image_default_size'));
    581612        }
    582613        return $form_fields;
    583614}
     
    654685                'url'          => array(
    655686                        'label'      => __('Link URL'),
    656687                        'input'      => 'html',
    657                         'html'       => "
    658                                 <input type='text' name='attachments[$post->ID][url]' value='" . attribute_escape($file) . "' /><br />
    659                                 <button type='button' class='button url-$post->ID' value=''>" . __('None') . "</button>
    660                                 <button type='button' class='button url-$post->ID' value='" . attribute_escape($file) . "'>" . __('File URL') . "</button>
    661                                 <button type='button' class='button url-$post->ID' value='" . attribute_escape($link) . "'>" . __('Post URL') . "</button>
    662                                 <script type='text/javascript'>
    663                                 jQuery('button.url-$post->ID').bind('click', function(){jQuery(this).siblings('input').val(this.value);});
    664                                 </script>\n",
     688                        'html'       => image_link_input_fields($post, get_option('image_default_link_type')),
    665689                        'helps'      => __('Enter a link URL or click above for presets.'),
    666690                ),
    667691        'menu_order'   => array(
     
    13121336                $alt_help = __('Also used as alternate text for the image');
    13131337        }
    13141338
     1339        $default_align = get_option('image_default_align');
     1340        if ( empty($default_align) )
     1341                $default_align = 'none';
     1342               
    13151343        return '
    13161344        <table class="describe"><tbody>
    13171345                <tr>
     
    13411369                <tr class="align">
    13421370                        <th valign="top" scope="row" class="label"><p><label for="align">' . __('Alignment') . '</label></p></th>
    13431371                        <td class="field">
    1344                                 <input name="align" id="align-none" value="alignnone" onclick="addExtImage.align=this.value" type="radio" checked="checked" />
     1372                                <input name="align" id="align-none" value="alignnone" onclick="addExtImage.align=this.value" type="radio"' . ($default_align == 'none' ? ' checked="checked"' : '').' />
    13451373                                <label for="align-none" class="align image-align-none-label">' . __('None') . '</label>
    1346                                 <input name="align" id="align-left" value="alignleft" onclick="addExtImage.align=this.value" type="radio" />
     1374                                <input name="align" id="align-left" value="alignleft" onclick="addExtImage.align=this.value" type="radio"' . ($default_align == 'left' ? ' checked="checked"' : '').' />
    13471375                                <label for="align-left" class="align image-align-left-label">' . __('Left') . '</label>
    1348                                 <input name="align" id="align-center" value="aligncenter" onclick="addExtImage.align=this.value" type="radio" />
     1376                                <input name="align" id="align-center" value="aligncenter" onclick="addExtImage.align=this.value" type="radio"' . ($default_align == 'center' ? ' checked="checked"' : '').' />
    13491377                                <label for="align-center" class="align image-align-center-label">' . __('Center') . '</label>
    1350                                 <input name="align" id="align-right" value="alignright" onclick="addExtImage.align=this.value" type="radio" />
     1378                                <input name="align" id="align-right" value="alignright" onclick="addExtImage.align=this.value" type="radio"' . ($default_align == 'right' ? ' checked="checked"' : '').' />
    13511379                                <label for="align-right" class="align image-align-right-label">' . __('Right') . '</label>
    13521380                        </td>
    13531381                </tr>
  • wp-admin/options-misc.php

     
    7171<input name="large_size_h" type="text" id="large_size_h" value="<?php form_option('large_size_h'); ?>" size="6" />
    7272</fieldset></td>
    7373</tr>
     74
     75<tr valign="top">
     76<th scope="row"><?php _e('Default image size') ?></th>
     77<td><fieldset><legend class="hidden"><?php _e('Default image size') ?></legend>
     78<?php
     79        $size_names = array('' => 'Auto', 'thumbnail' => 'Thumbnail', 'medium' => 'Medium', 'large' => 'Large', 'full' => 'Full size');
     80        foreach ($size_names as $size => $name) { ?>
     81                <input type="radio" name="image_default_size" id="image_default_size_<?php echo $size; ?>" value="<?php echo $size; ?>"<?php echo (get_option('image_default_size') == $size ? ' checked="checked"' : ''); ?> />                       
     82                <label for="image_default_size_<?php echo $size; ?>"><?php _e($name); ?></label>
     83        <?php
     84        }
     85
     86?>
     87</fieldset></td>
     88</tr>
     89
     90<tr valign="top">
     91<th scope="row"><?php _e('Default image alignment') ?></th>
     92<td><fieldset><legend class="hidden"><?php _e('Default image alignment') ?></legend>
     93<?php
     94        $alignments = array('none' => 'None', 'left' => 'Left', 'center' => 'Center', 'right' => 'Right');
     95        foreach ($alignments as $align => $name) { ?>
     96                <input type="radio" name="image_default_align" id="image_default_align_<?php echo $align; ?>" value="<?php echo $align; ?>"<?php echo (get_option('image_default_align') == $align ? ' checked="checked"' : ''); ?> />                 
     97                <label for="image_default_align_<?php echo $align; ?>"><?php _e($name); ?></label>
     98        <?php
     99        }
     100
     101?>
     102</fieldset></td>
     103</tr>
     104
     105<tr valign="top">
     106<th scope="row"><?php _e('Default image links') ?></th>
     107<td><fieldset><legend class="hidden"><?php _e('Default image links') ?></legend>
     108<?php
     109        $link_types = array('' => 'None', 'post' => 'Post URL', 'file' => 'File');
     110        foreach ($link_types as $type => $name) { ?>
     111                <input type="radio" name="image_default_link_type" id="image_default_link_type_<?php echo $type; ?>" value="<?php echo $type; ?>"<?php echo (get_option('image_default_link_type') == $type ? ' checked="checked"' : ''); ?> />                 
     112                <label for="image_default_link_type_<?php echo $type; ?>"><?php _e($name); ?></label>
     113        <?php
     114        }
     115
     116?>
     117</fieldset></td>
     118</tr>
     119
    74120</table>
    75121
    76122
     
    99145
    100146<p class="submit">
    101147<input type="hidden" name="action" value="update" />
    102 <input type="hidden" name="page_options" value="hack_file,use_linksupdate,uploads_use_yearmonth_folders,upload_path,upload_url_path,thumbnail_size_w,thumbnail_size_h,thumbnail_crop,medium_size_w,medium_size_h" />
     148<input type="hidden" name="page_options" value="hack_file,use_linksupdate,uploads_use_yearmonth_folders,upload_path,upload_url_path,thumbnail_size_w,thumbnail_size_h,thumbnail_crop,medium_size_w,medium_size_h,image_default_size,image_default_align,image_default_link_type" />
    103149<input type="submit" name="Submit" value="<?php _e('Save Changes') ?>" class="button" />
    104150</p>
    105151</form>