Title: WP_Admin_Bar::initialize
Published: April 25, 2014
Last modified: May 20, 2026

---

# WP_Admin_Bar::initialize()

## In this article

 * [Source](https://developer.wordpress.org/reference/classes/wp_admin_bar/initialize/?output_format=md#source)
 * [Hooks](https://developer.wordpress.org/reference/classes/wp_admin_bar/initialize/?output_format=md#hooks)
 * [Related](https://developer.wordpress.org/reference/classes/wp_admin_bar/initialize/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/classes/wp_admin_bar/initialize/?output_format=md#changelog)

[ Back to top](https://developer.wordpress.org/reference/classes/wp_admin_bar/initialize/?output_format=md#wp--skip-link--target)

Initializes the admin bar.

## 󠀁[Source](https://developer.wordpress.org/reference/classes/wp_admin_bar/initialize/?output_format=md#source)󠁿

    ```php
    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' );
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-admin-bar.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.0/src/wp-includes/class-wp-admin-bar.php#L36)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.0/src/wp-includes/class-wp-admin-bar.php#L36-L81)

## 󠀁[Hooks](https://developer.wordpress.org/reference/classes/wp_admin_bar/initialize/?output_format=md#hooks)󠁿

 [do_action( ‘admin_bar_init’ )](https://developer.wordpress.org/reference/hooks/admin_bar_init/)

Fires after [WP_Admin_Bar](https://developer.wordpress.org/reference/classes/wp_admin_bar/)
is initialized.

## 󠀁[Related](https://developer.wordpress.org/reference/classes/wp_admin_bar/initialize/?output_format=md#related)󠁿

| Uses | Description | 
| [get_theme_support()](https://developer.wordpress.org/reference/functions/get_theme_support/)`wp-includes/theme.php` |

Gets the theme support arguments passed when registering that support.

  | 
| [user_admin_url()](https://developer.wordpress.org/reference/functions/user_admin_url/)`wp-includes/link-template.php` |

Retrieves the URL to the admin area for the current user.

  | 
| [get_home_url()](https://developer.wordpress.org/reference/functions/get_home_url/)`wp-includes/link-template.php` |

Retrieves the URL for a given site where the front end is accessible.

  | 
| [get_blogs_of_user()](https://developer.wordpress.org/reference/functions/get_blogs_of_user/)`wp-includes/user.php` |

Gets the sites a user belongs to.

  | 
| [get_active_blog_for_user()](https://developer.wordpress.org/reference/functions/get_active_blog_for_user/)`wp-includes/ms-functions.php` |

Gets one of a user’s active blogs.

  | 
| [current_theme_supports()](https://developer.wordpress.org/reference/functions/current_theme_supports/)`wp-includes/theme.php` |

Checks a theme’s support for a given feature.

  | 
| [trailingslashit()](https://developer.wordpress.org/reference/functions/trailingslashit/)`wp-includes/formatting.php` |

Appends a trailing slash.

  | 
| [is_user_logged_in()](https://developer.wordpress.org/reference/functions/is_user_logged_in/)`wp-includes/pluggable.php` |

Determines whether the current visitor is a logged in user.

  | 
| [is_multisite()](https://developer.wordpress.org/reference/functions/is_multisite/)`wp-includes/load.php` |

Determines whether Multisite is enabled.

  | 
| [get_current_blog_id()](https://developer.wordpress.org/reference/functions/get_current_blog_id/)`wp-includes/load.php` |

Retrieves the current site ID.

  | 
| [wp_enqueue_script()](https://developer.wordpress.org/reference/functions/wp_enqueue_script/)`wp-includes/functions.wp-scripts.php` |

Enqueues a script.

  | 
| [home_url()](https://developer.wordpress.org/reference/functions/home_url/)`wp-includes/link-template.php` |

Retrieves the URL for the current site where the front end is accessible.

  | 
| [wp_enqueue_style()](https://developer.wordpress.org/reference/functions/wp_enqueue_style/)`wp-includes/functions.wp-styles.php` |

Enqueues a CSS stylesheet.

  | 
| [add_action()](https://developer.wordpress.org/reference/functions/add_action/)`wp-includes/plugin.php` |

Adds a callback function to an action hook.

  | 
| [do_action()](https://developer.wordpress.org/reference/functions/do_action/)`wp-includes/plugin.php` |

Calls the callback functions that have been added to an action hook.

  | 
| [get_current_user_id()](https://developer.wordpress.org/reference/functions/get_current_user_id/)`wp-includes/user.php` |

Gets the current user’s ID.

  |

[Show 11 more](https://developer.wordpress.org/reference/classes/wp_admin_bar/initialize/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/classes/wp_admin_bar/initialize/?output_format=md#)

| Used by | Description | 
| [_wp_admin_bar_init()](https://developer.wordpress.org/reference/functions/_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](https://developer.wordpress.org/reference/classes/wp_admin_bar/initialize/?output_format=md#changelog)󠁿

| Version | Description | 
| [3.1.0](https://developer.wordpress.org/reference/since/3.1.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fblue-sea-697d.quartiers047.workers.dev%3A443%2Fhttps%2Fdeveloper.wordpress.org%2Freference%2Fclasses%2Fwp_admin_bar%2Finitialize%2F)
before being able to contribute a note or feedback.