PageRenderTime 93ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-includes/admin-bar.php

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