Toolbar: Move the logic for rendering the admin bar on wp_footer to wp_admin_bar_render().

Clarify in the function documentation that it is now called on `wp_body_open` action first, with `wp_footer` as a fallback.

Follow-up to [47221].

Reviewed by whyisjake, SergeyBiryukov.
Merges [47455] to the 5.4 branch.
Fixes #47053.
Built from https://develop.svn.wordpress.org/branches/5.4@47467


git-svn-id: http://core.svn.wordpress.org/branches/5.4@47254 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Sergey Biryukov 2020-03-17 19:28:08 +00:00
parent 891db8e7b0
commit f9751ce78a
4 changed files with 17 additions and 11 deletions

View File

@ -55,8 +55,11 @@ function _wp_admin_bar_init() {
/**
* Renders the admin bar to the page based on the $wp_admin_bar->menu member var.
*
* This is called very late on the footer actions so that it will render after
* anything else being added to the footer.
* This is called very early on the {@see 'wp_body_open'} action so that it will render
* before anything else being added to the page body.
*
* For backward compatibility with themes not using the 'wp_body_open' action,
* the function is also called late on {@see 'wp_footer'}.
*
* It includes the {@see 'admin_bar_menu'} action which should be used to hook in and
* add new menus to the admin bar. That way you can be sure that you are adding at most
@ -64,11 +67,19 @@ function _wp_admin_bar_init() {
* the `$post` global, among others.
*
* @since 3.1.0
* @since 5.4.0 Called on 'wp_body_open' action first, with 'wp_footer' as a fallback.
*
* @global WP_Admin_Bar $wp_admin_bar
*
* @staticvar bool $rendered
*/
function wp_admin_bar_render() {
global $wp_admin_bar;
static $rendered = false;
if ( $rendered ) {
return;
}
if ( ! is_admin_bar_showing() || ! is_object( $wp_admin_bar ) ) {
return;
@ -100,6 +111,8 @@ function wp_admin_bar_render() {
* @since 3.1.0
*/
do_action( 'wp_after_admin_bar_render' );
$rendered = true;
}
/**

View File

@ -538,6 +538,7 @@ add_action( 'admin_init', '_wp_admin_bar_init' );
add_action( 'before_signup_header', '_wp_admin_bar_init' );
add_action( 'activate_header', '_wp_admin_bar_init' );
add_action( 'wp_body_open', 'wp_admin_bar_render', 0 );
add_action( 'wp_footer', 'wp_admin_bar_render', 1000 ); // Back-compat for themes not using `wp_body_open`.
add_action( 'in_admin_header', 'wp_admin_bar_render', 0 );
// Former admin filters that can also be hooked on the front end.

View File

@ -2892,14 +2892,6 @@ function wp_head() {
* @since 1.5.1
*/
function wp_footer() {
/**
* Sets up the Admin Bar if the current theme does not use `wp_body_open`.
*
* @since 5.4.0
*/
if ( ! did_action( 'wp_body_open' ) ) {
add_action( 'wp_footer', 'wp_admin_bar_render', 1000 );
}
/**
* Prints scripts or data before the closing body tag on the front end.
*

View File

@ -13,7 +13,7 @@
*
* @global string $wp_version
*/
$wp_version = '5.4-RC2-47466';
$wp_version = '5.4-RC2-47467';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.