From 1310ecbd1c163f2420c2305a87a3b838b6e276b2 Mon Sep 17 00:00:00 2001 From: markjaquith Date: Thu, 15 Oct 2009 14:27:04 +0000 Subject: [PATCH] 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 --- wp-includes/default-filters.php | 3 +++ wp-includes/media.php | 35 +++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/wp-includes/default-filters.php b/wp-includes/default-filters.php index ce4127a97..b943dc3d0 100644 --- a/wp-includes/default-filters.php +++ b/wp-includes/default-filters.php @@ -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'); diff --git a/wp-includes/media.php b/wp-includes/media.php index a8493562b..09405830d 100644 --- a/wp-includes/media.php +++ b/wp-includes/media.php @@ -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');