Skip to content

Commit

Permalink
Post excerpt > Ensure the postId from the block context is used to ge…
Browse files Browse the repository at this point in the history
…t_the_excerpt (#49495)

* ensure the postId from the block context to get_the_excerpt instead of relying on the global post object.

* Restructure the code for get_the_excerpt

* phpcs: Align equal sign
  • Loading branch information
nefeline authored Apr 8, 2023
1 parent bdedc58 commit 99d837a
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions packages/block-library/src/post-excerpt/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ function render_block_core_post_excerpt( $attributes, $content, $block ) {
* wp_trim_words is used instead.
*/
$excerpt_length = $attributes['excerptLength'];
$excerpt = get_the_excerpt( $block->context['postId'] );
if ( isset( $excerpt_length ) ) {
$excerpt = wp_trim_words( get_the_excerpt(), $excerpt_length );
} else {
$excerpt = get_the_excerpt();
$excerpt = wp_trim_words( $excerpt, $excerpt_length );
}

$more_text = ! empty( $attributes['moreText'] ) ? '<a class="wp-block-post-excerpt__more-link" href="' . esc_url( get_the_permalink( $block->context['postId'] ) ) . '">' . wp_kses_post( $attributes['moreText'] ) . '</a>' : '';
$filter_excerpt_more = function( $more ) use ( $more_text ) {
return empty( $more_text ) ? $more : '';
Expand Down

1 comment on commit 99d837a

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flaky tests detected in 99d837a.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/4643931996
📝 Reported issues:

Please sign in to comment.