WordPress.org

Make WordPress Core

Changeset 16132


Ignore:
Timestamp:
11/01/10 14:58:59 (3 years ago)
Author:
ryan
Message:

Use CPTs in admin bar menus. Props duck_. see #14772

File:
1 edited

Legend:

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

    r16114 r16132  
    181181        return; 
    182182 
    183     // @todo Use proper type name in edit strings 
    184183    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 ) ) { 
    185         $wp_admin_bar->add_menu( array( 'id' => 'edit', 'title' => __( 'Edit Post' ),  'href' => get_edit_post_link( $current_object->ID ), ) ); 
     184        $wp_admin_bar->add_menu( array( 'id' => 'edit', 'title' => $post_type_object->labels->edit_item,  'href' => get_edit_post_link( $current_object->ID ), ) ); 
    186185    } elseif ( ! empty( $current_object->taxonomy ) &&  ( $tax = get_taxonomy( $current_object->taxonomy ) ) && current_user_can( $tax->cap->edit_terms ) ) { 
    187         $wp_admin_bar->add_menu( array( 'id' => 'edit', 'title' => __( 'Edit Post' ), 'href' => get_edit_term_link( $current_object->term_id, $current_object->taxonomy ), ) ); 
     186        $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 ), ) ); 
    188187    } 
    189188} 
     
    192191    global $wp_admin_bar; 
    193192 
    194     // @todo Handle CPTs, use post type object for strings 
    195     $actions = array( 
    196         'post-new.php' => array(__('Post'), 'edit_posts', 'new-post'), 
    197         'post-new.php?post_type=page' => array(__('Page'), 'edit_pages', 'new-page'), 
    198     ); 
    199  
    200     $user_can = false; 
    201     foreach ( $actions as $action ) { 
    202         if ( current_user_can($action[1]) ) { 
    203             $user_can = true; 
    204             break; 
    205         } 
    206     } 
    207  
    208     if ( !$user_can ) 
     193    $actions = array(); 
     194    foreach ( (array) get_post_types( array('show_ui' => true, 'show_in_menu' => true) ) as $ptype ) { 
     195        $ptype_obj = get_post_type_object( $ptype ); 
     196        if ( $ptype_obj->show_in_menu !== true || ! current_user_can( $ptype_obj->cap->edit_posts ) ) 
     197            continue; 
     198             
     199        $actions["post-new.php?post_type=$ptype"] = array( $ptype_obj->labels->singular_name, $ptype_obj->cap->edit_posts, "new-$ptype" ); 
     200    } 
     201 
     202    if ( empty( $actions ) ) 
    209203        return; 
    210204 
Note: See TracChangeset for help on using the changeset viewer.