Advertisement
Guest User

komplet admin-bar.php

a guest
Sep 2nd, 2012
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 23.58 KB | None | 0 0
  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.  */
  18. function _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. }
  39. add_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.  */
  52. function 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. }
  66. add_action( 'wp_footer', 'wp_admin_bar_render', 1000 );
  67. add_action( 'in_admin_header', 'wp_admin_bar_render', 0 );
  68.  
  69. /**
  70.  * Add the WordPress logo menu.
  71.  *
  72.  * @since 3.3.0
  73.  */
  74. function 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. /* Soukrome zpravy admin bar*/
  128.  
  129.  
  130.  
  131. add_action('admin_bar_menu', 'add_toolbar_items', 100);
  132. function add_toolbar_items($admin_bar){
  133.  
  134.     // ziskani poctu zprav (vsechny + neprectene)
  135.     global $wpdb, $current_user;
  136.         $num_pm = $wpdb->get_var( 'SELECT COUNT(*) FROM ' . $wpdb->prefix . 'pm WHERE `recipient` = "' . $current_user->user_login . '" AND `deleted` != "2"' );
  137.         $num_unread = $wpdb->get_var( 'SELECT COUNT(*) FROM ' . $wpdb->prefix . 'pm WHERE `recipient` = "' . $current_user->user_login . '" AND `read` = 0 AND `deleted` != "2"' );
  138.  
  139.         if ( empty( $num_pm ) ) {
  140.             $num_pm = 0;
  141.         }
  142.  
  143.         if ( empty( $num_unread ) ) {
  144.             $num_unread = 0;
  145.             $nazev = 'Soukromé zprávy';
  146.             $titulek = 'Žádné nové zprávy';
  147.         }
  148.  
  149.         else {
  150.             $nazev = 'Soukromé zprávy (' . $num_unread . ')';
  151.             $titulek = $num_unread . 'nové zprávy';
  152.  
  153.         }
  154.    
  155.    
  156.  
  157.     $admin_bar->add_menu( array(
  158.         'id'    => 'my-item',
  159.         'title' => $nazev,
  160.         'href'  => self_admin_url('/admin.php?page=rwpm_inbox'),
  161.         'meta'  => array(
  162.             'title' => $titulek        
  163.         ),
  164.     ));
  165.     $admin_bar->add_menu( array(
  166.         'id'    => 'my-sub-item',
  167.         'parent' => 'my-item',
  168.         'title' => 'Odeslat zprávu',
  169.         'href'  => self_admin_url('/admin.php?page=rwpm_send'),
  170.         'meta'  => array(
  171.             'title' => __('Odeslat zprávu'),
  172.             'target' => '_blank',
  173.             'class' => 'my_menu_item_class'
  174.         ),
  175.     ));
  176.     $admin_bar->add_menu( array(
  177.         'id'    => 'my-second-sub-item',
  178.         'parent' => 'my-item',
  179.         'title' => 'Odeslané',
  180.         'href'  => self_admin_url('/admin.php?page=rwpm_outbox'),
  181.         'meta'  => array(
  182.             'title' => __('Odeslané'),
  183. /*          'target' => '_blank',*/
  184.             'class' => 'my_menu_item_class'
  185.         ),
  186.     ));
  187. }
  188.  
  189. /* Konec Soukrome zpravy admin bar*/
  190.  
  191.  
  192.  
  193. /**
  194.  * Add the "My Account" item.
  195.  *
  196.  * @since 3.3.0
  197.  */
  198. function wp_admin_bar_my_account_item( $wp_admin_bar ) {
  199.     $user_id      = get_current_user_id();
  200.     $current_user = wp_get_current_user();
  201.     $profile_url  = get_edit_profile_url( $user_id );
  202.  
  203.     if ( ! $user_id )
  204.         return;
  205.  
  206.     $avatar = get_avatar( $user_id, 16 );
  207.     $howdy  = sprintf( __('Howdy, %1$s'), $current_user->display_name );
  208.     $class  = empty( $avatar ) ? '' : 'with-avatar';
  209.  
  210.     $wp_admin_bar->add_menu( array(
  211.         'id'        => 'my-account',
  212.         'parent'    => 'top-secondary',
  213.         'title'     => $howdy . $avatar,
  214.         'href'      => $profile_url,
  215.         'meta'      => array(
  216.             'class'     => $class,
  217.             'title'     => __('My Account'),
  218.         ),
  219.     ) );
  220. }
  221.  
  222. /**
  223.  * Add the "My Account" submenu items.
  224.  *
  225.  * @since 3.1.0
  226.  */
  227. function wp_admin_bar_my_account_menu( $wp_admin_bar ) {
  228.     $user_id      = get_current_user_id();
  229.     $current_user = wp_get_current_user();
  230.     $profile_url  = get_edit_profile_url( $user_id );
  231.  
  232.     if ( ! $user_id )
  233.         return;
  234.  
  235.     $wp_admin_bar->add_group( array(
  236.         'parent' => 'my-account',
  237.         'id'     => 'user-actions',
  238.     ) );
  239.  
  240.     $user_info  = get_avatar( $user_id, 64 );
  241.     $user_info .= "<span class='display-name'>{$current_user->display_name}</span>";
  242.  
  243.     if ( $current_user->display_name !== $current_user->user_nicename )
  244.         $user_info .= "<span class='username'>{$current_user->user_nicename}</span>";
  245.  
  246.     $wp_admin_bar->add_menu( array(
  247.         'parent' => 'user-actions',
  248.         'id'     => 'user-info',
  249.         'title'  => $user_info,
  250.         'href'   => $profile_url,
  251.         'meta'   => array(
  252.             'tabindex' => -1,
  253.         ),
  254.     ) );
  255.     $wp_admin_bar->add_menu( array(
  256.         'parent' => 'user-actions',
  257.         'id'     => 'edit-profile',
  258.         'title'  => __( 'Edit My Profile' ),
  259.         'href' => $profile_url,
  260.     ) );
  261.     $wp_admin_bar->add_menu( array(
  262.         'parent' => 'user-actions',
  263.         'id'     => 'logout',
  264.         'title'  => __( 'Log Out' ),
  265.         'href'   => wp_logout_url(),
  266.     ) );
  267. }
  268.  
  269. /**
  270.  * Add the "Site Name" menu.
  271.  *
  272.  * @since 3.3.0
  273.  */
  274. function wp_admin_bar_site_menu( $wp_admin_bar ) {
  275.     global $current_site;
  276.  
  277.     // Don't show for logged out users.
  278.     if ( ! is_user_logged_in() )
  279.         return;
  280.  
  281.     // Show only when the user is a member of this site, or they're a super admin.
  282.     if ( ! is_user_member_of_blog() && ! is_super_admin() )
  283.         return;
  284.  
  285.     $blogname = get_bloginfo('name');
  286.  
  287.     if ( empty( $blogname ) )
  288.         $blogname = preg_replace( '#^(https?://)?(www.)?#', '', get_home_url() );
  289.  
  290.     if ( is_network_admin() ) {
  291.         $blogname = sprintf( __('Network Admin: %s'), esc_html( $current_site->site_name ) );
  292.     } elseif ( is_user_admin() ) {
  293.         $blogname = sprintf( __('Global Dashboard: %s'), esc_html( $current_site->site_name ) );
  294.     }
  295.  
  296.     $title = wp_html_excerpt( $blogname, 40 );
  297.     if ( $title != $blogname )
  298.         $title = trim( $title ) . '&hellip;';
  299.  
  300.     $wp_admin_bar->add_menu( array(
  301.         'id'    => 'site-name',
  302.         'title' => $title,
  303.         'href'  => is_admin() ? home_url( '/' ) : admin_url(),
  304.     ) );
  305.  
  306.     // Create submenu items.
  307.  
  308.     if ( is_admin() ) {
  309.         // Add an option to visit the site.
  310.         $wp_admin_bar->add_menu( array(
  311.             'parent' => 'site-name',
  312.             'id'     => 'view-site',
  313.             'title'  => __( 'Visit Site' ),
  314.             'href'   => home_url( '/' ),
  315.         ) );
  316.  
  317.         if ( is_blog_admin() && is_multisite() && current_user_can( 'manage_sites' ) ) {
  318.             $wp_admin_bar->add_menu( array(
  319.                 'parent' => 'site-name',
  320.                 'id'     => 'edit-site',
  321.                 'title'  => __( 'Edit Site' ),
  322.                 'href'   => network_admin_url( 'site-info.php?id=' . get_current_blog_id() ),
  323.             ) );
  324.         }
  325.  
  326.     } else {
  327.         // We're on the front end, link to the Dashboard.
  328.         $wp_admin_bar->add_menu( array(
  329.             'parent' => 'site-name',
  330.             'id'     => 'dashboard',
  331.             'title'  => __( 'Dashboard' ),
  332.             'href'   => admin_url(),
  333.         ) );
  334.  
  335.         // Add the appearance submenu items.
  336.         wp_admin_bar_appearance_menu( $wp_admin_bar );
  337.     }
  338. }
  339.  
  340. /**
  341.  * Add the "My Sites/[Site Name]" menu and all submenus.
  342.  *
  343.  * @since 3.1.0
  344.  */
  345. function wp_admin_bar_my_sites_menu( $wp_admin_bar ) {
  346.     global $wpdb;
  347.  
  348.     // Don't show for logged out users or single site mode.
  349.     if ( ! is_user_logged_in() || ! is_multisite() )
  350.         return;
  351.  
  352.     // Show only when the user has at least one site, or they're a super admin.
  353.     if ( count( $wp_admin_bar->user->blogs ) < 1 && ! is_super_admin() )
  354.         return;
  355.  
  356.     $wp_admin_bar->add_menu( array(
  357.         'id'    => 'my-sites',
  358.         'title' => __( 'My Sites' ),
  359.         'href'  => admin_url( 'my-sites.php' ),
  360.     ) );
  361.  
  362.     if ( is_super_admin() ) {
  363.         $wp_admin_bar->add_group( array(
  364.             'parent' => 'my-sites',
  365.             'id'     => 'my-sites-super-admin',
  366.         ) );
  367.  
  368.         $wp_admin_bar->add_menu( array(
  369.             'parent' => 'my-sites-super-admin',
  370.             'id'     => 'network-admin',
  371.             'title'  => __('Network Admin'),
  372.             'href'   => network_admin_url(),
  373.         ) );
  374.  
  375.         $wp_admin_bar->add_menu( array(
  376.             'parent' => 'network-admin',
  377.             'id'     => 'network-admin-d',
  378.             'title'  => __( 'Dashboard' ),
  379.             'href'   => network_admin_url(),
  380.         ) );
  381.         $wp_admin_bar->add_menu( array(
  382.             'parent' => 'network-admin',
  383.             'id'     => 'network-admin-s',
  384.             'title'  => __( 'Sites' ),
  385.             'href'   => network_admin_url( 'sites.php' ),
  386.         ) );
  387.         $wp_admin_bar->add_menu( array(
  388.             'parent' => 'network-admin',
  389.             'id'     => 'network-admin-u',
  390.             'title'  => __( 'Users' ),
  391.             'href'   => network_admin_url( 'users.php' ),
  392.         ) );
  393.         $wp_admin_bar->add_menu( array(
  394.             'parent' => 'network-admin',
  395.             'id'     => 'network-admin-v',
  396.             'title'  => __( 'Visit Network' ),
  397.             'href'   => network_home_url(),
  398.         ) );
  399.     }
  400.  
  401.     // Add site links
  402.     $wp_admin_bar->add_group( array(
  403.         'parent' => 'my-sites',
  404.         'id'     => 'my-sites-list',
  405.         'meta'   => array(
  406.             'class' => is_super_admin() ? 'ab-sub-secondary' : '',
  407.         ),
  408.     ) );
  409.  
  410.     $blue_wp_logo_url = includes_url('images/wpmini-blue.png');
  411.  
  412.     foreach ( (array) $wp_admin_bar->user->blogs as $blog ) {
  413.         // @todo Replace with some favicon lookup.
  414.         //$blavatar = '<img src="' . esc_url( blavatar_url( blavatar_domain( $blog->siteurl ), 'img', 16, $blue_wp_logo_url ) ) . '" alt="Blavatar" width="16" height="16" />';
  415.         $blavatar = '<img src="' . esc_url($blue_wp_logo_url) . '" alt="' . esc_attr__( 'Blavatar' ) . '" width="16" height="16" class="blavatar"/>';
  416.  
  417.         $blogname = empty( $blog->blogname ) ? $blog->domain : $blog->blogname;
  418.         $menu_id  = 'blog-' . $blog->userblog_id;
  419.  
  420.         $wp_admin_bar->add_menu( array(
  421.             'parent'    => 'my-sites-list',
  422.             'id'        => $menu_id,
  423.             'title'     => $blavatar . $blogname,
  424.             'href'      => get_admin_url( $blog->userblog_id ),
  425.         ) );
  426.  
  427.         $wp_admin_bar->add_menu( array(
  428.             'parent' => $menu_id,
  429.             'id'     => $menu_id . '-d',
  430.             'title'  => __( 'Dashboard' ),
  431.             'href'   => get_admin_url( $blog->userblog_id ),
  432.         ) );
  433.  
  434.         if ( current_user_can_for_blog( $blog->userblog_id, 'edit_posts' ) ) {
  435.             $wp_admin_bar->add_menu( array(
  436.                 'parent' => $menu_id,
  437.                 'id'     => $menu_id . '-n',
  438.                 'title'  => __( 'New Post' ),
  439.                 'href'   => get_admin_url( $blog->userblog_id, 'post-new.php' ),
  440.             ) );
  441.             $wp_admin_bar->add_menu( array(
  442.                 'parent' => $menu_id,
  443.                 'id'     => $menu_id . '-c',
  444.                 'title'  => __( 'Manage Comments' ),
  445.                 'href'   => get_admin_url( $blog->userblog_id, 'edit-comments.php' ),
  446.             ) );
  447.         }
  448.  
  449.         $wp_admin_bar->add_menu( array(
  450.             'parent' => $menu_id,
  451.             'id'     => $menu_id . '-v',
  452.             'title'  => __( 'Visit Site' ),
  453.             'href'   => get_home_url( $blog->userblog_id, '/' ),
  454.         ) );
  455.     }
  456. }
  457.  
  458. /**
  459.  * Provide a shortlink.
  460.  *
  461.  * @since 3.1.0
  462.  */
  463. function wp_admin_bar_shortlink_menu( $wp_admin_bar ) {
  464.     $short = wp_get_shortlink( 0, 'query' );
  465.     $id = 'get-shortlink';
  466.  
  467.     if ( empty( $short ) )
  468.         return;
  469.  
  470.     $html = '<input class="shortlink-input" type="text" readonly="readonly" value="' . esc_attr( $short ) . '" />';
  471.  
  472.     $wp_admin_bar->add_menu( array(
  473.         'id' => $id,
  474.         'title' => __( 'Shortlink' ),
  475.         'href' => $short,
  476.         'meta' => array( 'html' => $html ),
  477.     ) );
  478. }
  479.  
  480. /**
  481.  * Provide an edit link for posts and terms.
  482.  *
  483.  * @since 3.1.0
  484.  */
  485. function wp_admin_bar_edit_menu( $wp_admin_bar ) {
  486.     global $post, $tag, $wp_the_query;
  487.  
  488.     if ( is_admin() ) {
  489.         $current_screen = get_current_screen();
  490.  
  491.         if ( 'post' == $current_screen->base
  492.             && 'add' != $current_screen->action
  493.             && ( $post_type_object = get_post_type_object( $post->post_type ) )
  494.             && current_user_can( $post_type_object->cap->read_post, $post->ID )
  495.             && ( $post_type_object->public ) )
  496.         {
  497.             $wp_admin_bar->add_menu( array(
  498.                 'id' => 'view',
  499.                 'title' => $post_type_object->labels->view_item,
  500.                 'href' => get_permalink( $post->ID )
  501.             ) );
  502.         } elseif ( 'edit-tags' == $current_screen->base
  503.             && isset( $tag ) && is_object( $tag )
  504.             && ( $tax = get_taxonomy( $tag->taxonomy ) )
  505.             && $tax->public )
  506.         {
  507.             $wp_admin_bar->add_menu( array(
  508.                 'id' => 'view',
  509.                 'title' => $tax->labels->view_item,
  510.                 'href' => get_term_link( $tag )
  511.             ) );
  512.         }
  513.     } else {
  514.         $current_object = $wp_the_query->get_queried_object();
  515.  
  516.         if ( empty( $current_object ) )
  517.             return;
  518.  
  519.         if ( ! empty( $current_object->post_type )
  520.             && ( $post_type_object = get_post_type_object( $current_object->post_type ) )
  521.             && current_user_can( $post_type_object->cap->edit_post, $current_object->ID )
  522.             && ( $post_type_object->show_ui || 'attachment' == $current_object->post_type ) )
  523.         {
  524.             $wp_admin_bar->add_menu( array(
  525.                 'id' => 'edit',
  526.                 'title' => $post_type_object->labels->edit_item,
  527.                 'href' => get_edit_post_link( $current_object->ID )
  528.             ) );
  529.         } elseif ( ! empty( $current_object->taxonomy )
  530.             && ( $tax = get_taxonomy( $current_object->taxonomy ) )
  531.             && current_user_can( $tax->cap->edit_terms )
  532.             && $tax->show_ui )
  533.         {
  534.             $wp_admin_bar->add_menu( array(
  535.                 'id' => 'edit',
  536.                 'title' => $tax->labels->edit_item,
  537.                 'href' => get_edit_term_link( $current_object->term_id, $current_object->taxonomy )
  538.             ) );
  539.         }
  540.     }
  541. }
  542.  
  543. /**
  544.  * Add "Add New" menu.
  545.  *
  546.  * @since 3.1.0
  547.  */
  548. function wp_admin_bar_new_content_menu( $wp_admin_bar ) {
  549.     $actions = array();
  550.  
  551.     $cpts = (array) get_post_types( array( 'show_in_admin_bar' => true ), 'objects' );
  552.  
  553.     if ( isset( $cpts['post'] ) && current_user_can( $cpts['post']->cap->edit_posts ) ) {
  554.         $actions[ 'post-new.php' ] = array( $cpts['post']->labels->name_admin_bar, 'new-post' );
  555.         unset( $cpts['post'] );
  556.     }
  557.  
  558.     if ( current_user_can( 'upload_files' ) )
  559.         $actions[ 'media-new.php' ] = array( _x( 'Media', 'add new from admin bar' ), 'new-media' );
  560.  
  561.     if ( current_user_can( 'manage_links' ) )
  562.         $actions[ 'link-add.php' ] = array( _x( 'Link', 'add new from admin bar' ), 'new-link' );
  563.  
  564.     if ( isset( $cpts['page'] ) && current_user_can( $cpts['page']->cap->edit_posts ) ) {
  565.         $actions[ 'post-new.php?post_type=page' ] = array( $cpts['page']->labels->name_admin_bar, 'new-page' );
  566.         unset( $cpts['page'] );
  567.     }
  568.  
  569.     // Add any additional custom post types.
  570.     foreach ( $cpts as $cpt ) {
  571.         if ( ! current_user_can( $cpt->cap->edit_posts ) )
  572.             continue;
  573.  
  574.         $key = 'post-new.php?post_type=' . $cpt->name;
  575.         $actions[ $key ] = array( $cpt->labels->name_admin_bar, 'new-' . $cpt->name );
  576.     }
  577.  
  578.     if ( current_user_can( 'create_users' ) || current_user_can( 'promote_users' ) )
  579.         $actions[ 'user-new.php' ] = array( _x( 'User', 'add new from admin bar' ), 'new-user' );
  580.  
  581.     if ( ! $actions )
  582.         return;
  583.  
  584.     $title = '<span class="ab-icon"></span><span class="ab-label">' . _x( 'New', 'admin bar menu group label' ) . '</span>';
  585.  
  586.     $wp_admin_bar->add_menu( array(
  587.         'id'    => 'new-content',
  588.         'title' => $title,
  589.         'href'  => admin_url( current( array_keys( $actions ) ) ),
  590.         'meta'  => array(
  591.             'title' => _x( 'Add New', 'admin bar menu group label' ),
  592.         ),
  593.     ) );
  594.  
  595.     foreach ( $actions as $link => $action ) {
  596.         list( $title, $id ) = $action;
  597.  
  598.         $wp_admin_bar->add_menu( array(
  599.             'parent'    => 'new-content',
  600.             'id'        => $id,
  601.             'title'     => $title,
  602.             'href'      => admin_url( $link )
  603.         ) );
  604.     }
  605. }
  606.  
  607. /**
  608.  * Add edit comments link with awaiting moderation count bubble.
  609.  *
  610.  * @since 3.1.0
  611.  */
  612. function wp_admin_bar_comments_menu( $wp_admin_bar ) {
  613.     if ( !current_user_can('edit_posts') )
  614.         return;
  615.  
  616.     $awaiting_mod = wp_count_comments();
  617.     $awaiting_mod = $awaiting_mod->moderated;
  618.     $awaiting_title = esc_attr( sprintf( _n( '%s comment awaiting moderation', '%s comments awaiting moderation', $awaiting_mod ), number_format_i18n( $awaiting_mod ) ) );
  619.  
  620.     $icon  = '<span class="ab-icon"></span>';
  621.     $title = '<span id="ab-awaiting-mod" class="ab-label awaiting-mod pending-count count-' . $awaiting_mod . '">' . number_format_i18n( $awaiting_mod ) . '</span>';
  622.  
  623.     $wp_admin_bar->add_menu( array(
  624.         'id'    => 'comments',
  625.         'title' => $icon . $title,
  626.         'href'  => admin_url('edit-comments.php'),
  627.         'meta'  => array( 'title' => $awaiting_title ),
  628.     ) );
  629. }
  630.  
  631. /**
  632.  * Add appearance submenu items to the "Site Name" menu.
  633.  *
  634.  * @since 3.1.0
  635.  */
  636. function wp_admin_bar_appearance_menu( $wp_admin_bar ) {
  637.     $wp_admin_bar->add_group( array( 'parent' => 'site-name', 'id' => 'appearance' ) );
  638.  
  639.     if ( current_user_can( 'switch_themes' ) || current_user_can( 'edit_theme_options' ) )
  640.         $wp_admin_bar->add_menu( array( 'parent' => 'appearance', 'id' => 'themes', 'title' => __('Themes'), 'href' => admin_url('themes.php') ) );
  641.  
  642.     if ( ! current_user_can( 'edit_theme_options' ) )
  643.         return;
  644.  
  645.     $current_url = ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
  646.     $wp_admin_bar->add_menu( array(
  647.         'parent' => 'appearance',
  648.         'id'     => 'customize',
  649.         'title'  => __('Customize'),
  650.         'href'   => add_query_arg( 'url', urlencode( $current_url ), wp_customize_url() ),
  651.         'meta'   => array(
  652.             'class' => 'hide-if-no-customize',
  653.         ),
  654.     ) );
  655.     add_action( 'wp_before_admin_bar_render', 'wp_customize_support_script' );
  656.  
  657.     if ( current_theme_supports( 'widgets' )  )
  658.         $wp_admin_bar->add_menu( array( 'parent' => 'appearance', 'id' => 'widgets', 'title' => __('Widgets'), 'href' => admin_url('widgets.php') ) );
  659.  
  660.      if ( current_theme_supports( 'menus' ) || current_theme_supports( 'widgets' ) )
  661.         $wp_admin_bar->add_menu( array( 'parent' => 'appearance', 'id' => 'menus', 'title' => __('Menus'), 'href' => admin_url('nav-menus.php') ) );
  662.  
  663.     if ( current_theme_supports( 'custom-background' ) )
  664.         $wp_admin_bar->add_menu( array( 'parent' => 'appearance', 'id' => 'background', 'title' => __('Background'), 'href' => admin_url('themes.php?page=custom-background') ) );
  665.  
  666.     if ( current_theme_supports( 'custom-header' ) )
  667.         $wp_admin_bar->add_menu( array( 'parent' => 'appearance', 'id' => 'header', 'title' => __('Header'), 'href' => admin_url('themes.php?page=custom-header') ) );
  668. }
  669.  
  670. /**
  671.  * Provide an update link if theme/plugin/core updates are available.
  672.  *
  673.  * @since 3.1.0
  674.  */
  675. function wp_admin_bar_updates_menu( $wp_admin_bar ) {
  676.  
  677.     $update_data = wp_get_update_data();
  678.  
  679.     if ( !$update_data['counts']['total'] )
  680.         return;
  681.  
  682.     $title = '<span class="ab-icon"></span><span class="ab-label">' . number_format_i18n( $update_data['counts']['total'] ) . '</span>';
  683.  
  684.     $wp_admin_bar->add_menu( array(
  685.         'id'    => 'updates',
  686.         'title' => $title,
  687.         'href'  => network_admin_url( 'update-core.php' ),
  688.         'meta'  => array(
  689.             'title' => $update_data['title'],
  690.         ),
  691.     ) );
  692. }
  693.  
  694. /**
  695.  * Add search form.
  696.  *
  697.  * @since 3.3.0
  698.  */
  699. function wp_admin_bar_search_menu( $wp_admin_bar ) {
  700.     if ( is_admin() )
  701.         return;
  702.  
  703.     $form  = '<form action="' . esc_url( home_url( '/' ) ) . '" method="get" id="adminbarsearch">';
  704.     $form .= '<input class="adminbar-input" name="s" id="adminbar-search" tabindex="10" type="text" value="" maxlength="150" />';
  705.     $form .= '<input type="submit" class="adminbar-button" value="' . __('Search') . '"/>';
  706.     $form .= '</form>';
  707.  
  708.     $wp_admin_bar->add_menu( array(
  709.         'parent' => 'top-secondary',
  710.         'id'     => 'search',
  711.         'title'  => $form,
  712.         'meta'   => array(
  713.             'class'    => 'admin-bar-search',
  714.             'tabindex' => -1,
  715.         )
  716.     ) );
  717. }
  718.  
  719. /**
  720.  * Add secondary menus.
  721.  *
  722.  * @since 3.3.0
  723.  */
  724. function wp_admin_bar_add_secondary_groups( $wp_admin_bar ) {
  725.     $wp_admin_bar->add_group( array(
  726.         'id'     => 'top-secondary',
  727.         'meta'   => array(
  728.             'class' => 'ab-top-secondary',
  729.         ),
  730.     ) );
  731.  
  732.     $wp_admin_bar->add_group( array(
  733.         'parent' => 'wp-logo',
  734.         'id'     => 'wp-logo-external',
  735.         'meta'   => array(
  736.             'class' => 'ab-sub-secondary',
  737.         ),
  738.     ) );
  739. }
  740.  
  741. /**
  742.  * Style and scripts for the admin bar.
  743.  *
  744.  * @since 3.1.0
  745.  *
  746.  */
  747. function wp_admin_bar_header() { ?>
  748. <style type="text/css" media="print">#wpadminbar { display:none; }</style>
  749. <?php
  750. }
  751.  
  752. /**
  753.  * Default admin bar callback.
  754.  *
  755.  * @since 3.1.0
  756.  *
  757.  */
  758. function _admin_bar_bump_cb() { ?>
  759. <style type="text/css" media="screen">
  760.     html { margin-top: 28px !important; }
  761.     * html body { margin-top: 28px !important; }
  762. </style>
  763. <?php
  764. }
  765.  
  766. /**
  767.  * Set the display status of the admin bar.
  768.  *
  769.  * This can be called immediately upon plugin load. It does not need to be called from a function hooked to the init action.
  770.  *
  771.  * @since 3.1.0
  772.  *
  773.  * @param bool $show Whether to allow the admin bar to show.
  774.  * @return void
  775.  */
  776. function show_admin_bar( $show ) {
  777.     global $show_admin_bar;
  778.     $show_admin_bar = (bool) $show;
  779. }
  780.  
  781. /**
  782.  * Determine whether the admin bar should be showing.
  783.  *
  784.  * @since 3.1.0
  785.  *
  786.  * @return bool Whether the admin bar should be showing.
  787.  */
  788. function is_admin_bar_showing() {
  789.     global $show_admin_bar, $pagenow;
  790.  
  791.     // For all these types of requests, we never want an admin bar.
  792.     if ( defined('XMLRPC_REQUEST') || defined('APP_REQUEST') || defined('DOING_AJAX') || defined('IFRAME_REQUEST') )
  793.         return false;
  794.  
  795.     // Integrated into the admin.
  796.     if ( is_admin() )
  797.         return true;
  798.  
  799.     if ( ! isset( $show_admin_bar ) ) {
  800.         if ( ! is_user_logged_in() || 'wp-login.php' == $pagenow ) {
  801.             $show_admin_bar = false;
  802.         } else {
  803.             $show_admin_bar = _get_admin_bar_pref();
  804.         }
  805.     }
  806.  
  807.     $show_admin_bar = apply_filters( 'show_admin_bar', $show_admin_bar );
  808.  
  809.     return $show_admin_bar;
  810. }
  811.  
  812. /**
  813.  * Retrieve the admin bar display preference of a user.
  814.  *
  815.  * @since 3.1.0
  816.  * @access private
  817.  *
  818.  * @param string $context Context of this preference check. Defaults to 'front'. The 'admin'
  819.  *  preference is no longer used.
  820.  * @param int $user Optional. ID of the user to check, defaults to 0 for current user.
  821.  * @return bool Whether the admin bar should be showing for this user.
  822.  */
  823. function _get_admin_bar_pref( $context = 'front', $user = 0 ) {
  824.     $pref = get_user_option( "show_admin_bar_{$context}", $user );
  825.     if ( false === $pref )
  826.         return true;
  827.  
  828.     return 'true' === $pref;
  829. }?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement