WordPress.org

Make WordPress Core

Ticket #47053: 47053.7.diff

File 47053.7.diff, 2.8 KB (added by SergeyBiryukov, 19 months ago)
  • src/wp-includes/admin-bar.php

     
    5555/**
    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.
    6060 *
     61 * For backward compatibility with themes not using the 'wp_body_open' action,
     62 * the function is also called late on {@see 'wp_footer'}.
     63 *
    6164 * It includes the {@see 'admin_bar_menu'} action which should be used to hook in and
    6265 * add new menus to the admin bar. That way you can be sure that you are adding at most
    6366 * optimal point, right before the admin bar is rendered. This also gives you access to
     
    6467 * the `$post` global, among others.
    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;
    7279
     80        if ( $rendered ) {
     81                return;
     82        }
     83
    7384        if ( ! is_admin_bar_showing() || ! is_object( $wp_admin_bar ) ) {
    7485                return;
    7586        }
     
    100111         * @since 3.1.0
    101112         */
    102113        do_action( 'wp_after_admin_bar_render' );
     114
     115        $rendered = true;
    103116}
    104117
    105118/**
  • src/wp-includes/default-filters.php

     
    538538add_action( 'before_signup_header', '_wp_admin_bar_init' );
    539539add_action( 'activate_header', '_wp_admin_bar_init' );
    540540add_action( 'wp_body_open', 'wp_admin_bar_render', 0 );
     541add_action( 'wp_footer', 'wp_admin_bar_render', 1000 ); // Back-compat for themes not using `wp_body_open`.
    541542add_action( 'in_admin_header', 'wp_admin_bar_render', 0 );
    542543
    543544// Former admin filters that can also be hooked on the front end.
  • src/wp-includes/general-template.php

     
    28932893 */
    28942894function wp_footer() {
    28952895        /**
    2896          * Sets up the Admin Bar if the current theme does not use `wp_body_open`.
    2897          *
    2898          * @since 5.4.0
    2899          */
    2900         if ( ! did_action( 'wp_body_open' ) ) {
    2901                 add_action( 'wp_footer', 'wp_admin_bar_render', 1000 );
    2902         }
    2903         /**
    29042896         * Prints scripts or data before the closing body tag on the front end.
    29052897         *
    29062898         * @since 1.5.1