Skip to content

Build: Document the hooks generated by the wp-build page templates#78826

Merged
westonruter merged 1 commit into
trunkfrom
update/wp-build-page-template-hook-docs
Jun 2, 2026
Merged

Build: Document the hooks generated by the wp-build page templates#78826
westonruter merged 1 commit into
trunkfrom
update/wp-build-page-template-hook-docs

Conversation

@westonruter

Copy link
Copy Markdown
Member

What?

Follow up to #73120 and #73137.

The @wordpress/build page templates generate PHP files (output under wp-includes/build/pages/…) that invoke action hooks. This PR brings those hooks in line with the WordPress PHP documentation standards:

  • Add a DocBlock for the per-page init action ({page_slug}_init in page.php.template, {page_slug}-wp-admin_init in page-wp-admin.php.template), which previously had only a // line comment.
  • Replace the duplicated copies of core hook DocBlocks (admin_head, admin_head-{$hook_suffix}, admin_footer, admin_footer-{$hook_suffix}) in page.php.template with the standard /** This action is documented in … */ reference comments.

No behavior changes — documentation only.

Why?

Every action and filter should be documented, either with an inline DocBlock or, when the hook is documented elsewhere, with a This action/filter is documented in <file> reference comment. The page templates currently fall short in two ways:

  1. The init actions are undocumented. {page_slug}_init / {page_slug}-wp-admin_init carry only a // Fire init action… line comment, so every generated page ships an undocumented hook.
  2. Core hook DocBlocks are duplicated. The admin-header/admin-footer emulation region copies core's DocBlocks for admin_head, admin_footer, and their -{$hook_suffix} variants verbatim. These hooks are defined and documented in wp-admin/admin-header.php and wp-admin/admin-footer.php; core itself never duplicates a hook's DocBlock and instead uses the "documented in" reference. Duplicating risks the copies drifting from the canonical documentation and misrepresents where the hooks are defined.

(For context, a PHPStan rule being added on the WordPress core side flags exactly these two patterns, which is how they surfaced.)

How?

  • Added a DocBlock above the init do_action() in both page templates. No @since is included: a single shared template generates pages introduced in different versions, so no single version would be correct for the substituted hook name.
  • Replaced the four duplicated core DocBlocks in page.php.template with /** This action is documented in wp-admin/admin-header.php */ and /** This action is documented in wp-admin/admin-footer.php */ as appropriate.
  • Left the {page_slug}_boot_dependencies filter's DocBlock untouched — it is a genuinely new, page-specific filter (not a re-fire of a core hook), so its inline DocBlock is the canonical documentation and is correct as-is.

Testing Instructions

This is a documentation-only change to the build templates; there is no runtime behavior change.

  1. Run a production build: npm run build.
  2. Inspect a generated page, e.g. build/pages/font-library/page.php:
    • The init do_action( 'font-library_init' ) is now preceded by a /** … */ DocBlock.
    • The admin_head, admin_head-{$hook_suffix}, admin_footer, and admin_footer-{$hook_suffix} calls are now preceded by /** This action is documented in … */ reference comments instead of copied DocBlocks.
  3. Inspect a wp-admin page, e.g. build/pages/.../page-wp-admin.php, and confirm the …-wp-admin_init action now has a DocBlock.

Testing Instructions for Keyboard

N/A — no UI changes.

Screenshots or screencast

N/A — documentation-only change to generated PHP.

Use of AI Tools

This pull request was authored with the assistance of Claude Code (Claude Opus). All changes were reviewed by the contributor, who takes responsibility for them.

In the page templates, add a docblock for the per-page init action
({{PAGE_SLUG}}_init / {{PAGE_SLUG}}-wp-admin_init) so generated pages document
the hook. No @SInCE is given because the shared template serves pages
introduced in different versions.

Replace the duplicated copies of core hook docblocks (admin_head,
admin_head-{$hook_suffix}, admin_footer, admin_footer-{$hook_suffix}) with the
standard "This action is documented in ..." reference comments, matching how
WordPress core references hooks documented elsewhere.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@github-actions

github-actions Bot commented May 29, 2026

Copy link
Copy Markdown

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: westonruter <westonruter@git.wordpress.org>
Co-authored-by: t-hamano <wildworks@git.wordpress.org>

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

@westonruter westonruter added [Type] Bug An existing feature does not function as intended [Package] wp-build /packages/wp-build labels May 29, 2026
@github-actions

Copy link
Copy Markdown

Flaky tests detected in cfbeca0.
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/26664863194
📝 Reported issues:

@westonruter westonruter merged commit 3f54b42 into trunk Jun 2, 2026
51 checks passed
@westonruter westonruter deleted the update/wp-build-page-template-hook-docs branch June 2, 2026 11:27
@github-actions github-actions Bot added this to the Gutenberg 23.4 milestone Jun 2, 2026
@t-hamano

t-hamano commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

Let's backport this PR to 7.0.1 as well, so that #75985 can be correctly backported to 7.0.1.

@t-hamano t-hamano added the Backport to WP Minor Release Pull request that needs to be backported to a WordPress minor release label Jun 2, 2026
@desrosj

desrosj commented Jun 24, 2026

Copy link
Copy Markdown
Member

It looks like this never made its way into the wp/7.0 branch. The workflow exited early and I don't see the commit in the branch's commits.

@t-hamano

Copy link
Copy Markdown
Contributor

It looks like this never made its way into the wp/7.0 branch. The workflow exited early and I don't see the commit in the branch's commits.

I believe that unlike Beta releases, automatic cherry-picking based on labels is not performed for minor releases. I think manual cherry-picking is necessary for minor releases.

https://github.com/WordPress/gutenberg/blob/trunk/docs/contributors/code/release/plugin-release.md#cherry-pick-bug-fixes

Example: #74806

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Backport to WP Minor Release Pull request that needs to be backported to a WordPress minor release [Package] wp-build /packages/wp-build [Type] Bug An existing feature does not function as intended

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants