[wp-trac] [WordPress Trac] #7065: Add filter 'image_class' to 'get_image_tag' function in 'wp-includes/media.php'

WordPress Trac wp-trac at lists.automattic.com
Fri May 30 06:19:38 GMT 2008


#7065: Add filter 'image_class' to 'get_image_tag' function in 'wp-
includes/media.php'
-------------------------+--------------------------------------------------
 Reporter:  ronalfy      |       Owner:  anonymous  
     Type:  enhancement  |      Status:  new        
 Priority:  normal       |   Milestone:  2.5.2      
Component:  General      |     Version:  2.5.1      
 Severity:  normal       |    Keywords:  needs-patch
-------------------------+--------------------------------------------------
 As [http://weblogtoolscollection.com/archives/2008/05/29/removing-
 widthheight-from-the-image-uploader/#comments referenced in this post],
 some would like the ability to remove or customize the class attribute in
 the media manager.

 Recommended solution is to add a new filter called 'image_class' to the
 'get_image_tag' function in '/wp-includes/media.php'.

 Before:
 {{{
 function get_image_tag($id, $alt, $title, $align, $size='medium') {

         list( $img_src, $width, $height ) = image_downsize($id, $size);
         $hwstring = image_hwstring($width, $height);

         $html = '<img src="'.attribute_escape($img_src).'"
 alt="'.attribute_escape($alt).'" title="'.attribute_escape($title).'"
 '.$hwstring.'class="align'.attribute_escape($align).'
 size-'.attribute_escape($size).' wp-image-'.$id.'" />';

         $url = '';
         $html = apply_filters( 'image_send_to_editor', $html, $id, $alt,
 $title, $align, $url, $size );

         return $html;
 }
 }}}

 After:
 {{{
 function get_image_tag($id, $alt, $title, $align, $size='medium') {

         list( $img_src, $width, $height ) = image_downsize($id, $size);
         $hwstring = image_hwstring($width, $height);
         $class = 'align'.attribute_escape($align).'
 size-'.attribute_escape($size).' wp-image-'.$id;
         $class = apply_filters('image_class', $class, $id, $align, $size);
         $html = '<img src="'.attribute_escape($img_src).'"
 alt="'.attribute_escape($alt).'" title="'.attribute_escape($title).'"
 '.$hwstring.'class="'.$class.'" />';

         $html = apply_filters( 'image_send_to_editor', $html, $id, $alt,
 $title, $align, $url );

         return $html;
 }
 }}}

 Code changed is here:

 {{{
 $class = 'align'.attribute_escape($align).'
 size-'.attribute_escape($size).' wp-image-'.$id;
         $class = apply_filters('image_class', $class, $id, $align, $size);
         $html = '<img src="'.attribute_escape($img_src).'"
 alt="'.attribute_escape($alt).'" title="'.attribute_escape($title).'"
 '.$hwstring.'class="'.$class.'" />';
 }}}

-- 
Ticket URL: <http://trac.wordpress.org/ticket/7065>
WordPress Trac <http://trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list