[wp-trac] [WordPress Trac] #46743: A way to detect whether the current theme supports wp_body_open()

WordPress Trac noreply at wordpress.org
Tue Apr 16 01:20:20 UTC 2019


#46743: A way to detect whether the current theme supports wp_body_open()
-----------------------------------+---------------------
 Reporter:  SergeyBiryukov         |       Owner:  (none)
     Type:  defect (bug)           |      Status:  new
 Priority:  normal                 |   Milestone:  5.2
Component:  Themes                 |     Version:  trunk
 Severity:  normal                 |  Resolution:
 Keywords:  has-patch 2nd-opinion  |     Focuses:
-----------------------------------+---------------------

Comment (by SergeyBiryukov):

 Replying to [comment:3 ramiy]:

 Thanks for the feedback! I'll try to address the items one by one.

 > We don't register theme features for `wp_head()` and `wp_footer()`.

 `wp_head()` and `wp_footer()` are long-established functions, it's safe to
 assume every theme has them, as a lot of things break otherwise (admin
 bar, stylesheets, etc.).

 > When hooking to the `wp_body_open` action, if the action does not exist
 (pre 5.3 versions), it won't do nothing and won't break nothing as the
 action does not exist.

 That means plugin authors cannot rely on the new action, as there's no
 guarantee that the current theme supports it. Unless I'm missing
 something, that makes the new action largely useless.

 Let's consider the use case from #12563: adding asynchronous JS code right
 after the opening `<body>` tag. How would the plugin author know if the
 code was successfully added? If the current theme does not support
 `wp_body_open()`, they would need to use some fallback code.

 > We should educate theme developers how to use wp_body_open() function
 (see #46679)

 I agree, but that does not solve the immediate issue for plugin authors.

 > If plugin developers want to check if the `wp_body_open()` function
 exist, they can check it using:
 >
 > `if ( ! function_exists( 'wp_body_open' ) ) { ... }`

 The point was not to check if the function exists (it always does in
 5.2+), but whether the current theme supports it.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/46743#comment:5>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list