Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure that post thumbnail is cached in post template block. #40572

Merged
merged 4 commits into from
May 6, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Improve logic.
  • Loading branch information
spacedmonkey committed May 6, 2022
commit 0a20bcb335f1ffefda4716b556b3176c25607750
19 changes: 6 additions & 13 deletions packages/block-library/src/post-template/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,19 @@
* @return bool
*/
function block_core_post_template_uses_feature_image( $inner_blocks ) {
$inner_blocks_array = iterator_to_array( $inner_blocks );
$has_thumbnail = false;
foreach ( $inner_blocks_array as $block ) {
foreach ( $inner_blocks as $block ) {
if ( 'core/post-featured-image' === $block->name ) {
$has_thumbnail = true;
break;
return true;
}
if ( 'core/cover' === $block->name && $block->attributes && isset( $block->attributes['useFeaturedImage'] ) && $block->attributes['useFeaturedImage'] ) {
$has_thumbnail = true;
break;
return true;
}
if ( $block->inner_blocks ) {
if ( block_core_post_template_uses_feature_image( $block->inner_blocks ) ) {
$has_thumbnail = true;
break;
}
if ( $block->inner_blocks && block_core_post_template_uses_feature_image( $block->inner_blocks ) ) {
return true;
}
}

return $has_thumbnail;
return false;
}

/**
Expand Down