Use CPTs in admin bar menus. Props duck_. see #14772
git-svn-id: http://svn.automattic.com/wordpress/trunk@16132 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
f00861d35f
commit
629eb4397d
|
@ -180,32 +180,26 @@ function wp_admin_bar_edit_menu () {
|
||||||
if ( empty($current_object) )
|
if ( empty($current_object) )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// @todo Use proper type name in edit strings
|
|
||||||
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 ) ) {
|
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 ) ) {
|
||||||
$wp_admin_bar->add_menu( array( 'id' => 'edit', 'title' => __( 'Edit Post' ), 'href' => get_edit_post_link( $current_object->ID ), ) );
|
$wp_admin_bar->add_menu( array( 'id' => 'edit', 'title' => $post_type_object->labels->edit_item, 'href' => get_edit_post_link( $current_object->ID ), ) );
|
||||||
} elseif ( ! empty( $current_object->taxonomy ) && ( $tax = get_taxonomy( $current_object->taxonomy ) ) && current_user_can( $tax->cap->edit_terms ) ) {
|
} elseif ( ! empty( $current_object->taxonomy ) && ( $tax = get_taxonomy( $current_object->taxonomy ) ) && current_user_can( $tax->cap->edit_terms ) ) {
|
||||||
$wp_admin_bar->add_menu( array( 'id' => 'edit', 'title' => __( 'Edit Post' ), 'href' => get_edit_term_link( $current_object->term_id, $current_object->taxonomy ), ) );
|
$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 ), ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function wp_admin_bar_new_content_menu() {
|
function wp_admin_bar_new_content_menu() {
|
||||||
global $wp_admin_bar;
|
global $wp_admin_bar;
|
||||||
|
|
||||||
// @todo Handle CPTs, use post type object for strings
|
$actions = array();
|
||||||
$actions = array(
|
foreach ( (array) get_post_types( array('show_ui' => true, 'show_in_menu' => true) ) as $ptype ) {
|
||||||
'post-new.php' => array(__('Post'), 'edit_posts', 'new-post'),
|
$ptype_obj = get_post_type_object( $ptype );
|
||||||
'post-new.php?post_type=page' => array(__('Page'), 'edit_pages', 'new-page'),
|
if ( $ptype_obj->show_in_menu !== true || ! current_user_can( $ptype_obj->cap->edit_posts ) )
|
||||||
);
|
continue;
|
||||||
|
|
||||||
$user_can = false;
|
$actions["post-new.php?post_type=$ptype"] = array( $ptype_obj->labels->singular_name, $ptype_obj->cap->edit_posts, "new-$ptype" );
|
||||||
foreach ( $actions as $action ) {
|
|
||||||
if ( current_user_can($action[1]) ) {
|
|
||||||
$user_can = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !$user_can )
|
if ( empty( $actions ) )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
$wp_admin_bar->add_menu( array( 'id' => 'new-content', 'title' => __( 'New Content' ), 'href' => '', ) );
|
$wp_admin_bar->add_menu( array( 'id' => 'new-content', 'title' => __( 'New Content' ), 'href' => '', ) );
|
||||||
|
|
Loading…
Reference in New Issue