Administration: Switch core post type labels to add_new_item.

In [56515], the default value of `Add New` was changed to "Add New Post / Add New Page". This caused problems with post types where `add_new` was not declared.

Change core usage to reference the `add_new_item` value and revert the default value of `add_new` back to "Add New / Add New". This retains the accessibility advantages without creating counter intuitive usage of the `add_new` key.

With this change, post types registered with no `add_new` key will be unimpacted in core, and post types registered with no `add_new_item` key will use the default "Add New Post", which is not a change from the current state.

Props smerriman, afercia, rcreators, joedolson, eclev91, johnbillion.
Fixes #60045.
Built from https://develop.svn.wordpress.org/trunk@59161


git-svn-id: http://core.svn.wordpress.org/trunk@58556 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
joedolson 2024-10-03 22:46:15 +00:00
parent 9fd5f24d73
commit 3de3fb8c83
6 changed files with 8 additions and 6 deletions

View File

@ -434,7 +434,7 @@ echo esc_html( $title );
<?php <?php
if ( isset( $post_new_file ) && current_user_can( $post_type_object->cap->create_posts ) ) { if ( isset( $post_new_file ) && current_user_can( $post_type_object->cap->create_posts ) ) {
echo ' <a href="' . esc_url( admin_url( $post_new_file ) ) . '" class="page-title-action">' . esc_html( $post_type_object->labels->add_new ) . '</a>'; echo ' <a href="' . esc_url( admin_url( $post_new_file ) ) . '" class="page-title-action">' . esc_html( $post_type_object->labels->add_new_item ) . '</a>';
} }
?> ?>

View File

@ -419,7 +419,7 @@ echo esc_html( $post_type_object->labels->name );
<?php <?php
if ( current_user_can( $post_type_object->cap->create_posts ) ) { if ( current_user_can( $post_type_object->cap->create_posts ) ) {
echo ' <a href="' . esc_url( admin_url( $post_new_file ) ) . '" class="page-title-action">' . esc_html( $post_type_object->labels->add_new ) . '</a>'; echo ' <a href="' . esc_url( admin_url( $post_new_file ) ) . '" class="page-title-action">' . esc_html( $post_type_object->labels->add_new_item ) . '</a>';
} }
if ( isset( $_REQUEST['s'] ) && strlen( $_REQUEST['s'] ) ) { if ( isset( $_REQUEST['s'] ) && strlen( $_REQUEST['s'] ) ) {

View File

@ -169,7 +169,7 @@ foreach ( array_merge( $builtin, $types ) as $ptype ) {
$menu[ $ptype_menu_position ] = array( esc_attr( $ptype_obj->labels->menu_name ), $ptype_obj->cap->edit_posts, $ptype_file, '', $menu_class, $ptype_menu_id, $menu_icon ); $menu[ $ptype_menu_position ] = array( esc_attr( $ptype_obj->labels->menu_name ), $ptype_obj->cap->edit_posts, $ptype_file, '', $menu_class, $ptype_menu_id, $menu_icon );
$submenu[ $ptype_file ][5] = array( $ptype_obj->labels->all_items, $ptype_obj->cap->edit_posts, $ptype_file ); $submenu[ $ptype_file ][5] = array( $ptype_obj->labels->all_items, $ptype_obj->cap->edit_posts, $ptype_file );
$submenu[ $ptype_file ][10] = array( $ptype_obj->labels->add_new, $ptype_obj->cap->create_posts, $post_new_file ); $submenu[ $ptype_file ][10] = array( $ptype_obj->labels->add_new_item, $ptype_obj->cap->create_posts, $post_new_file );
$i = 15; $i = 15;
foreach ( get_taxonomies( array(), 'objects' ) as $tax ) { foreach ( get_taxonomies( array(), 'objects' ) as $tax ) {

View File

@ -973,7 +973,7 @@ final class WP_Post_Type {
self::$default_labels = array( self::$default_labels = array(
'name' => array( _x( 'Posts', 'post type general name' ), _x( 'Pages', 'post type general name' ) ), 'name' => array( _x( 'Posts', 'post type general name' ), _x( 'Pages', 'post type general name' ) ),
'singular_name' => array( _x( 'Post', 'post type singular name' ), _x( 'Page', 'post type singular name' ) ), 'singular_name' => array( _x( 'Post', 'post type singular name' ), _x( 'Page', 'post type singular name' ) ),
'add_new' => array( __( 'Add New Post' ), __( 'Add New Page' ) ), 'add_new' => array( __( 'Add New' ), __( 'Add New' ) ),
'add_new_item' => array( __( 'Add New Post' ), __( 'Add New Page' ) ), 'add_new_item' => array( __( 'Add New Post' ), __( 'Add New Page' ) ),
'edit_item' => array( __( 'Edit Post' ), __( 'Edit Page' ) ), 'edit_item' => array( __( 'Edit Post' ), __( 'Edit Page' ) ),
'new_item' => array( __( 'New Post' ), __( 'New Page' ) ), 'new_item' => array( __( 'New Post' ), __( 'New Page' ) ),

View File

@ -2022,7 +2022,7 @@ function _post_type_meta_capabilities( $capabilities = null ) {
* - `name` - General name for the post type, usually plural. The same and overridden * - `name` - General name for the post type, usually plural. The same and overridden
* by `$post_type_object->label`. Default is 'Posts' / 'Pages'. * by `$post_type_object->label`. Default is 'Posts' / 'Pages'.
* - `singular_name` - Name for one object of this post type. Default is 'Post' / 'Page'. * - `singular_name` - Name for one object of this post type. Default is 'Post' / 'Page'.
* - `add_new` - Label for adding a new item. Default is 'Add New Post' / 'Add New Page'. * - `add_new` - Label for adding a new item. Default is 'Add New' / 'Add New'.
* - `add_new_item` - Label for adding a new singular item. Default is 'Add New Post' / 'Add New Page'. * - `add_new_item` - Label for adding a new singular item. Default is 'Add New Post' / 'Add New Page'.
* - `edit_item` - Label for editing a singular item. Default is 'Edit Post' / 'Edit Page'. * - `edit_item` - Label for editing a singular item. Default is 'Edit Post' / 'Edit Page'.
* - `new_item` - Label for the new item page title. Default is 'New Post' / 'New Page'. * - `new_item` - Label for the new item page title. Default is 'New Post' / 'New Page'.
@ -2084,6 +2084,8 @@ function _post_type_meta_capabilities( $capabilities = null ) {
* @since 6.4.0 Changed default values for the `add_new` label to include the type of content. * @since 6.4.0 Changed default values for the `add_new` label to include the type of content.
* This matches `add_new_item` and provides more context for better accessibility. * This matches `add_new_item` and provides more context for better accessibility.
* @since 6.6.0 Added the `template_name` label. * @since 6.6.0 Added the `template_name` label.
* @since 6.7.0 Restored pre-6.4.0 defaults for the `add_new` label and updated documentation.
* Updated core usage to reference `add_new_item`.
* *
* @access private * @access private
* *

View File

@ -16,7 +16,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '6.7-beta1-59160'; $wp_version = '6.7-beta1-59161';
/** /**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.