Skip to content

Commit 4e43f97

Browse files
Improve performance
1 parent 47846a0 commit 4e43f97

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

plugins/auto-sizes/includes/improve-calculate-sizes.php

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ function auto_sizes_filter_image_tag( $content, array $parsed_block, WP_Block $b
105105
* See https://github.com/WordPress/wordpress-develop/blob/3f9c6fce666ed2ea0d56c21f6235c37db3d91392/src/wp-includes/blocks/post-featured-image.php#L65
106106
*/
107107
if ( 'core/post-featured-image' === $block->name && isset( $block->context['postId'] ) ) {
108-
$id = auto_sizes_get_featured_image_id_from_block( $block );
108+
$id = auto_sizes_get_featured_image_id_from_block( $block->context['postId'] );
109109
}
110110

111111
/*
@@ -133,7 +133,7 @@ function auto_sizes_filter_image_tag( $content, array $parsed_block, WP_Block $b
133133
* See https://github.com/WordPress/wordpress-develop/blob/3f9c6fce666ed2ea0d56c21f6235c37db3d91392/src/wp-includes/blocks/post-featured-image.php#L65
134134
*/
135135
if ( 'core/post-featured-image' === $block->name && isset( $block->context['postId'] ) ) {
136-
$id = auto_sizes_get_featured_image_id_from_block( $block );
136+
$id = auto_sizes_get_featured_image_id_from_block( $block->context['postId'] );
137137
}
138138

139139
$sizes = wp_calculate_image_sizes(
@@ -386,17 +386,13 @@ function auto_sizes_filter_render_block_context( array $context, array $block, ?
386386
*
387387
* @since n.e.x.t
388388
*
389-
* @param WP_Block $block The block instance.
389+
* @param int $post_id The post id.
390390
* @return int The featured image ID or 0 if not found.
391391
*/
392-
function auto_sizes_get_featured_image_id_from_block( WP_Block $block ): int {
393-
$post_id = $block->context['postId'];
394-
395-
$post = get_post( $post_id );
396-
397-
if ( ! ( $post instanceof WP_Post ) ) {
392+
function auto_sizes_get_featured_image_id_from_block( int $post_id ): int {
393+
if ( 0 === $post_id ) {
398394
return 0;
399395
}
400396

401-
return (int) get_post_thumbnail_id( $post );
397+
return (int) get_post_thumbnail_id( $post_id );
402398
}

0 commit comments

Comments
 (0)