Make WordPress Core

Ticket #14772: 14772.CPT-new-content.diff

File 14772.CPT-new-content.diff, 2.3 KB (added by duck_, 15 years ago)
  • wp-includes/admin-bar.php

     
    180180        if ( empty($current_object) )
    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}
    190189
    191190function wp_admin_bar_new_content_menu() {
    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                 }
     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" );
    206200        }
    207201
    208         if ( !$user_can )
     202        if ( empty( $actions ) )
    209203                return;
    210204
    211205        $wp_admin_bar->add_menu( array( 'id' => 'new-content', 'title' => __( 'New Content' ), 'href' => '', ) );