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].

Fixes #47053.
Built from https://develop.svn.wordpress.org/trunk@47455


git-svn-id: http://core.svn.wordpress.org/trunk@47242 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Sergey Biryukov 2020-03-14 16:01:08 +00:00
parent d5f942d7ba
commit dacd7a55ea
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. * 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 * This is called very early on the {@see 'wp_body_open'} action so that it will render
* anything else being added to the footer. * 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 * 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 * 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. * the `$post` global, among others.
* *
* @since 3.1.0 * @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 * @global WP_Admin_Bar $wp_admin_bar
*
* @staticvar bool $rendered
*/ */
function wp_admin_bar_render() { function wp_admin_bar_render() {
global $wp_admin_bar; global $wp_admin_bar;
static $rendered = false;
if ( $rendered ) {
return;
}
if ( ! is_admin_bar_showing() || ! is_object( $wp_admin_bar ) ) { if ( ! is_admin_bar_showing() || ! is_object( $wp_admin_bar ) ) {
return; return;
@ -100,6 +111,8 @@ function wp_admin_bar_render() {
* @since 3.1.0 * @since 3.1.0
*/ */
do_action( 'wp_after_admin_bar_render' ); 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( 'before_signup_header', '_wp_admin_bar_init' );
add_action( 'activate_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_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 ); add_action( 'in_admin_header', 'wp_admin_bar_render', 0 );
// Former admin filters that can also be hooked on the front end. // 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 * @since 1.5.1
*/ */
function wp_footer() { 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. * Prints scripts or data before the closing body tag on the front end.
* *

View File

@ -13,7 +13,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '5.5-alpha-47454'; $wp_version = '5.5-alpha-47455';
/** /**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.