Skip to content

Post Author, Post Author Name: Context existence check required #69948

@t-hamano

Description

@t-hamano

Description

In #67136, a logic has been added to check if a custom post type supports author, to prevent author information leakage. However, $block->context may be an empty array in some scenarios, which causes a PHP undefined array key error. One example is when the author has not published any article yet.

Step-by-step reproduction 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 PHP warning logs are displayed.

Screenshots, screen recording, code snippet

Author Archives Template

Image

Frontend

Image

Environment info

No response

Please confirm that you have searched existing issues in the repo.

  • Yes

Please confirm that you have tested with all plugins deactivated except Gutenberg.

  • Yes

Please confirm which theme type you used for testing.

  • Block
  • Classic
  • Hybrid (e.g. classic with theme.json)
  • Not sure

Metadata

Metadata

Assignees

Labels

[Block] Author NameAffects the Author Name Block[Block] Post AuthorAffects the Post Author Block[Type] BugAn existing feature does not function as intended

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions