Make WordPress Core


Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/3.1/wp-includes/admin-bar.php

    r18261 r17509  
    7676 * @since 3.1.0
    7777 */
    78 function wp_admin_bar_my_account_menu( $wp_admin_bar ) {
    79     global $user_identity;
     78function wp_admin_bar_my_account_menu() {
     79    global $wp_admin_bar, $user_identity;
    8080
    8181    $user_id = get_current_user_id();
     
    9090        /* Add the "My Account" sub menus */
    9191        $wp_admin_bar->add_menu( array( 'parent' => $id, 'title' => __( 'Edit My Profile' ), 'href' => get_edit_profile_url( $user_id ) ) );
     92        if ( is_multisite() )
     93            $wp_admin_bar->add_menu( array( 'parent' => $id, 'title' => __( 'Dashboard' ), 'href' => get_dashboard_url( $user_id ) ) );
     94        else
     95            $wp_admin_bar->add_menu( array( 'parent' => $id, 'title' => __( 'Dashboard' ), 'href' => admin_url() ) );
    9296        $wp_admin_bar->add_menu( array( 'parent' => $id, 'title' => __( 'Log Out' ), 'href' => wp_logout_url() ) );
    9397    }
     
    9599
    96100/**
    97  * Add the "Dashboard"/"Visit Site" menu.
    98  *
    99  * @since 3.2.0
    100  */
    101 function wp_admin_bar_dashboard_view_site_menu( $wp_admin_bar ) {
    102     $user_id = get_current_user_id();
    103 
    104     if ( 0 != $user_id ) {
    105         if ( is_admin() )
    106             $wp_admin_bar->add_menu( array( 'title' => __( 'Visit Site' ), 'href' => home_url() ) );
    107         elseif ( is_multisite() )
    108             $wp_admin_bar->add_menu( array( 'title' => __( 'Dashboard' ), 'href' => get_dashboard_url( $user_id ) ) );
    109         else
    110             $wp_admin_bar->add_menu( array( 'title' => __( 'Dashboard' ), 'href' => admin_url() ) );
    111     }
    112 }
    113 
    114 /**
    115101 * Add the "My Sites/[Site Name]" menu and all submenus.
    116102 *
    117103 * @since 3.1.0
    118104 */
    119 function wp_admin_bar_my_sites_menu( $wp_admin_bar ) {
    120     global $wpdb;
     105function wp_admin_bar_my_sites_menu() {
     106    global $wpdb, $wp_admin_bar;
    121107
    122108    /* Add the 'My Sites' menu if the user has more than one site. */
     
    152138 * @since 3.1.0
    153139 */
    154 function wp_admin_bar_shortlink_menu( $wp_admin_bar ) {
     140function wp_admin_bar_shortlink_menu() {
     141    global $wp_admin_bar;
     142
    155143    $short = wp_get_shortlink( 0, 'query' );
    156144    $id = 'get-shortlink';
     
    174162 * @since 3.1.0
    175163 */
    176 function wp_admin_bar_edit_menu( $wp_admin_bar ) {
    177     global $post, $tag;
    178 
    179     if ( is_admin() ) {
    180         $current_screen = get_current_screen();
    181 
    182         if ( 'post' == $current_screen->base
    183             && 'add' != $current_screen->action
    184             && ( $post_type_object = get_post_type_object( $post->post_type ) )
    185             && current_user_can( $post_type_object->cap->read_post, $post->ID )
    186             && ( $post_type_object->public ) )
    187         {
    188             $wp_admin_bar->add_menu( array(
    189                 'id' => 'view',
    190                 'title' => $post_type_object->labels->view_item,
    191                 'href' => get_permalink( $post->ID )
    192             ) );
    193         } elseif ( 'edit-tags' == $current_screen->base
    194             && isset( $tag ) && is_object( $tag )
    195             && ( $tax = get_taxonomy( $tag->taxonomy ) )
    196             && $tax->public )
    197         {
    198             $wp_admin_bar->add_menu( array(
    199                 'id' => 'view',
    200                 'title' => $tax->labels->view_item,
    201                 'href' => get_term_link( $tag )
    202             ) );
    203         }
    204     } else {
    205         $current_object = get_queried_object();
    206 
    207         if ( empty($current_object) )
    208             return;
    209 
    210         if ( ! empty( $current_object->post_type )
    211             && ( $post_type_object = get_post_type_object( $current_object->post_type ) )
    212             && current_user_can( $post_type_object->cap->edit_post, $current_object->ID )
    213             && ( $post_type_object->show_ui || 'attachment' == $current_object->post_type ) )
    214         {
    215             $wp_admin_bar->add_menu( array(
    216                 'id' => 'edit',
    217                 'title' => $post_type_object->labels->edit_item,
    218                 'href' => get_edit_post_link( $current_object->ID )
    219             ) );
    220         } elseif ( ! empty( $current_object->taxonomy )
    221             && ( $tax = get_taxonomy( $current_object->taxonomy ) )
    222             && current_user_can( $tax->cap->edit_terms )
    223             && $tax->show_ui )
    224         {
    225             $wp_admin_bar->add_menu( array(
    226                 'id' => 'edit',
    227                 'title' => $tax->labels->edit_item,
    228                 'href' => get_edit_term_link( $current_object->term_id, $current_object->taxonomy )
    229             ) );
    230         }
     164function wp_admin_bar_edit_menu () {
     165    global $wp_admin_bar;
     166
     167    $current_object = get_queried_object();
     168
     169    if ( empty($current_object) )
     170        return;
     171
     172    if ( ! empty( $current_object->post_type ) && ( $post_type_object = get_post_type_object( $current_object->post_type ) ) && current_user_can( $post_type_object->cap->edit_post, $current_object->ID ) && $post_type_object->show_ui ) {
     173        $wp_admin_bar->add_menu( array( 'id' => 'edit', 'title' => $post_type_object->labels->edit_item,  'href' => get_edit_post_link( $current_object->ID ) ) );
     174    } elseif ( ! empty( $current_object->taxonomy ) &&  ( $tax = get_taxonomy( $current_object->taxonomy ) ) && current_user_can( $tax->cap->edit_terms ) && $tax->show_ui ) {
     175        $wp_admin_bar->add_menu( array( 'id' => 'edit', 'title' => $tax->labels->edit_item, 'href' => get_edit_term_link( $current_object->term_id, $current_object->taxonomy ) ) );
    231176    }
    232177}
     
    237182 * @since 3.1.0
    238183 */
    239 function wp_admin_bar_new_content_menu( $wp_admin_bar ) {
     184function wp_admin_bar_new_content_menu() {
     185    global $wp_admin_bar;
     186
    240187    $actions = array();
    241     foreach ( (array) get_post_types( array( 'show_in_admin_bar' => true ), 'objects' ) as $ptype_obj ) {
    242         if ( ! current_user_can( $ptype_obj->cap->edit_posts ) )
     188    foreach ( (array) get_post_types( array( 'show_ui' => true ), 'objects' ) as $ptype_obj ) {
     189        if ( true !== $ptype_obj->show_in_menu || ! current_user_can( $ptype_obj->cap->edit_posts ) )
    243190            continue;
    244191
    245         $actions[ 'post-new.php?post_type=' . $ptype_obj->name ] = array( $ptype_obj->labels->name_admin_bar, $ptype_obj->cap->edit_posts, 'new-' . $ptype_obj->name );
    246     }
    247 
    248     if ( current_user_can( 'upload_files' ) )
    249         $actions[ 'media-new.php' ] = array( _x( 'Media', 'add new from admin bar' ), 'upload_files', 'new-media' );
    250 
    251     if ( current_user_can( 'manage_links' ) )
    252         $actions[ 'link-add.php' ] = array( _x( 'Link', 'add new from admin bar' ), 'manage_links', 'new-link' );
    253 
    254     if ( current_user_can( 'create_users' ) || current_user_can( 'promote_users' ) )
    255         $actions[ 'user-new.php' ] = array( _x( 'User', 'add new from admin bar' ), 'create_users', 'new-user' );
    256 
    257     if ( ! is_multisite() && current_user_can( 'install_themes' ) )
    258         $actions[ 'theme-install.php' ] = array( _x( 'Theme', 'add new from admin bar' ), 'install_themes', 'new-theme' );
    259 
    260     if ( ! is_multisite() && current_user_can( 'install_plugins' ) )
    261         $actions[ 'plugin-install.php' ] = array( _x( 'Plugin', 'add new from admin bar' ), 'install_plugins', 'new-plugin' );
     192        $actions[ 'post-new.php?post_type=' . $ptype_obj->name ] = array( $ptype_obj->labels->singular_name, $ptype_obj->cap->edit_posts, 'new-' . $ptype_obj->name );
     193    }
    262194
    263195    if ( empty( $actions ) )
     
    276208 * @since 3.1.0
    277209 */
    278 function wp_admin_bar_comments_menu( $wp_admin_bar ) {
     210function wp_admin_bar_comments_menu() {
     211    global $wp_admin_bar;
     212
    279213    if ( !current_user_can('edit_posts') )
    280214        return;
     
    292226 * @since 3.1.0
    293227 */
    294 function wp_admin_bar_appearance_menu( $wp_admin_bar ) {
    295     // You can have edit_theme_options but not switch_themes.
    296     if ( ! current_user_can('switch_themes') && ! current_user_can( 'edit_theme_options' ) )
     228function wp_admin_bar_appearance_menu() {
     229    global $wp_admin_bar;
     230
     231    if ( !current_user_can('switch_themes') )
    297232        return;
    298233
    299234    $wp_admin_bar->add_menu( array( 'id' => 'appearance', 'title' => __('Appearance'), 'href' => admin_url('themes.php') ) );
    300235
    301     if ( ! current_user_can( 'edit_theme_options' ) )
    302         return;
    303 
    304     if ( current_user_can( 'switch_themes' ) )
    305         $wp_admin_bar->add_menu( array( 'parent' => 'appearance', 'id' => 'themes', 'title' => __('Themes'), 'href' => admin_url('themes.php') ) );
     236    if ( !current_user_can('edit_theme_options') )
     237        return;
    306238
    307239    if ( current_theme_supports( 'widgets' )  )
     
    310242     if ( current_theme_supports( 'menus' ) || current_theme_supports( 'widgets' ) )
    311243        $wp_admin_bar->add_menu( array( 'parent' => 'appearance', 'id' => 'menus', 'title' => __('Menus'), 'href' => admin_url('nav-menus.php') ) );
    312 
    313     if ( current_theme_supports( 'custom-background' ) )
    314         $wp_admin_bar->add_menu( array( 'parent' => 'appearance', 'id' => 'background', 'title' => __('Background'), 'href' => admin_url('themes.php?page=custom-background') ) );
    315 
    316     if ( current_theme_supports( 'custom-header' ) )
    317         $wp_admin_bar->add_menu( array( 'parent' => 'appearance', 'id' => 'header', 'title' => __('Header'), 'href' => admin_url('themes.php?page=custom-header') ) );
    318244}
    319245
     
    323249 * @since 3.1.0
    324250 */
    325 function wp_admin_bar_updates_menu( $wp_admin_bar ) {
     251function wp_admin_bar_updates_menu() {
     252    global $wp_admin_bar;
     253
    326254    if ( !current_user_can('install_plugins') )
    327255        return;
     
    351279        $update_title[] = sprintf(_n('%d Plugin Update', '%d Plugin Updates', $plugin_update_count), $plugin_update_count);
    352280    if ( $theme_update_count )
    353         $update_title[] = sprintf(_n('%d Theme Update', '%d Theme Updates', $theme_update_count), $theme_update_count);
     281        $update_title[] = sprintf(_n('%d Theme Update', '%d Themes Updates', $theme_update_count), $theme_update_count);
    354282
    355283    $update_title = !empty($update_title) ? esc_attr(implode(', ', $update_title)) : '';
     
    380308 */
    381309function _admin_bar_bump_cb() { ?>
    382 <style type="text/css" media="screen">
     310<style type="text/css">
    383311    html { margin-top: 28px !important; }
    384312    * html body { margin-top: 28px !important; }
     
    388316
    389317/**
    390  * Set the display status of the admin bar.
     318 * Set the display status of the admin bar
    391319 *
    392320 * This can be called immediately upon plugin load.  It does not need to be called from a function hooked to the init action.
     
    436364 * @access private
    437365 *
    438  * @param string $context Context of this preference check, either 'admin' or 'front'.
    439  * @param int $user Optional. ID of the user to check, defaults to 0 for current user.
    440  * @return bool Whether the admin bar should be showing for this user.
     366 * @param string $context Context of this preference check, either 'admin' or 'front'
     367 * @param int $user Optional. ID of the user to check, defaults to 0 for current user
     368 * @return bool Whether the admin bar should be showing for this user
    441369 */
    442370function _get_admin_bar_pref( $context, $user = 0 ) {
Note: See TracChangeset for help on using the changeset viewer.