Make WordPress Core

Opened 4 months ago

Closed 7 weeks ago

Last modified 7 weeks ago

#60881 closed enhancement (fixed)

Introduce 'template_name' label to custom post types and custom taxonomies

Reported by: aljullu's profile aljullu Owned by: peterwilsoncc's profile peterwilsoncc
Milestone: 6.6 Priority: normal
Severity: normal Version: 6.1
Component: Editor Keywords: has-patch commit gutenberg-merge dev-reviewed
Focuses: Cc:

Description

Currently, there is no way to add user-friendly names to block templates generated automatically from custom post types and custom taxonomies.

This ticket is about introducing a new label: 'template_name', which could be used to label templates in the Site Editor instead of the currently used single_name.

See https://github.com/WordPress/gutenberg/issues/60283 for more context.

Change History (17)

This ticket was mentioned in PR #6344 on WordPress/wordpress-develop by @aljullu.


4 months ago
#1

  • Keywords has-patch added

This PR is a follow-up of https://github.com/WordPress/gutenberg/pull/60367 to:

  1. Document the template_name label when registering post types and taxonomies.
  2. Add a default value.

## Testing steps

  1. Add this code snippet to your site. You can use the Code Snippets plugin:

{{{PHP
add_action( 'init', function () {

register_post_type(

'recipe',
array(

'labels' => array(

'name' => 'Recipes',
'singular_name' => 'Recipe',

),
'public' => true,
'show_in_rest' => true,

)

);
register_taxonomy(

'recipe_cat',
'recipe',
array(

'label' => 'Categories',
'labels' => array(

'name' => 'Recipe categories',
'singular_name' => 'Category',

),
'show_in_rest' => true,

)

);

} );
}}}

  1. Go to Appearance > Editor > Templates > Add new and verify there are no regressions in the Add template screen: two items related to the code snippet should appear there: _Single item: Recipe_ and _Category (recipe_cat)_.

https://github.com/WordPress/gutenberg/assets/3616980/c76df58d-2d87-4097-9e41-b2ec90a32c09

  1. Install Gutenberg and checkout this branch: https://github.com/WordPress/gutenberg/pull/60367.
  2. Repeat step 2 and verify there are no regressions.
  3. Now, modify the code snippet you created before, adding template_name to the post type and taxonomy:
add_action( 'init', function () {
        register_post_type(
                'recipe',
                array(
                        'labels'       => array(
                                'name'          => 'Recipes',
                                'singular_name' => 'Recipe',
+                               'template_name' => 'Single recipe',
                        ),
                        'public'       => true,
                        'show_in_rest' => true,
                )
        );
        register_taxonomy(
                'recipe_cat',
                'recipe',
                array(
                        'label'        => 'Categories',
                        'labels'       => array(
                                'name'          => 'Recipe categories',
                                'singular_name' => 'Category',
+                               'template_name' => 'Recipes by category',
                        ),
                        'show_in_rest' => true,
                )
        );
} );
  1. Repeat step 2 and verify the user-friendly template labels are shown:

https://github.com/WordPress/gutenberg/assets/3616980/57e675fc-7cf0-4c5c-9ad1-8afa9ef1302b

Trac ticket: https://core.trac.wordpress.org/ticket/60881

@ntsekouras commented on PR #6344:


2 months ago
#2

Thanks for the PR! Can you create a trac ticket for this and link this PR?

@aljullu commented on PR #6344:


2 months ago
#3

Can you create a trac ticket for this and link this PR?

Thanks for taking a look, @ntsekouras! The track ticket was already created: https://core.trac.wordpress.org/ticket/60881. It's linked from the PR description. :slightly_smiling_face:

@aljullu commented on PR #6344:


2 months ago
#4

Thanks for the review, @audrasjb! I rebased this PR with the latest trunk but I don't have permissions to merge. I also see some checks were cancelled or skipped, is that expected?

@aljullu commented on PR #6344:


2 months ago
#5

Thanks for the review, @peterwilsoncc! I updated the PR based on your feedback. If the custom post type and the custom taxonomies don't include a template_name, _Single item: [singular name]_ and _[singular name] Archives_ will be used instead:

https://github.com/WordPress/wordpress-develop/assets/3616980/d9e2afe5-24ec-4a01-8ab3-05ba87b13068

@aljullu commented on PR #6344:


2 months ago
#6

Thanks again for the review, @peterwilsoncc, feedback should be addressed.

At the moment the archive is always shown as Archive: [CPT] but if WP is to allow for Single item: [CPT] to be customized it seems inconsistent not to allow the archive to be renamed too.

You mean adding a archive_template_name label or something along these lines? AFAIK it hasn't been discussed, as I didn't think about this case. I'm happy to add it, but I would lean towards doing that in a separate PR to keep the scope of this one smaller, if that sounds good.

@aljullu commented on PR #6344:


8 weeks ago
#7

Once again, thanks for the review, @peterwilsoncc! I don't have merge/commit access to the WordPress repo, so please let me know if there is anything else I can do from my end. :pray:

#8 @peterwilsoncc
8 weeks ago

@aljullu @ellatrix Will gutenberg#60367 be included in WordPress 6.6? If so, I'll add this to the milestone and commit it during the week.

#9 @aljullu
7 weeks ago

Will gutenberg#60367 be included in WordPress 6.6? If so, I'll add this to the milestone and commit it during the week.

I will let @ellatrix confirm, but AFAIK yes. gutenberg#60367 is included in Gutenberg 18.5, which will be included in WordPress 6.6.

#10 @ellatrix
7 weeks ago

Yes, it's in GB 18.5.

#11 @peterwilsoncc
7 weeks ago

  • Keywords commit added
  • Milestone changed from Awaiting Review to 6.6

THe linked pull request has been approved and gutenberg#60367 will be in 6.6 so making this for commit and moving to the milestone.

#12 @oglekler
7 weeks ago

  • Keywords gutenberg-merge added

#13 @rajinsharwar
7 weeks ago

I have tested the Patch: PR-6344

I found:-

  1. Setting the template_name displays the string in the add new template screen. ✅ https://prnt.sc/B4slbn9qVW_1 https://prnt.sc/KH0p7q4NUHGm
  1. Setting labels without the template name displays the singular name ✅ https://prnt.sc/HyZBtizHYWVp https://prnt.sc/VEtgEDJ2_08t
  1. Setting neither $label nor $labels display the object slug to differentiate. ✅ https://prnt.sc/fy0tmRaR0FNP https://prnt.sc/dPR_Dfln9AZt
  1. Setting singular $label without $labels displays the $label in the default string. ✅ https://prnt.sc/Cd_7U7a6PcEH https://prnt.sc/KLbtRNfZYDD0

Looks good with the tests and changes. 👍

#14 @audrasjb
7 weeks ago

  • Owner set to peterwilsoncc
  • Status changed from new to assigned

Hi there,

While 6.6 is officially closed for new enhancements, I believe we can make an exception for this one. Assigning the ticket to @peterwilsoncc who proposed to commit it.

#15 @audrasjb
7 weeks ago

  • Keywords dev-reviewed added

#16 @peterwilsoncc
7 weeks ago

  • Resolution set to fixed
  • Status changed from assigned to closed

In 58377:

Editor: Add labels for template name display in site editor.

Add the label template_name to post types and taxonomies for use by the site editor to display on the templates/add new template screens to allow extenders to customize the display.

For post types the template name applies to templates for a singular pages with the default value "Single item: [singular name]".

For taxonomies the template name applies to templates for term archives with the default value "[singular name] Archives".

Props aljullu, audrasjb, ntsekouras, ellatrix, oglekler, rajinsharwar.
Fixes #60881.

Note: See TracTickets for help on using tickets.