Make WordPress Core


Ignore:
Timestamp:
11/16/2009 01:37:30 AM (17 years ago)
Author:
azaozz
Message:

Fix improper selection of radio buttons, improve JS for storing image settings, fixes #11021

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/includes/media.php

    r12162 r12188  
    781781function image_align_input_fields( $post, $checked = '' ) {
    782782
     783        if ( empty($checked) )
     784                $checked = get_user_setting('align', 'none');
     785
    783786        $alignments = array('none' => __('None'), 'left' => __('Left'), 'center' => __('Center'), 'right' => __('Right'));
    784787        if ( !array_key_exists( (string) $checked, $alignments ) )
     
    786789
    787790        $out = array();
    788         foreach ($alignments as $name => $label) {
     791        foreach ( $alignments as $name => $label ) {
    789792                $name = esc_attr($name);
    790793                $out[] = "<input type='radio' name='attachments[{$post->ID}][align]' id='image-align-{$name}-{$post->ID}' value='$name'".
    791794                        ( $checked == $name ? " checked='checked'" : "" ) .
    792                         " /><label for='image-align-{$name}-{$post->ID}' class='align image-align-{$name}-label'>" . $label . "</label>";
     795                        " /><label for='image-align-{$name}-{$post->ID}' class='align image-align-{$name}-label'>$label</label>";
    793796        }
    794797        return join("\n", $out);
     
    804807 * @return unknown
    805808 */
    806 function image_size_input_fields( $post, $checked = '' ) {
     809function image_size_input_fields( $post, $check = '' ) {
    807810
    808811                // get a list of the actual pixel dimensions of each possible intermediate version of this image
    809812                $size_names = array('thumbnail' => __('Thumbnail'), 'medium' => __('Medium'), 'large' => __('Large'), 'full' => __('Full size'));
    810813
    811                 foreach ( $size_names as $size => $name ) {
     814                if ( empty($check) )
     815                        $check = get_user_setting('imgsize', 'medium');
     816
     817                foreach ( $size_names as $size => $label ) {
    812818                        $downsize = image_downsize($post->ID, $size);
     819                        $checked = '';
    813820
    814821                        // is this size selectable?
     
    816823                        $css_id = "image-size-{$size}-{$post->ID}";
    817824                        // if this size is the default but that's not available, don't select it
    818                         if ( $checked && !$enabled )
    819                                 $checked = '';
    820                         // if $checked was not specified, default to the first available size that's bigger than a thumbnail
    821                         if ( !$checked && $enabled && 'thumbnail' != $size )
    822                                 $checked = $size;
    823 
    824                         $html = "<div class='image-size-item'><input type='radio' ".( $enabled ? '' : "disabled='disabled'")."name='attachments[$post->ID][image-size]' id='{$css_id}' value='{$size}'".( $checked == $size ? " checked='checked'" : '') ." />";
    825 
    826                         $html .= "<label for='{$css_id}'>" . __($name). "</label>";
     825                        if ( $size == $check ) {
     826                                if ( $enabled )
     827                                        $checked = " checked='checked'";
     828                                else
     829                                        $check = '';
     830                        } elseif ( !$check && $enabled && 'thumbnail' != $size ) {
     831                                // if $check is not enabled, default to the first available size that's bigger than a thumbnail
     832                                $check = $size;
     833                                $checked = " checked='checked'";
     834                        }
     835
     836                        $html = "<div class='image-size-item'><input type='radio' " . ( $enabled ? '' : "disabled='disabled' " ) . "name='attachments[$post->ID][image-size]' id='{$css_id}' value='{$size}'$checked />";
     837
     838                        $html .= "<label for='{$css_id}'>$label</label>";
    827839                        // only show the dimensions if that choice is available
    828840                        if ( $enabled )
     
    850862 * @return unknown
    851863 */
    852 function image_link_input_fields($post, $url_type='') {
     864function image_link_input_fields($post, $url_type = '') {
    853865
    854866        $file = wp_get_attachment_url($post->ID);
    855867        $link = get_attachment_link($post->ID);
     868
     869        if ( empty($url_type) )
     870                $url_type = get_user_setting('urlbutton', 'post');
    856871
    857872        $url = '';
     
    861876                $url = $link;
    862877
    863         return "<input type='text' class='urlfield' name='attachments[$post->ID][url]' value='" . esc_attr($url) . "' /><br />
    864                                 <button type='button' class='button urlnone' title=''>" . __('None') . "</button>
    865                                 <button type='button' class='button urlfile' title='" . esc_attr($file) . "'>" . __('File URL') . "</button>
    866                                 <button type='button' class='button urlpost' title='" . esc_attr($link) . "'>" . __('Post URL') . "</button>
     878        return "
     879        <input type='text' class='urlfield' name='attachments[$post->ID][url]' value='" . esc_attr($url) . "' /><br />
     880        <button type='button' class='button urlnone' title=''>" . __('None') . "</button>
     881        <button type='button' class='button urlfile' title='" . esc_attr($file) . "'>" . __('File URL') . "</button>
     882        <button type='button' class='button urlpost' title='" . esc_attr($link) . "'>" . __('Post URL') . "</button>
    867883";
    868884}
     
    897913                );
    898914
    899                 $form_fields['image-size'] = image_size_input_fields( $post, get_option('image_default_size') );
     915                $form_fields['image-size'] = image_size_input_fields( $post, get_option('image_default_size', 'medium') );
    900916
    901917        } else {
Note: See TracChangeset for help on using the changeset viewer.