Make WordPress Core

Opened 5 years ago

Closed 5 years ago

#47032 closed enhancement (wontfix)

Rename wp_body_open hook and function

Reported by: rilwis's profile rilwis Owned by:
Milestone: Priority: normal
Severity: normal Version: 5.2
Component: Themes Keywords:
Focuses: template Cc:

Description

The wp_body_open hook is added to v5.2 in this ticket #12563. However, I think the naming is bad. The hook doesn't fit the context where the body tag opens. It happens when the body tag already opened. We can tell in another way: we don't know that hook fires before or after the tag is opened by just looking into its name.

I suggest using the naming convention in the Theme Hook Alliance:

  • Hooks should be of the form prefix_ + [section of the theme] + _[placement within block].
  • Hooks should be named based upon the generally-accepted semantic name for the section of a theme they cover, e.g., prefix_content_* should refer to the section/block of a theme containing the content (or "The Loop"), while prefix_sidebar_* would refer to the sidebars generally called by get_sidebar().
  • Hooks should be suffixed based upon their placement within a block.
    • Hooks immediately preceding a block should use _before.
    • Hooks immediately following a block should use _after.
    • Hooks placed at the very beginning of a block should use _top.
    • Hooks placed at the very end of a block should use _bottom.
  • If the theme section covered by a hook can contain multiple semantic elements, it should be pluralized. (Primarily applies to prefix_sidebars_before/after in the early goings.)

In this case, the prefix is wp_, the block is body, so the hook should be wp_body_top.

Benefit: this provides a consistent naming conversion for future hooks that implemented in the themes by WordPress or by theme providers.

Change History (4)

#1 @pento
5 years ago

  • Keywords dev-feedback 2nd-opinion needs-dev-note removed
  • Milestone Awaiting Review deleted
  • Resolution set to wontfix
  • Status changed from new to closed

Thank you for the suggestion, @rilwis!

The THA link is interesting, but doesn't seem to have gained much traction since its proposal.

There are quite a few different naming forms that are scattered throughout the WordPress codebase. The *_top form of hook name appears, as does post_*_tag, *_tag, *_tag_pre, pre_*... you get the idea. 🙂

Outside of a substantial re-architecture of our hook naming scheme, I don't think it's necessary to try and lock into a particular format for new hooks.

#2 @rilwis
5 years ago

Thanks for your comment, @pento!

The WordPress hooks with post_ or pre_ unlikely match this context. They're used for internal actions, like before or after doing something. While in the front end, there's exclusively and clearly a context (HTML block). The hook tells more about the location than action. That's why the words *_before, *_after, *_top, *_bottom make sense.

Also, this is the first hook in the front end for themes (except required wp_head and wp_footer), it will create a kind of standard for future hooks. I'm thinking about the hooks for content areas in Gutenberg Phase 2.

For those reasons, I think it's a good time to start a naming convention now.

#3 @apedog
5 years ago

  • Resolution wontfix deleted
  • Status changed from closed to reopened

If this is not too late into the development process, I'd also add my support for wp_body_top being more readable and easier to understand than wp_body_open

#4 @SergeyBiryukov
5 years ago

  • Resolution set to wontfix
  • Status changed from reopened to closed

Since we're already in RC stage, it's probably too late to change the name.

Note: See TracTickets for help on using tickets.