Make WordPress Core


Ignore:
Timestamp:
03/17/2020 07:26:34 PM (4 years ago)
Author:
SergeyBiryukov
Message:

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.

Location:
branches/5.4
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/5.4

  • branches/5.4/src/wp-includes/admin-bar.php

    r47198 r47467  
    5656 * Renders the admin bar to the page based on the $wp_admin_bar->menu member var.
    5757 *
    58  * This is called very late on the footer actions so that it will render after
    59  * anything else being added to the footer.
     58 * This is called very early on the {@see 'wp_body_open'} action so that it will render
     59 * before anything else being added to the page body.
     60 *
     61 * For backward compatibility with themes not using the 'wp_body_open' action,
     62 * the function is also called late on {@see 'wp_footer'}.
    6063 *
    6164 * It includes the {@see 'admin_bar_menu'} action which should be used to hook in and
     
    6568 *
    6669 * @since 3.1.0
     70 * @since 5.4.0 Called on 'wp_body_open' action first, with 'wp_footer' as a fallback.
    6771 *
    6872 * @global WP_Admin_Bar $wp_admin_bar
     73 *
     74 * @staticvar bool $rendered
    6975 */
    7076function wp_admin_bar_render() {
    7177    global $wp_admin_bar;
     78    static $rendered = false;
     79
     80    if ( $rendered ) {
     81        return;
     82    }
    7283
    7384    if ( ! is_admin_bar_showing() || ! is_object( $wp_admin_bar ) ) {
     
    101112     */
    102113    do_action( 'wp_after_admin_bar_render' );
     114
     115    $rendered = true;
    103116}
    104117
Note: See TracChangeset for help on using the changeset viewer.