Skip to content

Conversation

@t-hamano
Copy link
Contributor

@t-hamano t-hamano commented Apr 19, 2025

What?

Follow-up #67136
Closes #69948

Why?

Fixes PHP warning error when the Author and Author Name block have no context.

See #69948

How?

Checks for the existence of a context. If it doesn't, it continues with further processing. That is, if the block isn't relevant for a particular post type, it will be rendered.

However, the User REST API doesn't allow listing users if they have no posts written yet. As a follow-up, we may also need to add a check for the number of posts a user has written, in accordance with the REST API specification, in both blocks.

Testing Instructions

  • Add a new user with the "Editor" role (This user has no posts).
  • Add an Author Archives template:
<main class="wp-block-group">
<!-- wp:query-title {"type":"archive"} /-->
<!-- wp:post-author /-->
<!-- wp:post-author-name /-->
</main>
<!-- /wp:group -->
  • Access http://localhost:8888/?author=2 (Change the author param value to the actual user id for the newly added user)
  • Confirm that two blocks are rendered correctly and no PHP warning logs are displayed.

@t-hamano t-hamano added [Type] Bug An existing feature does not function as intended [Block] Post Author Affects the Post Author Block Backport to WP Minor Release Pull request that needs to be backported to a WordPress minor release [Block] Author Name Affects the Author Name Block labels Apr 19, 2025
@t-hamano t-hamano moved this to 🔎 Needs Review in WordPress 6.8.x Editor Tasks Apr 19, 2025
@t-hamano t-hamano marked this pull request as ready for review April 19, 2025 09:41
@github-actions
Copy link

github-actions bot commented Apr 19, 2025

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: t-hamano <[email protected]>
Co-authored-by: Mamaduka <[email protected]>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

Copy link
Member

@Mamaduka Mamaduka left a comment

Choose a reason for hiding this comment

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

However, the User REST API doesn't allow listing users if they have no posts written yet. As a follow-up, we may also need to add a check for the number of posts a user has written, in accordance with the REST API specification, in both blocks.

That condition has its problems and might change in the future. See: #69921

@t-hamano
Copy link
Contributor Author

@Mamaduka Thanks for the review!

I'd like to add @justlevine, who first reported this issue on Slack, to the props list: https://wordpress.slack.com/archives/C02QB2JS7/p1744930825415699

@t-hamano t-hamano merged commit c94f1d7 into trunk Apr 19, 2025
71 checks passed
@Mamaduka
Copy link
Member

Of course! This would be their WP contribution email.

Co-authored-by: justlevine <[email protected]>

@t-hamano t-hamano deleted the fix/post-author-context-check branch April 19, 2025 10:11
@github-actions github-actions bot added this to the Gutenberg 20.8 milestone Apr 19, 2025
@t-hamano t-hamano moved this from 🔎 Needs Review to ✅ Done in WordPress 6.8.x Editor Tasks Apr 19, 2025
t-hamano added a commit that referenced this pull request Apr 28, 2025
…text (#69949)

Co-authored-by: t-hamano <[email protected]>
Co-authored-by: Mamaduka <[email protected]>
Co-authored-by: justlevine <[email protected]>
@t-hamano
Copy link
Contributor Author

A backport PR for the wp/6.8 branch: #70001

t-hamano added a commit that referenced this pull request Apr 28, 2025
…text (#69949)

Co-authored-by: t-hamano <[email protected]>
Co-authored-by: Mamaduka <[email protected]>
Co-authored-by: justlevine <[email protected]>
t-hamano added a commit that referenced this pull request Apr 28, 2025
…text (#69949) (#70001)

Co-authored-by: Mamaduka <[email protected]>
Co-authored-by: justlevine <[email protected]>
Co-authored-by: t-hamano <[email protected]>
Co-authored-by: fabiankaegy <[email protected]>
@t-hamano
Copy link
Contributor Author

Removing the Backport to WP Minor Release label as #70001 has just been merged into the wp/6.8 branch.

@t-hamano t-hamano removed the Backport to WP Minor Release Pull request that needs to be backported to a WordPress minor release label Apr 28, 2025
chriszarate pushed a commit to chriszarate/gutenberg that referenced this pull request Jul 1, 2025
…text (WordPress#69949)

Co-authored-by: t-hamano <[email protected]>
Co-authored-by: Mamaduka <[email protected]>
Co-authored-by: justlevine <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Block] Author Name Affects the Author Name Block [Block] Post Author Affects the Post Author Block [Type] Bug An existing feature does not function as intended

Projects

No open projects

Development

Successfully merging this pull request may close these issues.

Post Author, Post Author Name: Context existence check required

3 participants