PageRenderTime 433ms CodeModel.GetById 81ms app.highlight 273ms RepoModel.GetById 30ms app.codeStats 1ms

/wp-includes/admin-bar.php

https://bitbucket.org/abnopanda/wordpress
PHP | 767 lines | 502 code | 114 blank | 151 comment | 84 complexity | 47d90d463f46829f535f21e8b2817faa MD5 | raw file
  1<?php
  2/**
  3 * Admin Bar
  4 *
  5 * This code handles the building and rendering of the press bar.
  6 */
  7
  8/**
  9 * Instantiate the admin bar object and set it up as a global for access elsewhere.
 10 *
 11 * To hide the admin bar, you're looking in the wrong place. Unhooking this function will not
 12 * properly remove the admin bar. For that, use show_admin_bar(false) or the show_admin_bar filter.
 13 *
 14 * @since 3.1.0
 15 * @access private
 16 * @return bool Whether the admin bar was successfully initialized.
 17 */
 18function _wp_admin_bar_init() {
 19	global $wp_admin_bar;
 20
 21	if ( ! is_admin_bar_showing() )
 22		return false;
 23
 24	/* Load the admin bar class code ready for instantiation */
 25	require( ABSPATH . WPINC . '/class-wp-admin-bar.php' );
 26
 27	/* Instantiate the admin bar */
 28	$admin_bar_class = apply_filters( 'wp_admin_bar_class', 'WP_Admin_Bar' );
 29	if ( class_exists( $admin_bar_class ) )
 30		$wp_admin_bar = new $admin_bar_class;
 31	else
 32		return false;
 33
 34	$wp_admin_bar->initialize();
 35	$wp_admin_bar->add_menus();
 36
 37	return true;
 38}
 39add_action( 'init', '_wp_admin_bar_init' ); // Don't remove. Wrong way to disable.
 40
 41/**
 42 * Render the admin bar to the page based on the $wp_admin_bar->menu member var.
 43 * This is called very late on the footer actions so that it will render after anything else being
 44 * added to the footer.
 45 *
 46 * It includes the action "admin_bar_menu" which should be used to hook in and
 47 * add new menus to the admin bar. That way you can be sure that you are adding at most optimal point,
 48 * right before the admin bar is rendered. This also gives you access to the $post global, among others.
 49 *
 50 * @since 3.1.0
 51 */
 52function wp_admin_bar_render() {
 53	global $wp_admin_bar;
 54
 55	if ( ! is_admin_bar_showing() || ! is_object( $wp_admin_bar ) )
 56		return false;
 57
 58	do_action_ref_array( 'admin_bar_menu', array( &$wp_admin_bar ) );
 59
 60	do_action( 'wp_before_admin_bar_render' );
 61
 62	$wp_admin_bar->render();
 63
 64	do_action( 'wp_after_admin_bar_render' );
 65}
 66add_action( 'wp_footer', 'wp_admin_bar_render', 1000 );
 67add_action( 'in_admin_header', 'wp_admin_bar_render', 0 );
 68
 69/**
 70 * Add the WordPress logo menu.
 71 *
 72 * @since 3.3.0
 73 */
 74function wp_admin_bar_wp_menu( $wp_admin_bar ) {
 75	$wp_admin_bar->add_menu( array(
 76		'id'    => 'wp-logo',
 77		'title' => '<span class="ab-icon"></span>',
 78		'href'  => self_admin_url( 'about.php' ),
 79		'meta'  => array(
 80			'title' => __('About WordPress'),
 81		),
 82	) );
 83
 84	if ( is_user_logged_in() ) {
 85		// Add "About WordPress" link
 86		$wp_admin_bar->add_menu( array(
 87			'parent' => 'wp-logo',
 88			'id'     => 'about',
 89			'title'  => __('About WordPress'),
 90			'href'  => self_admin_url( 'about.php' ),
 91		) );
 92	}
 93
 94	// Add WordPress.org link
 95	$wp_admin_bar->add_menu( array(
 96		'parent'    => 'wp-logo-external',
 97		'id'        => 'wporg',
 98		'title'     => __('WordPress.org'),
 99		'href'      => __('http://wordpress.org/'),
100	) );
101
102	// Add codex link
103	$wp_admin_bar->add_menu( array(
104		'parent'    => 'wp-logo-external',
105		'id'        => 'documentation',
106		'title'     => __('Documentation'),
107		'href'      => __('http://codex.wordpress.org/'),
108	) );
109
110	// Add forums link
111	$wp_admin_bar->add_menu( array(
112		'parent'    => 'wp-logo-external',
113		'id'        => 'support-forums',
114		'title'     => __('Support Forums'),
115		'href'      => __('http://wordpress.org/support/'),
116	) );
117
118	// Add feedback link
119	$wp_admin_bar->add_menu( array(
120		'parent'    => 'wp-logo-external',
121		'id'        => 'feedback',
122		'title'     => __('Feedback'),
123		'href'      => __('http://wordpress.org/support/forum/requests-and-feedback'),
124	) );
125}
126
127/**
128 * Add the "My Account" item.
129 *
130 * @since 3.3.0
131 */
132function wp_admin_bar_my_account_item( $wp_admin_bar ) {
133	$user_id      = get_current_user_id();
134	$current_user = wp_get_current_user();
135	$profile_url  = get_edit_profile_url( $user_id );
136
137	if ( ! $user_id )
138		return;
139
140	$avatar = get_avatar( $user_id, 16 );
141	$howdy  = sprintf( __('Howdy, %1$s'), $current_user->display_name );
142	$class  = empty( $avatar ) ? '' : 'with-avatar';
143
144	$wp_admin_bar->add_menu( array(
145		'id'        => 'my-account',
146		'parent'    => 'top-secondary',
147		'title'     => $howdy . $avatar,
148		'href'      => $profile_url,
149		'meta'      => array(
150			'class'     => $class,
151			'title'     => __('My Account'),
152		),
153	) );
154}
155
156/**
157 * Add the "My Account" submenu items.
158 *
159 * @since 3.1.0
160 */
161function wp_admin_bar_my_account_menu( $wp_admin_bar ) {
162	$user_id      = get_current_user_id();
163	$current_user = wp_get_current_user();
164	$profile_url  = get_edit_profile_url( $user_id );
165
166	if ( ! $user_id )
167		return;
168
169	$wp_admin_bar->add_group( array(
170		'parent' => 'my-account',
171		'id'     => 'user-actions',
172	) );
173
174	$user_info  = get_avatar( $user_id, 64 );
175	$user_info .= "<span class='display-name'>{$current_user->display_name}</span>";
176
177	if ( $current_user->display_name !== $current_user->user_nicename )
178		$user_info .= "<span class='username'>{$current_user->user_nicename}</span>";
179
180	$wp_admin_bar->add_menu( array(
181		'parent' => 'user-actions',
182		'id'     => 'user-info',
183		'title'  => $user_info,
184		'href'   => $profile_url,
185		'meta'   => array(
186			'tabindex' => -1,
187		),
188	) );
189	$wp_admin_bar->add_menu( array(
190		'parent' => 'user-actions',
191		'id'     => 'edit-profile',
192		'title'  => __( 'Edit My Profile' ),
193		'href' => $profile_url,
194	) );
195	$wp_admin_bar->add_menu( array(
196		'parent' => 'user-actions',
197		'id'     => 'logout',
198		'title'  => __( 'Log Out' ),
199		'href'   => wp_logout_url(),
200	) );
201}
202
203/**
204 * Add the "Site Name" menu.
205 *
206 * @since 3.3.0
207 */
208function wp_admin_bar_site_menu( $wp_admin_bar ) {
209	global $current_site;
210
211	// Don't show for logged out users.
212	if ( ! is_user_logged_in() )
213		return;
214
215	// Show only when the user is a member of this site, or they're a super admin.
216	if ( ! is_user_member_of_blog() && ! is_super_admin() )
217		return;
218
219	$blogname = get_bloginfo('name');
220
221	if ( empty( $blogname ) )
222		$blogname = preg_replace( '#^(https?://)?(www.)?#', '', get_home_url() );
223
224	if ( is_network_admin() ) {
225		$blogname = sprintf( __('Network Admin: %s'), esc_html( $current_site->site_name ) );
226	} elseif ( is_user_admin() ) {
227		$blogname = sprintf( __('Global Dashboard: %s'), esc_html( $current_site->site_name ) );
228	}
229
230	$title = wp_html_excerpt( $blogname, 40 );
231	if ( $title != $blogname )
232		$title = trim( $title ) . '&hellip;';
233
234	$wp_admin_bar->add_menu( array(
235		'id'    => 'site-name',
236		'title' => $title,
237		'href'  => is_admin() ? home_url( '/' ) : admin_url(),
238	) );
239
240	// Create submenu items.
241
242	if ( is_admin() ) {
243		// Add an option to visit the site.
244		$wp_admin_bar->add_menu( array(
245			'parent' => 'site-name',
246			'id'     => 'view-site',
247			'title'  => __( 'Visit Site' ),
248			'href'   => home_url( '/' ),
249		) );
250
251		if ( is_blog_admin() && is_multisite() && current_user_can( 'manage_sites' ) ) {
252			$wp_admin_bar->add_menu( array(
253				'parent' => 'site-name',
254				'id'     => 'edit-site',
255				'title'  => __( 'Edit Site' ),
256				'href'   => network_admin_url( 'site-info.php?id=' . get_current_blog_id() ),
257			) );
258		}
259
260	} else {
261		// We're on the front end, link to the Dashboard.
262		$wp_admin_bar->add_menu( array(
263			'parent' => 'site-name',
264			'id'     => 'dashboard',
265			'title'  => __( 'Dashboard' ),
266			'href'   => admin_url(),
267		) );
268
269		// Add the appearance submenu items.
270		wp_admin_bar_appearance_menu( $wp_admin_bar );
271	}
272}
273
274/**
275 * Add the "My Sites/[Site Name]" menu and all submenus.
276 *
277 * @since 3.1.0
278 */
279function wp_admin_bar_my_sites_menu( $wp_admin_bar ) {
280	global $wpdb;
281
282	// Don't show for logged out users or single site mode.
283	if ( ! is_user_logged_in() || ! is_multisite() )
284		return;
285
286	// Show only when the user has at least one site, or they're a super admin.
287	if ( count( $wp_admin_bar->user->blogs ) < 1 && ! is_super_admin() )
288		return;
289
290	$wp_admin_bar->add_menu( array(
291		'id'    => 'my-sites',
292		'title' => __( 'My Sites' ),
293		'href'  => admin_url( 'my-sites.php' ),
294	) );
295
296	if ( is_super_admin() ) {
297		$wp_admin_bar->add_group( array(
298			'parent' => 'my-sites',
299			'id'     => 'my-sites-super-admin',
300		) );
301
302		$wp_admin_bar->add_menu( array(
303			'parent' => 'my-sites-super-admin',
304			'id'     => 'network-admin',
305			'title'  => __('Network Admin'),
306			'href'   => network_admin_url(),
307		) );
308
309		$wp_admin_bar->add_menu( array(
310			'parent' => 'network-admin',
311			'id'     => 'network-admin-d',
312			'title'  => __( 'Dashboard' ),
313			'href'   => network_admin_url(),
314		) );
315		$wp_admin_bar->add_menu( array(
316			'parent' => 'network-admin',
317			'id'     => 'network-admin-s',
318			'title'  => __( 'Sites' ),
319			'href'   => network_admin_url( 'sites.php' ),
320		) );
321		$wp_admin_bar->add_menu( array(
322			'parent' => 'network-admin',
323			'id'     => 'network-admin-u',
324			'title'  => __( 'Users' ),
325			'href'   => network_admin_url( 'users.php' ),
326		) );
327		$wp_admin_bar->add_menu( array(
328			'parent' => 'network-admin',
329			'id'     => 'network-admin-v',
330			'title'  => __( 'Visit Network' ),
331			'href'   => network_home_url(),
332		) );
333	}
334
335	// Add site links
336	$wp_admin_bar->add_group( array(
337		'parent' => 'my-sites',
338		'id'     => 'my-sites-list',
339		'meta'   => array(
340			'class' => is_super_admin() ? 'ab-sub-secondary' : '',
341		),
342	) );
343
344	foreach ( (array) $wp_admin_bar->user->blogs as $blog ) {
345		switch_to_blog( $blog->userblog_id );
346
347		$blavatar = '<div class="blavatar"></div>';
348
349		$blogname = empty( $blog->blogname ) ? $blog->domain : $blog->blogname;
350		$menu_id  = 'blog-' . $blog->userblog_id;
351
352		$wp_admin_bar->add_menu( array(
353			'parent'    => 'my-sites-list',
354			'id'        => $menu_id,
355			'title'     => $blavatar . $blogname,
356			'href'      => admin_url(),
357		) );
358
359		$wp_admin_bar->add_menu( array(
360			'parent' => $menu_id,
361			'id'     => $menu_id . '-d',
362			'title'  => __( 'Dashboard' ),
363			'href'   => admin_url(),
364		) );
365
366		if ( current_user_can( 'edit_posts' ) ) {
367			$wp_admin_bar->add_menu( array(
368				'parent' => $menu_id,
369				'id'     => $menu_id . '-n',
370				'title'  => __( 'New Post' ),
371				'href'   => admin_url( 'post-new.php' ),
372			) );
373			$wp_admin_bar->add_menu( array(
374				'parent' => $menu_id,
375				'id'     => $menu_id . '-c',
376				'title'  => __( 'Manage Comments' ),
377				'href'   => admin_url( 'edit-comments.php' ),
378			) );
379		}
380
381		$wp_admin_bar->add_menu( array(
382			'parent' => $menu_id,
383			'id'     => $menu_id . '-v',
384			'title'  => __( 'Visit Site' ),
385			'href'   => home_url( '/' ),
386		) );
387
388		restore_current_blog();
389	}
390}
391
392/**
393 * Provide a shortlink.
394 *
395 * @since 3.1.0
396 */
397function wp_admin_bar_shortlink_menu( $wp_admin_bar ) {
398	$short = wp_get_shortlink( 0, 'query' );
399	$id = 'get-shortlink';
400
401	if ( empty( $short ) )
402		return;
403
404	$html = '<input class="shortlink-input" type="text" readonly="readonly" value="' . esc_attr( $short ) . '" />';
405
406	$wp_admin_bar->add_menu( array(
407		'id' => $id,
408		'title' => __( 'Shortlink' ),
409		'href' => $short,
410		'meta' => array( 'html' => $html ),
411	) );
412}
413
414/**
415 * Provide an edit link for posts and terms.
416 *
417 * @since 3.1.0
418 */
419function wp_admin_bar_edit_menu( $wp_admin_bar ) {
420	global $tag, $wp_the_query;
421
422	if ( is_admin() ) {
423		$current_screen = get_current_screen();
424		$post = get_post();
425
426		if ( 'post' == $current_screen->base
427			&& 'add' != $current_screen->action
428			&& ( $post_type_object = get_post_type_object( $post->post_type ) )
429			&& current_user_can( $post_type_object->cap->read_post, $post->ID )
430			&& ( $post_type_object->public )
431			&& ( $post_type_object->show_in_admin_bar ) )
432		{
433			$wp_admin_bar->add_menu( array(
434				'id' => 'view',
435				'title' => $post_type_object->labels->view_item,
436				'href' => get_permalink( $post->ID )
437			) );
438		} elseif ( 'edit-tags' == $current_screen->base
439			&& isset( $tag ) && is_object( $tag )
440			&& ( $tax = get_taxonomy( $tag->taxonomy ) )
441			&& $tax->public )
442		{
443			$wp_admin_bar->add_menu( array(
444				'id' => 'view',
445				'title' => $tax->labels->view_item,
446				'href' => get_term_link( $tag )
447			) );
448		}
449	} else {
450		$current_object = $wp_the_query->get_queried_object();
451
452		if ( empty( $current_object ) )
453			return;
454
455		if ( ! empty( $current_object->post_type )
456			&& ( $post_type_object = get_post_type_object( $current_object->post_type ) )
457			&& current_user_can( $post_type_object->cap->edit_post, $current_object->ID )
458			&& $post_type_object->show_ui && $post_type_object->show_in_admin_bar )
459		{
460			$wp_admin_bar->add_menu( array(
461				'id' => 'edit',
462				'title' => $post_type_object->labels->edit_item,
463				'href' => get_edit_post_link( $current_object->ID )
464			) );
465		} elseif ( ! empty( $current_object->taxonomy )
466			&& ( $tax = get_taxonomy( $current_object->taxonomy ) )
467			&& current_user_can( $tax->cap->edit_terms )
468			&& $tax->show_ui )
469		{
470			$wp_admin_bar->add_menu( array(
471				'id' => 'edit',
472				'title' => $tax->labels->edit_item,
473				'href' => get_edit_term_link( $current_object->term_id, $current_object->taxonomy )
474			) );
475		}
476	}
477}
478
479/**
480 * Add "Add New" menu.
481 *
482 * @since 3.1.0
483 */
484function wp_admin_bar_new_content_menu( $wp_admin_bar ) {
485	$actions = array();
486
487	$cpts = (array) get_post_types( array( 'show_in_admin_bar' => true ), 'objects' );
488
489	if ( isset( $cpts['post'] ) && current_user_can( $cpts['post']->cap->edit_posts ) )
490		$actions[ 'post-new.php' ] = array( $cpts['post']->labels->name_admin_bar, 'new-post' );
491
492	if ( isset( $cpts['attachment'] ) && current_user_can( 'upload_files' ) )
493		$actions[ 'media-new.php' ] = array( $cpts['attachment']->labels->name_admin_bar, 'new-media' );
494
495	if ( current_user_can( 'manage_links' ) )
496		$actions[ 'link-add.php' ] = array( _x( 'Link', 'add new from admin bar' ), 'new-link' );
497
498	if ( isset( $cpts['page'] ) && current_user_can( $cpts['page']->cap->edit_posts ) )
499		$actions[ 'post-new.php?post_type=page' ] = array( $cpts['page']->labels->name_admin_bar, 'new-page' );
500
501	unset( $cpts['post'], $cpts['page'], $cpts['attachment'] );
502
503	// Add any additional custom post types.
504	foreach ( $cpts as $cpt ) {
505		if ( ! current_user_can( $cpt->cap->edit_posts ) )
506			continue;
507
508		$key = 'post-new.php?post_type=' . $cpt->name;
509		$actions[ $key ] = array( $cpt->labels->name_admin_bar, 'new-' . $cpt->name );
510	}
511	// Avoid clash with parent node and a 'content' post type.
512	if ( isset( $actions['post-new.php?post_type=content'] ) )
513		$actions['post-new.php?post_type=content'][1] = 'add-new-content';
514
515	if ( current_user_can( 'create_users' ) || current_user_can( 'promote_users' ) )
516		$actions[ 'user-new.php' ] = array( _x( 'User', 'add new from admin bar' ), 'new-user' );
517
518	if ( ! $actions )
519		return;
520
521	$title = '<span class="ab-icon"></span><span class="ab-label">' . _x( 'New', 'admin bar menu group label' ) . '</span>';
522
523	$wp_admin_bar->add_menu( array(
524		'id'    => 'new-content',
525		'title' => $title,
526		'href'  => admin_url( current( array_keys( $actions ) ) ),
527		'meta'  => array(
528			'title' => _x( 'Add New', 'admin bar menu group label' ),
529		),
530	) );
531
532	foreach ( $actions as $link => $action ) {
533		list( $title, $id ) = $action;
534
535		$wp_admin_bar->add_menu( array(
536			'parent'    => 'new-content',
537			'id'        => $id,
538			'title'     => $title,
539			'href'      => admin_url( $link )
540		) );
541	}
542}
543
544/**
545 * Add edit comments link with awaiting moderation count bubble.
546 *
547 * @since 3.1.0
548 */
549function wp_admin_bar_comments_menu( $wp_admin_bar ) {
550	if ( !current_user_can('edit_posts') )
551		return;
552
553	$awaiting_mod = wp_count_comments();
554	$awaiting_mod = $awaiting_mod->moderated;
555	$awaiting_title = esc_attr( sprintf( _n( '%s comment awaiting moderation', '%s comments awaiting moderation', $awaiting_mod ), number_format_i18n( $awaiting_mod ) ) );
556
557	$icon  = '<span class="ab-icon"></span>';
558	$title = '<span id="ab-awaiting-mod" class="ab-label awaiting-mod pending-count count-' . $awaiting_mod . '">' . number_format_i18n( $awaiting_mod ) . '</span>';
559
560	$wp_admin_bar->add_menu( array(
561		'id'    => 'comments',
562		'title' => $icon . $title,
563		'href'  => admin_url('edit-comments.php'),
564		'meta'  => array( 'title' => $awaiting_title ),
565	) );
566}
567
568/**
569 * Add appearance submenu items to the "Site Name" menu.
570 *
571 * @since 3.1.0
572 */
573function wp_admin_bar_appearance_menu( $wp_admin_bar ) {
574	$wp_admin_bar->add_group( array( 'parent' => 'site-name', 'id' => 'appearance' ) );
575
576	if ( current_user_can( 'switch_themes' ) || current_user_can( 'edit_theme_options' ) )
577		$wp_admin_bar->add_menu( array( 'parent' => 'appearance', 'id' => 'themes', 'title' => __('Themes'), 'href' => admin_url('themes.php') ) );
578
579	if ( ! current_user_can( 'edit_theme_options' ) )
580		return;
581
582	$current_url = ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
583	$wp_admin_bar->add_menu( array(
584		'parent' => 'appearance',
585		'id'     => 'customize',
586		'title'  => __('Customize'),
587		'href'   => add_query_arg( 'url', urlencode( $current_url ), wp_customize_url() ),
588		'meta'   => array(
589			'class' => 'hide-if-no-customize',
590		),
591	) );
592	add_action( 'wp_before_admin_bar_render', 'wp_customize_support_script' );
593
594	if ( current_theme_supports( 'widgets' )  )
595		$wp_admin_bar->add_menu( array( 'parent' => 'appearance', 'id' => 'widgets', 'title' => __('Widgets'), 'href' => admin_url('widgets.php') ) );
596
597	 if ( current_theme_supports( 'menus' ) || current_theme_supports( 'widgets' ) )
598		$wp_admin_bar->add_menu( array( 'parent' => 'appearance', 'id' => 'menus', 'title' => __('Menus'), 'href' => admin_url('nav-menus.php') ) );
599
600	if ( current_theme_supports( 'custom-background' ) )
601		$wp_admin_bar->add_menu( array( 'parent' => 'appearance', 'id' => 'background', 'title' => __('Background'), 'href' => admin_url('themes.php?page=custom-background') ) );
602
603	if ( current_theme_supports( 'custom-header' ) )
604		$wp_admin_bar->add_menu( array( 'parent' => 'appearance', 'id' => 'header', 'title' => __('Header'), 'href' => admin_url('themes.php?page=custom-header') ) );
605}
606
607/**
608 * Provide an update link if theme/plugin/core updates are available.
609 *
610 * @since 3.1.0
611 */
612function wp_admin_bar_updates_menu( $wp_admin_bar ) {
613
614	$update_data = wp_get_update_data();
615
616	if ( !$update_data['counts']['total'] )
617		return;
618
619	$title = '<span class="ab-icon"></span><span class="ab-label">' . number_format_i18n( $update_data['counts']['total'] ) . '</span>';
620	$title .= '<span class="screen-reader-text">' . $update_data['title'] . '</span>';
621
622	$wp_admin_bar->add_menu( array(
623		'id'    => 'updates',
624		'title' => $title,
625		'href'  => network_admin_url( 'update-core.php' ),
626		'meta'  => array(
627			'title' => $update_data['title'],
628		),
629	) );
630}
631
632/**
633 * Add search form.
634 *
635 * @since 3.3.0
636 */
637function wp_admin_bar_search_menu( $wp_admin_bar ) {
638	if ( is_admin() )
639		return;
640
641	$form  = '<form action="' . esc_url( home_url( '/' ) ) . '" method="get" id="adminbarsearch">';
642	$form .= '<input class="adminbar-input" name="s" id="adminbar-search" type="text" value="" maxlength="150" />';
643	$form .= '<input type="submit" class="adminbar-button" value="' . __('Search') . '"/>';
644	$form .= '</form>';
645
646	$wp_admin_bar->add_menu( array(
647		'parent' => 'top-secondary',
648		'id'     => 'search',
649		'title'  => $form,
650		'meta'   => array(
651			'class'    => 'admin-bar-search',
652			'tabindex' => -1,
653		)
654	) );
655}
656
657/**
658 * Add secondary menus.
659 *
660 * @since 3.3.0
661 */
662function wp_admin_bar_add_secondary_groups( $wp_admin_bar ) {
663	$wp_admin_bar->add_group( array(
664		'id'     => 'top-secondary',
665		'meta'   => array(
666			'class' => 'ab-top-secondary',
667		),
668	) );
669
670	$wp_admin_bar->add_group( array(
671		'parent' => 'wp-logo',
672		'id'     => 'wp-logo-external',
673		'meta'   => array(
674			'class' => 'ab-sub-secondary',
675		),
676	) );
677}
678
679/**
680 * Style and scripts for the admin bar.
681 *
682 * @since 3.1.0
683 *
684 */
685function wp_admin_bar_header() { ?>
686<style type="text/css" media="print">#wpadminbar { display:none; }</style>
687<?php
688}
689
690/**
691 * Default admin bar callback.
692 *
693 * @since 3.1.0
694 *
695 */
696function _admin_bar_bump_cb() { ?>
697<style type="text/css" media="screen">
698	html { margin-top: 28px !important; }
699	* html body { margin-top: 28px !important; }
700</style>
701<?php
702}
703
704/**
705 * Set the display status of the admin bar.
706 *
707 * This can be called immediately upon plugin load. It does not need to be called from a function hooked to the init action.
708 *
709 * @since 3.1.0
710 *
711 * @param bool $show Whether to allow the admin bar to show.
712 * @return void
713 */
714function show_admin_bar( $show ) {
715	global $show_admin_bar;
716	$show_admin_bar = (bool) $show;
717}
718
719/**
720 * Determine whether the admin bar should be showing.
721 *
722 * @since 3.1.0
723 *
724 * @return bool Whether the admin bar should be showing.
725 */
726function is_admin_bar_showing() {
727	global $show_admin_bar, $pagenow;
728
729	// For all these types of requests, we never want an admin bar.
730	if ( defined('XMLRPC_REQUEST') || defined('DOING_AJAX') || defined('IFRAME_REQUEST') )
731		return false;
732
733	// Integrated into the admin.
734	if ( is_admin() )
735		return true;
736
737	if ( ! isset( $show_admin_bar ) ) {
738		if ( ! is_user_logged_in() || 'wp-login.php' == $pagenow ) {
739			$show_admin_bar = false;
740		} else {
741			$show_admin_bar = _get_admin_bar_pref();
742		}
743	}
744
745	$show_admin_bar = apply_filters( 'show_admin_bar', $show_admin_bar );
746
747	return $show_admin_bar;
748}
749
750/**
751 * Retrieve the admin bar display preference of a user.
752 *
753 * @since 3.1.0
754 * @access private
755 *
756 * @param string $context Context of this preference check. Defaults to 'front'. The 'admin'
757 * 	preference is no longer used.
758 * @param int $user Optional. ID of the user to check, defaults to 0 for current user.
759 * @return bool Whether the admin bar should be showing for this user.
760 */
761function _get_admin_bar_pref( $context = 'front', $user = 0 ) {
762	$pref = get_user_option( "show_admin_bar_{$context}", $user );
763	if ( false === $pref )
764		return true;
765
766	return 'true' === $pref;
767}