Advertisement
Guest User

Untitled

a guest
Dec 4th, 2018
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function get_the_post_thumbnail( $post = null, $size = 'post-thumbnail', $attr = '' ) {
  2.     $post = get_post( $post );
  3.     if ( ! $post ) {
  4.         return '';
  5.     }
  6.     $post_thumbnail_id = get_post_thumbnail_id( $post );
  7.  
  8.     /**
  9.      * Filters the post thumbnail size.
  10.      *
  11.      * @since 2.9.0
  12.      * @since 4.9.0 Added the `$post_id` parameter.
  13.      *
  14.      * @param string|array $size    The post thumbnail size. Image size or array of width and height
  15.      *                              values (in that order). Default 'post-thumbnail'.
  16.      * @param int          $post_id The post ID.
  17.      */
  18.     $size = apply_filters( 'post_thumbnail_size', $size, $post->ID );
  19.  
  20.     if ( $post_thumbnail_id ) {
  21.  
  22.         /**
  23.          * Fires before fetching the post thumbnail HTML.
  24.          *
  25.          * Provides "just in time" filtering of all filters in wp_get_attachment_image().
  26.          *
  27.          * @since 2.9.0
  28.          *
  29.          * @param int          $post_id           The post ID.
  30.          * @param string       $post_thumbnail_id The post thumbnail ID.
  31.          * @param string|array $size              The post thumbnail size. Image size or array of width
  32.          *                                        and height values (in that order). Default 'post-thumbnail'.
  33.          */
  34.         do_action( 'begin_fetch_post_thumbnail_html', $post->ID, $post_thumbnail_id, $size );
  35.         if ( in_the_loop() )
  36.             update_post_thumbnail_cache();
  37.         $html = wp_get_attachment_image( $post_thumbnail_id, $size, false, $attr );
  38.  
  39.         /**
  40.          * Fires after fetching the post thumbnail HTML.
  41.          *
  42.          * @since 2.9.0
  43.          *
  44.          * @param int          $post_id           The post ID.
  45.          * @param string       $post_thumbnail_id The post thumbnail ID.
  46.          * @param string|array $size              The post thumbnail size. Image size or array of width
  47.          *                                        and height values (in that order). Default 'post-thumbnail'.
  48.          */
  49.         do_action( 'end_fetch_post_thumbnail_html', $post->ID, $post_thumbnail_id, $size );
  50.  
  51.     } else {
  52.         $html = '';
  53.     }
  54.     /**
  55.      * Filters the post thumbnail HTML.
  56.      *
  57.      * @since 2.9.0
  58.      *
  59.      * @param string       $html              The post thumbnail HTML.
  60.      * @param int          $post_id           The post ID.
  61.      * @param string       $post_thumbnail_id The post thumbnail ID.
  62.      * @param string|array $size              The post thumbnail size. Image size or array of width and height
  63.      *                                        values (in that order). Default 'post-thumbnail'.
  64.      * @param string       $attr              Query string of attributes.
  65.      */
  66.     return apply_filters( 'post_thumbnail_html', $html, $post->ID, $post_thumbnail_id, $size, $attr );
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement