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

Post excerpt > Ensure the postId from the block context is used to get_the_excerpt #49495

Merged
merged 3 commits into from
Apr 8, 2023

Conversation

nefeline
Copy link
Contributor

@nefeline nefeline commented Mar 30, 2023

What?

Ensures the postId from the block context is used for fetching the post excerpt.

Why?

Similar to this change made to the Post Title block, here we can ensure that independent of where the Post Excerpt block is added, the rendered content will be aligned with the context of the block itself rather than the global post.

For context, this limitation surfaced while working on the new Single Product Block on WooCommerce blocks, where the displayed excerpt would match the current post rather than the block context while at the same time, the Post Title block would respect the block context accordingly.

Testing Instructions

  1. Add the Post Excerpt block to any post/page.
  2. Confirm that the excerpt is properly rendered both on the editor and on the front-end sides.

@github-actions github-actions bot added the First-time Contributor Pull request opened by a first-time contributor to Gutenberg repository label Mar 30, 2023
@github-actions
Copy link

👋 Thanks for your first Pull Request and for helping build the future of Gutenberg and WordPress, @nefeline! In case you missed it, we'd love to have you join us in our Slack community, where we hold regularly weekly meetings open to anyone to coordinate with each other.

If you want to learn more about WordPress development in general, check out the Core Handbook full of helpful information.

@gziolo gziolo added [Type] Bug An existing feature does not function as intended [Block] Post Excerpt Affects the Post Excerpt Block labels Mar 30, 2023
@gziolo
Copy link
Member

gziolo commented Mar 30, 2023

Thank you for opening the bug fix. It makes sense and aligns with how it works in edit.

Similar to this change made to the Post Title block

Thank you for linking to that prior work from @spacedmonkey. Would it also he beneficial for performance to use the post object here?

@carolinan
Copy link
Contributor

carolinan commented Mar 31, 2023

Would it also he beneficial for performance to use the post object here?

There is a related discussion here but not enough testing has been done:
#47997

Copy link
Member

@gziolo gziolo left a comment

Choose a reason for hiding this comment

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

Approving the changes.

The follow-up could cover potential perf improvements. We could also refactor the code so it's easier to follow:

$excerpt = get_the_excerpt( $block->context['postId'] );
if ( isset( $excerpt_length ) ) {
    $excerpt = wp_trim_words( $excerpt, $excerpt_length );
}

Copy link
Member

@aristath aristath left a comment

Choose a reason for hiding this comment

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

LGTM 👍

I agree that it would be better if we tweak the code a bit like @gziolo suggested above, but no strong feelings either way.

@nefeline
Copy link
Contributor Author

nefeline commented Mar 31, 2023

Thanks all 🎉 !

I tweaked the code as @gziolo suggested.

@gziolo gziolo merged commit 99d837a into WordPress:trunk Apr 8, 2023
@github-actions
Copy link

github-actions bot commented Apr 8, 2023

Congratulations on your first merged pull request, @nefeline! We'd like to credit you for your contribution in the post announcing the next WordPress release, but we can't find a WordPress.org profile associated with your GitHub account. When you have a moment, visit the following URL and click "link your GitHub account" under "GitHub Username" to link your accounts:

https://profiles.wordpress.org/me/profile/edit/

And if you don't have a WordPress.org account, you can create one on this page:

https://login.wordpress.org/register

Kudos!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Post Excerpt Affects the Post Excerpt Block First-time Contributor Pull request opened by a first-time contributor to Gutenberg repository [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants