Changeset 42030 – WordPress Trac (original) (raw)
Timestamp:
10/27/2017 05:04:04 AM (8 years ago)
westonruter
Message:
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.
Location:
Files:
- src/wp-includes/widgets/class-wp-widget-media-image.php (1 diff)
- tests/phpunit/tests/widgets/media-image-widget.php (3 diffs)
Legend:
Unmodified
Added
Removed
| r41696 | r42030 | |
|---|---|---|
| 178 | 178 | } |
| 179 | 179 | if ( $attachment ) { |
| 180 | caption=caption = caption=attachment->post_excerpt; | |
| 181 | if ( $instance['caption'] ) { | |
| 180 | $caption = ''; | |
| 181 | if ( ! isset( $instance['caption'] ) ) { | |
| 182 | caption=caption = caption=attachment->post_excerpt; | |
| 183 | } elseif ( trim( $instance['caption'] ) ) { | |
| 182 | 184 | caption=caption = caption=instance['caption']; |
| 183 | 185 | } |
| r41549 | r42030 | |
|---|---|---|
| 426 | 426 | this−>assertContains(′target="blank"′,this->assertContains( 'target="_blank"', this−>assertContains(′target="blank"′,output ); |
| 427 | 427 | |
| 428 | // |
|
| 428 | // Populate caption in attachment. | |
| 429 | 429 | wp_update_post( array( |
| 430 | 430 | 'ID' => $attachment_id, |
| … | … | |
| 432 | 432 | ) ); |
| 433 | 433 | |
| 434 | ob_start(); | |
| 435 | $widget->render_media( array( | |
| 436 | 'attachment_id' => $attachment_id, | |
| 437 | ) ); | |
| 438 | $output = ob_get_clean(); | |
| 439 | ||
| 434 | // If no caption is supplied, then the default is '', and so the caption will not be displayed. | |
| 435 | ob_start(); | |
| 436 | $widget->render_media( array( | |
| 437 | 'attachment_id' => $attachment_id, | |
| 438 | ) ); | |
| 439 | $output = ob_get_clean(); | |
| 440 | this−>assertNotContains(′wp−caption′,this->assertNotContains( 'wp-caption', this−>assertNotContains(′wp−caption′,output ); | |
| 441 | this−>assertNotContains(′<pclass="wp−caption−text">′,this->assertNotContains( '<p class="wp-caption-text">', this−>assertNotContains(′<pclass="wp−caption−text">′,output ); | |
| 442 | ||
| 443 | // If the caption is explicitly null, then the caption of the underlying attachment will be displayed. | |
| 444 | ob_start(); | |
| 445 | $widget->render_media( array( | |
| 446 | 'attachment_id' => $attachment_id, | |
| 447 | 'caption' => null, | |
| 448 | ) ); | |
| 449 | $output = ob_get_clean(); | |
| 440 | 450 | this−>assertContains(′class="wp−captionalignnone"′,this->assertContains( 'class="wp-caption alignnone"', this−>assertContains(′class="wp−captionalignnone"′,output ); |
| 441 | 451 | this−>assertContains(′<pclass="wp−caption−text">Defaultcaption</p>′,this->assertContains( '<p class="wp-caption-text">Default caption</p>', this−>assertContains(′<pclass="wp−caption−text">Defaultcaption</p>′,output ); |
| 442 | 452 | |
| 453 | // If caption is provided, then it will be displayed. | |
| 443 | 454 | ob_start(); |
| 444 | 455 | $widget->render_media( array( |
| … | … | |
| 447 | 458 | ) ); |
| 448 | 459 | $output = ob_get_clean(); |
| 449 | ||
| 450 | 460 | this−>assertContains(′class="wp−captionalignnone"′,this->assertContains( 'class="wp-caption alignnone"', this−>assertContains(′class="wp−captionalignnone"′,output ); |
| 451 | 461 | this−>assertContains(′<pclass="wp−caption−text">Customcaption</p>′,this->assertContains( '<p class="wp-caption-text">Custom caption</p>', this−>assertContains(′<pclass="wp−caption−text">Customcaption</p>′,output ); |
Note: See TracChangeset for help on using the changeset viewer.