From e3fcbf5d551e3df01dad39af9531bbb9b0e3f261 Mon Sep 17 00:00:00 2001 From: Scott Taylor Date: Tue, 22 Sep 2015 04:15:24 +0000 Subject: [PATCH] Media: Add new functions, `get_the_post_thumbnail_url()` and `the_post_thumbnail_url()`. Adds unit tests. Props dipesh.kakadiya, swissspidy, atomicjack. Fixes #33070. Built from https://develop.svn.wordpress.org/trunk@34373 git-svn-id: http://core.svn.wordpress.org/trunk@34337 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/post-thumbnail-template.php | 27 +++++++++++++++++++++++++ wp-includes/version.php | 2 +- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/wp-includes/post-thumbnail-template.php b/wp-includes/post-thumbnail-template.php index f07302df3a..a024b1c00b 100644 --- a/wp-includes/post-thumbnail-template.php +++ b/wp-includes/post-thumbnail-template.php @@ -170,3 +170,30 @@ function get_the_post_thumbnail( $post = null, $size = 'post-thumbnail', $attr = */ return apply_filters( 'post_thumbnail_html', $html, $post->ID, $post_thumbnail_id, $size, $attr ); } + +/** + * Return the post thumbnail URL. + * + * @since 4.4.0 + * + * @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global `$post`. + * @param string|array $size Optional. Registered image size to retrieve the source for or a flat + * array of height and width dimensions. Default 'post-thumbnail'. + * @return string Post thumbnail URL or empty string. + */ +function get_the_post_thumbnail_url( $post = null, $size = 'post-thumbnail' ) { + $image = wp_get_attachment_image_url( get_post_thumbnail_id( $post ), $size ); + return isset( $image ) ? $image : ''; +} + +/** + * Display the post thumbnail URL. + * + * @since 4.4.0 + * + * @param string|array $size Optional. Registered image size to retrieve the source for or a flat + * array of height and width dimensions. Default 'post-thumbnail'. + */ +function the_post_thumbnail_url( $size = 'post-thumbnail' ) { + echo get_the_post_thumbnail_url( null, $size ); +} diff --git a/wp-includes/version.php b/wp-includes/version.php index bb0f87835f..8755504419 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.4-alpha-34372'; +$wp_version = '4.4-alpha-34373'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.