Widgets: Prevent showing underlying attachment excerpt as caption when empty caption value is supplied in Image widget.

Allow underlying attachment to display if `caption` is `null`.

Props miyauchi, westonruter.
See #39993.
Fixes #42350.


git-svn-id: https://develop.svn.wordpress.org/trunk@42030 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Weston Ruter
2017-10-27 05:04:04 +00:00
parent 49ec33ae71
commit 6eacf2f06b
2 changed files with 16 additions and 4 deletions
@@ -177,8 +177,10 @@ class WP_Widget_Media_Image extends WP_Widget_Media {
$attachment = get_post( $instance['attachment_id'] );
}
if ( $attachment ) {
$caption = $attachment->post_excerpt;
if ( $instance['caption'] ) {
$caption = '';
if ( ! isset( $instance['caption'] ) ) {
$caption = $attachment->post_excerpt;
} elseif ( trim( $instance['caption'] ) ) {
$caption = $instance['caption'];
}