Ticket #11571: 11571.6.diff

File 11571.6.diff, 1.8 KB (added by leewillis77, 21 months ago)

Adds filters as per scribu's comments

Line 
1Index: post-thumbnail-template.php
2===================================================================
3--- post-thumbnail-template.php (revision 18627)
4+++ post-thumbnail-template.php (working copy)
5@@ -83,11 +83,10 @@
6  * @since 2.9.0
7  *
8  * @param int $post_id Optional. Post ID.
9- * @param string $size Optional. Image size.  Defaults to 'thumbnail'.
10+ * @param string $size Optional. Image size.  Defaults to 'post-thumbnail'.
11  * @param string|array $attr Optional. Query string or array of attributes.
12  */
13 function get_the_post_thumbnail( $post_id = null, $size = 'post-thumbnail', $attr = '' ) {
14-       $post_id = ( null === $post_id ) ? get_the_ID() : $post_id;
15        $post_thumbnail_id = get_post_thumbnail_id( $post_id );
16        $size = apply_filters( 'post_thumbnail_size', $size );
17        if ( $post_thumbnail_id ) {
18@@ -102,4 +101,27 @@
19        return apply_filters( 'post_thumbnail_html', $html, $post_id, $post_thumbnail_id, $size, $attr );
20 }
21 
22+/**
23+ * Retrieve Post Thumbnail URL
24+ *
25+ * @param int $post_id Optional. Post ID.
26+ * @param string $size Optional. Image size.  Defaults to 'post-thumbnail'.
27+ * @return string|bool Image src, or false if the post does not have a thumbnail.
28+ */
29+function get_the_post_thumbnail_src( $post_id = null, $size = 'post-thumbnail' ) {
30+       $post_thumbnail_id = get_post_thumbnail_id( $post_id );
31+
32+       if ( ! $post_thumbnail_id ) {
33+               return false;
34+
35+       do_action( 'begin_fetch_post_thumbnail_html', $post_id, $post_thumbnail_id, $size ); // for "Just In Time" filtering of all of wp_get_attachment_image()'s filters
36+       if ( in_the_loop() )
37+               update_post_thumbnail_cache();
38+       $size = apply_filters( 'post_thumbnail_size', $size );
39+       list( $src ) = wp_get_attachment_image_src( $post_thumbnail_id, $size, false );
40+       do_action( 'end_fetch_post_thumbnail_html', $post_id, $post_thumbnail_id, $size );
41+
42+       return $src;
43+}
44+
45 ?>