On this page
WP_Admin_Bar::initialize()
Initializes the admin bar.
Source
File: wp-includes/class-wp-admin-bar.php. View all references
public function initialize() {
$this->user = new stdClass;
if ( is_user_logged_in() ) {
/* Populate settings we need for the menu based on the current user. */
$this->user->blogs = get_blogs_of_user( get_current_user_id() );
if ( is_multisite() ) {
$this->user->active_blog = get_active_blog_for_user( get_current_user_id() );
$this->user->domain = empty( $this->user->active_blog ) ? user_admin_url() : trailingslashit( get_home_url( $this->user->active_blog->blog_id ) );
$this->user->account_domain = $this->user->domain;
} else {
$this->user->active_blog = $this->user->blogs[ get_current_blog_id() ];
$this->user->domain = trailingslashit( home_url() );
$this->user->account_domain = $this->user->domain;
}
}
add_action( 'wp_head', 'wp_admin_bar_header' );
add_action( 'admin_head', 'wp_admin_bar_header' );
if ( current_theme_supports( 'admin-bar' ) ) {
/**
* To remove the default padding styles from WordPress for the Toolbar, use the following code:
* add_theme_support( 'admin-bar', array( 'callback' => '__return_false' ) );
*/
$admin_bar_args = get_theme_support( 'admin-bar' );
$header_callback = $admin_bar_args[0]['callback'];
}
if ( empty( $header_callback ) ) {
$header_callback = '_admin_bar_bump_cb';
}
add_action( 'wp_head', $header_callback );
wp_enqueue_script( 'admin-bar' );
wp_enqueue_style( 'admin-bar' );
/**
* Fires after WP_Admin_Bar is initialized.
*
* @since 3.1.0
*/
do_action( 'admin_bar_init' );
}
Hooks
- do_action( 'admin_bar_init' )
-
Fires after WP_Admin_Bar is initialized.
Related
Uses
| Uses | Description |
|---|---|
| wp_enqueue_script() wp-includes/functions.wp-scripts.php | Enqueue a script. |
| get_theme_support() wp-includes/theme.php | Gets the theme support arguments passed when registering that support. |
| user_admin_url() wp-includes/link-template.php | Retrieves the URL to the admin area for the current user. |
| get_home_url() wp-includes/link-template.php | Retrieves the URL for a given site where the front end is accessible. |
| wp_enqueue_style() wp-includes/functions.wp-styles.php | Enqueue a CSS stylesheet. |
| get_blogs_of_user() wp-includes/user.php | Gets the sites a user belongs to. |
| get_active_blog_for_user() wp-includes/ms-functions.php | Gets one of a user’s active blogs. |
| current_theme_supports() wp-includes/theme.php | Checks a theme’s support for a given feature. |
| trailingslashit() wp-includes/formatting.php | Appends a trailing slash. |
| is_user_logged_in() wp-includes/pluggable.php | Determines whether the current visitor is a logged in user. |
| is_multisite() wp-includes/load.php | If Multisite is enabled. |
| get_current_blog_id() wp-includes/load.php | Retrieve the current site ID. |
| home_url() wp-includes/link-template.php | Retrieves the URL for the current site where the front end is accessible. |
| add_action() wp-includes/plugin.php | Adds a callback function to an action hook. |
| do_action() wp-includes/plugin.php | Calls the callback functions that have been added to an action hook. |
| get_current_user_id() wp-includes/user.php | Gets the current user’s ID. |
Used By
| Used By | Description |
|---|---|
| _wp_admin_bar_init() wp-includes/admin-bar.php | Instantiates the admin bar object and set it up as a global for access elsewhere. |
Changelog
| Version | Description |
|---|---|
| 3.1.0 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/classes/wp_admin_bar/initialize