Make WordPress Core


Ignore:
File:
1 edited

Legend:

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

    r17509 r18261  
    7676 * @since 3.1.0
    7777 */
    78 function wp_admin_bar_my_account_menu() {
    79     global $wp_admin_bar, $user_identity;
     78function wp_admin_bar_my_account_menu( $wp_admin_bar ) {
     79    global $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 ) ) );
     92        $wp_admin_bar->add_menu( array( 'parent' => $id, 'title' => __( 'Log Out' ), 'href' => wp_logout_url() ) );
     93    }
     94}
     95
     96/**
     97 * Add the "Dashboard"/"Visit Site" menu.
     98 *
     99 * @since 3.2.0
     100 */
     101function 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 ) ) );
    94109        else
    95             $wp_admin_bar->add_menu( array( 'parent' => $id, 'title' => __( 'Dashboard' ), 'href' => admin_url() ) );
    96         $wp_admin_bar->add_menu( array( 'parent' => $id, 'title' => __( 'Log Out' ), 'href' => wp_logout_url() ) );
     110            $wp_admin_bar->add_menu( array( 'title' => __( 'Dashboard' ), 'href' => admin_url() ) );
    97111    }
    98112}
     
    103117 * @since 3.1.0
    104118 */
    105 function wp_admin_bar_my_sites_menu() {
    106     global $wpdb, $wp_admin_bar;
     119function wp_admin_bar_my_sites_menu( $wp_admin_bar ) {
     120    global $wpdb;
    107121
    108122    /* Add the 'My Sites' menu if the user has more than one site. */
     
    138152 * @since 3.1.0
    139153 */
    140 function wp_admin_bar_shortlink_menu() {
    141     global $wp_admin_bar;
    142 
     154function wp_admin_bar_shortlink_menu( $wp_admin_bar ) {
    143155    $short = wp_get_shortlink( 0, 'query' );
    144156    $id = 'get-shortlink';
     
    162174 * @since 3.1.0
    163175 */
    164 function 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 ) ) );
     176function 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        }
    176231    }
    177232}
     
    182237 * @since 3.1.0
    183238 */
    184 function wp_admin_bar_new_content_menu() {
    185     global $wp_admin_bar;
    186 
     239function wp_admin_bar_new_content_menu( $wp_admin_bar ) {
    187240    $actions = array();
    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 ) )
     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 ) )
    190243            continue;
    191244
    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     }
     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' );
    194262
    195263    if ( empty( $actions ) )
     
    208276 * @since 3.1.0
    209277 */
    210 function wp_admin_bar_comments_menu() {
    211     global $wp_admin_bar;
    212 
     278function wp_admin_bar_comments_menu( $wp_admin_bar ) {
    213279    if ( !current_user_can('edit_posts') )
    214280        return;
     
    226292 * @since 3.1.0
    227293 */
    228 function wp_admin_bar_appearance_menu() {
    229     global $wp_admin_bar;
    230 
    231     if ( !current_user_can('switch_themes') )
     294function 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' ) )
    232297        return;
    233298
    234299    $wp_admin_bar->add_menu( array( 'id' => 'appearance', 'title' => __('Appearance'), 'href' => admin_url('themes.php') ) );
    235300
    236     if ( !current_user_can('edit_theme_options') )
    237         return;
     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') ) );
    238306
    239307    if ( current_theme_supports( 'widgets' )  )
     
    242310     if ( current_theme_supports( 'menus' ) || current_theme_supports( 'widgets' ) )
    243311        $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') ) );
    244318}
    245319
     
    249323 * @since 3.1.0
    250324 */
    251 function wp_admin_bar_updates_menu() {
    252     global $wp_admin_bar;
    253 
     325function wp_admin_bar_updates_menu( $wp_admin_bar ) {
    254326    if ( !current_user_can('install_plugins') )
    255327        return;
     
    279351        $update_title[] = sprintf(_n('%d Plugin Update', '%d Plugin Updates', $plugin_update_count), $plugin_update_count);
    280352    if ( $theme_update_count )
    281         $update_title[] = sprintf(_n('%d Theme Update', '%d Themes Updates', $theme_update_count), $theme_update_count);
     353        $update_title[] = sprintf(_n('%d Theme Update', '%d Theme Updates', $theme_update_count), $theme_update_count);
    282354
    283355    $update_title = !empty($update_title) ? esc_attr(implode(', ', $update_title)) : '';
     
    308380 */
    309381function _admin_bar_bump_cb() { ?>
    310 <style type="text/css">
     382<style type="text/css" media="screen">
    311383    html { margin-top: 28px !important; }
    312384    * html body { margin-top: 28px !important; }
     
    316388
    317389/**
    318  * Set the display status of the admin bar
     390 * Set the display status of the admin bar.
    319391 *
    320392 * This can be called immediately upon plugin load.  It does not need to be called from a function hooked to the init action.
     
    364436 * @access private
    365437 *
    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
     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.
    369441 */
    370442function _get_admin_bar_pref( $context, $user = 0 ) {
Note: See TracChangeset for help on using the changeset viewer.