Changeset 37915
- Timestamp:
- 06/29/2016 05:28:00 PM (8 years ago)
- Location:
- trunk
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/default-filters.php
r37908 r37915 143 143 add_filter( 'the_excerpt', 'shortcode_unautop'); 144 144 add_filter( 'get_the_excerpt', 'wp_trim_excerpt' ); 145 146 add_filter( 'the_post_thumbnail_caption', 'wptexturize' ); 147 add_filter( 'the_post_thumbnail_caption', 'convert_smilies' ); 148 add_filter( 'the_post_thumbnail_caption', 'convert_chars' ); 145 149 146 150 add_filter( 'comment_text', 'wptexturize' ); -
trunk/src/wp-includes/post-thumbnail-template.php
r37502 r37915 211 211 } 212 212 } 213 214 /** 215 * Returns the post thumbnail caption. 216 * 217 * @since 4.6.0 218 * 219 * @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global `$post`. 220 * @return string Post thumbnail caption. 221 */ 222 function get_the_post_thumbnail_caption( $post = null ) { 223 $post_thumbnail_id = get_post_thumbnail_id( $post ); 224 if ( ! $post_thumbnail_id ) { 225 return ''; 226 } 227 228 $caption = wp_get_attachment_caption( $post_thumbnail_id ); 229 230 if ( ! $caption ) { 231 $caption = ''; 232 } 233 234 return $caption; 235 } 236 237 /** 238 * Displays the post thumbnail caption. 239 * 240 * @since 4.6.0 241 * 242 * @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global `$post`. 243 */ 244 function the_post_thumbnail_caption( $post = null ) { 245 /** 246 * Filters the displayed post thumbnail caption. 247 * 248 * @since 4.6.0 249 * 250 * @param string $caption Caption for the given attachment. 251 */ 252 echo apply_filters( 'the_post_thumbnail_caption', get_the_post_thumbnail_caption( $post ) ); 253 } -
trunk/src/wp-includes/post.php
r37890 r37915 4938 4938 4939 4939 /** 4940 * Retrieves the caption for an attachment. 4941 * 4942 * @since 4.6.0 4943 * 4944 * @param int $post_id Optional. Attachment ID. Default 0. 4945 * @return string|false False on failure. Attachment caption on success. 4946 */ 4947 function wp_get_attachment_caption( $post_id = 0 ) { 4948 $post_id = (int) $post_id; 4949 if ( ! $post = get_post( $post_id ) ) { 4950 return false; 4951 } 4952 4953 if ( 'attachment' !== $post->post_type ) { 4954 return false; 4955 } 4956 4957 $caption = $post->post_excerpt; 4958 4959 /** 4960 * Filters the attachment caption. 4961 * 4962 * @since 4.6.0 4963 * 4964 * @param string $caption Caption for the given attachment. 4965 * @param int $post_id Attachment ID. 4966 */ 4967 return apply_filters( 'wp_get_attachment_caption', $caption, $post->ID ); 4968 } 4969 4970 /** 4940 4971 * Retrieve thumbnail for an attachment. 4941 4972 * -
trunk/tests/phpunit/tests/media.php
r37702 r37915 903 903 904 904 /** 905 * @ticket 12235 906 */ 907 function test_wp_get_attachment_caption() { 908 $this->assertFalse( wp_get_attachment_caption( 0 ) ); 909 910 $caption = 'This is a caption.'; 911 912 $post_id = self::factory()->post->create(); 913 $attachment_id = self::factory()->attachment->create_object( $this->img_name, $post_id, array( 914 'post_mime_type' => 'image/jpeg', 915 'post_type' => 'attachment', 916 'post_excerpt' => $caption, 917 ) ); 918 919 $this->assertFalse( wp_get_attachment_caption( $post_id ) ); 920 921 $this->assertEquals( $caption, wp_get_attachment_caption( $attachment_id ) ); 922 } 923 924 /** 925 * @ticket 12235 926 */ 927 function test_wp_get_attachment_caption_empty() { 928 $post_id = self::factory()->post->create(); 929 $attachment_id = self::factory()->attachment->create_object( $this->img_name, $post_id, array( 930 'post_mime_type' => 'image/jpeg', 931 'post_type' => 'attachment', 932 'post_excerpt' => '', 933 ) ); 934 935 $this->assertEquals( '', wp_get_attachment_caption( $attachment_id ) ); 936 } 937 938 /** 905 939 * Helper function to get image size array from size "name" 906 940 */ -
trunk/tests/phpunit/tests/post/thumbnails.php
r35244 r37915 75 75 } 76 76 77 /** 78 * @ticket 12235 79 */ 80 function test_get_the_post_thumbnail_caption() { 81 $this->assertEquals( '', get_the_post_thumbnail_caption() ); 82 83 $caption = 'This is a caption.'; 84 85 $post_id = self::factory()->post->create(); 86 $attachment_id = self::factory()->attachment->create_object( 'image.jpg', $post_id, array( 87 'post_mime_type' => 'image/jpeg', 88 'post_type' => 'attachment', 89 'post_excerpt' => $caption, 90 ) ); 91 92 set_post_thumbnail( $post_id, $attachment_id ); 93 94 $this->assertEquals( $caption, get_the_post_thumbnail_caption( $post_id ) ); 95 } 96 97 /** 98 * @ticket 12235 99 */ 100 function test_get_the_post_thumbnail_caption_empty() { 101 $post_id = self::factory()->post->create(); 102 $attachment_id = self::factory()->attachment->create_object( 'image.jpg', $post_id, array( 103 'post_mime_type' => 'image/jpeg', 104 'post_type' => 'attachment', 105 'post_excerpt' => '', 106 ) ); 107 108 set_post_thumbnail( $post_id, $attachment_id ); 109 110 $this->assertEquals( '', get_the_post_thumbnail_caption( $post_id ) ); 111 } 112 113 /** 114 * @ticket 12235 115 */ 116 function test_the_post_thumbnail_caption() { 117 $caption = 'This is a caption.'; 118 119 $post_id = self::factory()->post->create(); 120 $attachment_id = self::factory()->attachment->create_object( 'image.jpg', $post_id, array( 121 'post_mime_type' => 'image/jpeg', 122 'post_type' => 'attachment', 123 'post_excerpt' => $caption, 124 ) ); 125 126 set_post_thumbnail( $post_id, $attachment_id ); 127 128 ob_start(); 129 the_post_thumbnail_caption( $post_id ); 130 131 $this->assertEquals( $caption, ob_get_clean() ); 132 } 133 77 134 function test_get_the_post_thumbnail() { 78 135 $this->assertEquals( '', get_the_post_thumbnail() );
Note: See TracChangeset
for help on using the changeset viewer.