WordPress.org

Make WordPress Core

Ticket #33723: 33723.2.diff

File 33723.2.diff, 2.5 KB (added by swissspidy, 6 years ago)

Adds unit tests

  • src/wp-includes/post-thumbnail-template.php

    diff --git src/wp-includes/post-thumbnail-template.php src/wp-includes/post-thumbnail-template.php
    index 7b8d1a2..045bbb3 100644
     
    1313 * Check if post has an image attached.
    1414 *
    1515 * @since 2.9.0
     16 * @since 4.4.0 Added the ability to pass a post object to `$post`.
    1617 *
    17  * @param int $post_id Optional. Post ID.
     18 * @param int|WP_Post $post Optional. Post ID or post object.
    1819 * @return bool Whether post has an image attached.
    1920 */
    20 function has_post_thumbnail( $post_id = null ) {
    21         return (bool) get_post_thumbnail_id( $post_id );
     21function has_post_thumbnail( $post = null ) {
     22        return (bool) get_post_thumbnail_id( $post );
    2223}
    2324
    2425/**
    2526 * Retrieve Post Thumbnail ID.
    2627 *
    2728 * @since 2.9.0
     29 * @since 4.4.0 Added the ability to pass a post object to `$post`.
    2830 *
    29  * @param int|null $post_id Optional. Post ID.
     31 * @param int|null|WP_Post $post Optional. Post ID or object
    3032 * @return mixed
    3133 */
    32 function get_post_thumbnail_id( $post_id = null ) {
    33         $post_id = ( null === $post_id ) ? get_the_ID() : $post_id;
     34function get_post_thumbnail_id( $post = null ) {
     35        $post = get_post( $post );
     36        $post_id = is_a( $post, 'WP_Post' ) ? $post->ID : null;
    3437        return get_post_meta( $post_id, '_thumbnail_id', true );
    3538}
    3639
    function update_post_thumbnail_cache( $wp_query = null ) { 
    9699 * size is used by default, though a different size can be specified instead as needed.
    97100 *
    98101 * @since 2.9.0
     102 * @since 4.4.0 Added the ability to pass a post object to `$post`.
    99103 *
    100  * @param int $post_id       Post ID. Default is the ID of the `$post` global.
     104 * @param int $post          Post ID or post object. Default to the current post.
    101105 * @param string|array $size Optional. Registered image size to use, or flat array of height
    102106 *                           and width values. Default 'post-thumbnail'.
    103107 * @param string|array $attr Optional. Query string or array of attributes. Default empty.
    104108 * @return string
    105109 */
    106 function get_the_post_thumbnail( $post_id = null, $size = 'post-thumbnail', $attr = '' ) {
    107         $post_id = ( null === $post_id ) ? get_the_ID() : $post_id;
    108         $post_thumbnail_id = get_post_thumbnail_id( $post_id );
     110function get_the_post_thumbnail( $post = null, $size = 'post-thumbnail', $attr = '' ) {
     111        $post = get_post( $post );
     112        $post_id = is_a( $post, 'WP_Post' ) ? $post->ID : null;
     113        $post_thumbnail_id = get_post_thumbnail_id( $post );
    109114
    110115        /**
    111116         * Filter the post thumbnail size.