Introduce name_admin_bar label and the show_in_admin_bar (Add New menu) argument for post types. Allows for proper translations of these strings and provides for consolidated logic. fixes #16406.
git-svn-id: http://svn.automattic.com/wordpress/trunk@18261 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
d648585363
commit
2d54db5d7c
|
@ -238,11 +238,11 @@ function wp_admin_bar_edit_menu( $wp_admin_bar ) {
|
|||
*/
|
||||
function wp_admin_bar_new_content_menu( $wp_admin_bar ) {
|
||||
$actions = array();
|
||||
foreach ( (array) get_post_types( array( 'show_ui' => true ), 'objects' ) as $ptype_obj ) {
|
||||
if ( true !== $ptype_obj->show_in_menu || ! current_user_can( $ptype_obj->cap->edit_posts ) )
|
||||
foreach ( (array) get_post_types( array( 'show_in_admin_bar' => true ), 'objects' ) as $ptype_obj ) {
|
||||
if ( ! current_user_can( $ptype_obj->cap->edit_posts ) )
|
||||
continue;
|
||||
|
||||
$actions[ 'post-new.php?post_type=' . $ptype_obj->name ] = array( $ptype_obj->labels->singular_name, $ptype_obj->cap->edit_posts, 'new-' . $ptype_obj->name );
|
||||
$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 );
|
||||
}
|
||||
|
||||
if ( current_user_can( 'upload_files' ) )
|
||||
|
|
|
@ -18,6 +18,9 @@
|
|||
*/
|
||||
function create_initial_post_types() {
|
||||
register_post_type( 'post', array(
|
||||
'labels' => array(
|
||||
'name_admin_bar' => _x( 'Post', 'add new on admin bar' ),
|
||||
),
|
||||
'public' => true,
|
||||
'_builtin' => true, /* internal use only. don't use this when registering your own post type. */
|
||||
'_edit_link' => 'post.php?post=%d', /* internal use only. don't use this when registering your own post type. */
|
||||
|
@ -30,6 +33,9 @@ function create_initial_post_types() {
|
|||
) );
|
||||
|
||||
register_post_type( 'page', array(
|
||||
'labels' => array(
|
||||
'name_admin_bar' => _x( 'Page', 'add new on admin bar' ),
|
||||
),
|
||||
'public' => true,
|
||||
'publicly_queryable' => false,
|
||||
'_builtin' => true, /* internal use only. don't use this when registering your own post type. */
|
||||
|
@ -915,7 +921,8 @@ function register_post_type($post_type, $args = array()) {
|
|||
'public' => false, 'rewrite' => true, 'has_archive' => false, 'query_var' => true,
|
||||
'supports' => array(), 'register_meta_box_cb' => null,
|
||||
'taxonomies' => array(), 'show_ui' => null, 'menu_position' => null, 'menu_icon' => null,
|
||||
'permalink_epmask' => EP_PERMALINK, 'can_export' => true, 'show_in_nav_menus' => null, 'show_in_menu' => null,
|
||||
'permalink_epmask' => EP_PERMALINK, 'can_export' => true,
|
||||
'show_in_nav_menus' => null, 'show_in_menu' => null, 'show_in_admin_bar' => null,
|
||||
);
|
||||
$args = wp_parse_args($args, $defaults);
|
||||
$args = (object) $args;
|
||||
|
@ -938,6 +945,10 @@ function register_post_type($post_type, $args = array()) {
|
|||
if ( null === $args->show_in_menu || ! $args->show_ui )
|
||||
$args->show_in_menu = $args->show_ui;
|
||||
|
||||
// If not set, default to the whether the full UI is shown.
|
||||
if ( null === $args->show_in_admin_bar )
|
||||
$args->show_in_admin_bar = true === $args->show_in_menu;
|
||||
|
||||
// Whether to show this type in nav-menus.php. Defaults to the setting for public.
|
||||
if ( null === $args->show_in_nav_menus )
|
||||
$args->show_in_nav_menus = $args->public;
|
||||
|
@ -1194,6 +1205,9 @@ function _get_custom_object_labels( $object, $nohier_vs_hier_defaults ) {
|
|||
if ( !isset( $object->labels['singular_name'] ) && isset( $object->labels['name'] ) )
|
||||
$object->labels['singular_name'] = $object->labels['name'];
|
||||
|
||||
if ( ! isset( $object->labels['name_admin_bar'] ) )
|
||||
$object->labels['name_admin_bar'] = isset( $object->labels['singular_name'] ) ? $object->labels['singular_name'] : $object->name;
|
||||
|
||||
if ( !isset( $object->labels['menu_name'] ) && isset( $object->labels['name'] ) )
|
||||
$object->labels['menu_name'] = $object->labels['name'];
|
||||
|
||||
|
|
Loading…
Reference in New Issue