Add wp-post-image CSS class to post images. see #10928

git-svn-id: http://svn.automattic.com/wordpress/trunk@12039 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
markjaquith 2009-10-15 14:27:04 +00:00
parent 83364a9737
commit 1310ecbd1c
2 changed files with 38 additions and 0 deletions

View File

@ -215,6 +215,9 @@ add_action('future_page', '_future_post_hook', 5, 2);
add_action('save_post', '_save_post_hook', 5, 2);
add_action('transition_post_status', '_transition_post_status', 5, 3);
add_action('comment_form', 'wp_comment_form_unfiltered_html_nonce');
// Post Image CSS class filtering
add_action( 'begin_fetch_post_image_html', '_wp_post_image_class_filter_add' );
add_action( 'end_fetch_post_image_html', '_wp_post_image_class_filter_remove' );
// Redirect Old Slugs
add_action('template_redirect', 'wp_old_slug_redirect');
add_action('edit_post', 'wp_check_for_changed_slugs');

View File

@ -556,6 +556,41 @@ function wp_get_attachment_image($attachment_id, $size = 'thumbnail', $icon = fa
return $html;
}
/**
* Adds a 'wp-post-image' class to post image thumbnails
* Uses the begin_fetch_post_image_html and end_fetch_post_image_html action hooks to
* dynamically add/remove itself so as to only filter post image thumbnails
*
* @author Mark Jaquith
* @since 2.9.0
* @param array $attr Attributes including src, class, alt, title
* @return array
*/
function _wp_post_image_class_filter( $attr ) {
$attr['class'] .= ' wp-post-image';
return $attr;
}
/**
* Adds _wp_post_image_class_filter to the wp_get_attachment_image_attributes filter
*
* @author Mark Jaquith
* @since 2.9.0
*/
function _wp_post_image_class_filter_add( $attr ) {
add_filter( 'wp_get_attachment_image_attributes', '_wp_post_image_class_filter' );
}
/**
* Removes _wp_post_image_class_filter from the wp_get_attachment_image_attributes filter
*
* @author Mark Jaquith
* @since 2.9.0
*/
function _wp_post_image_class_filter_remove( $attr ) {
remove_filter( 'wp_get_attachment_image_attributes', '_wp_post_image_class_filter' );
}
add_shortcode('wp_caption', 'img_caption_shortcode');
add_shortcode('caption', 'img_caption_shortcode');