Ticket #7065 (closed enhancement: fixed)

Opened 3 months ago

Last modified 3 months ago

Add filter 'image_class' to 'get_image_tag' function in 'wp-includes/media.php'

Reported by: ronalfy Assigned to: anonymous
Priority: normal Milestone: 2.6
Component: General Version: 2.5.1
Severity: normal Keywords: has-patch 2nd-opinion
Cc:

Description

As 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.'" />';

Attachments

media.phpdoc.7065.diff (1.8 kB) - added by jacobsantos on 05/30/08 23:38:58.
New filter for get_image_tag() and phpdoc based off of r8027
media.phpdoc.2.5.2.diff (1.8 kB) - added by jacobsantos on 05/30/08 23:42:47.
Patch for 2.5 branch based off of r8027

Change History

05/30/08 23:38:58 changed by jacobsantos

  • attachment media.phpdoc.7065.diff added.

New filter for get_image_tag() and phpdoc based off of r8027

05/30/08 23:40:23 changed by jacobsantos

  • keywords changed from needs-patch to has-patch 2nd-opinion.
  • milestone changed from 2.5.2 to 2.6.

Patch adds new filter named 'get_image_tag_class' to get_image_tag().

05/30/08 23:42:47 changed by jacobsantos

  • attachment media.phpdoc.2.5.2.diff added.

Patch for 2.5 branch based off of r8027

05/30/08 23:43:11 changed by jacobsantos

Added patch for 2.5.x too.

05/31/08 19:12:56 changed by ryan

  • status changed from new to closed.
  • resolution set to fixed.

(In [8029]) New filter and phpdoc for get_image_tag(). Props jacobsantos. fixes #7065 for trunk

05/31/08 19:13:24 changed by ryan

(In [8030]) New filter and phpdoc for get_image_tag(). Props jacobsantos. fixes #7065 for 2.5