Skip to content

Conversation

@Mayank-Tripathi32
Copy link
Contributor

What?

Closes #70559

This PR enhances the WordPress Block Editor's Command Palette by adding dynamic "Add New" commands for custom post types (CPTs). Users can now quickly create new custom post types directly from the Command Palette, similar to how they can add new posts and pages.

Why?

Currently, the Command Palette only provides "Add new post" and "Add new page" commands. Users with custom post types need to navigate through the admin menu to create new content, which is inefficient. This enhancement improves the user experience by providing quick access to create any custom post type directly from the Command Palette.

How?

The implementation:

  • Uses getPostTypes() to fetch all available post types and dynamically generates commands for user-created custom post types
  • Excludes system post types (post, page, attachment, etc.) and only includes viewable custom post types
  • Converts dashicon strings (e.g., dashicons-book) to proper React components using the Dashicon component
  • Follows the same patterns as existing "Add new post/page" commands

Testing Instructions

Custom Post Type Testing:

  • Create a custom post type (e.g., "Books") with a custom icon
  • Open the Command Palette
  • Search for "Add new Book"
  • Verify the command appears with the correct icon and label
  • Test the command to ensure it navigates to post-new.php?post_type=books

Edge Cases:

  • Test with custom post types that have no icon set
  • Test with custom post types that use non-dashicon icons
  • Verify system post types (post, page, attachment, etc.) do not appear in the list

Testing Instructions for Keyboard

  • Open the Command Palette using Ctrl/Cmd + K
  • Use arrow keys to navigate through the command list
  • Type "Add new" to filter commands
  • Use Tab/Shift+Tab to navigate between commands
  • Press Enter to execute a command
  • Verify that the selected command properly navigates to the new post page
  • Test with screen readers to ensure proper accessibility

Screenshots

Before

image

After

image

@github-actions
Copy link

github-actions bot commented Jul 15, 2025

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: Mayank-Tripathi32 <[email protected]>
Co-authored-by: t-hamano <[email protected]>
Co-authored-by: jasmussen <[email protected]>
Co-authored-by: himanshupathak95 <[email protected]>
Co-authored-by: karmatosed <[email protected]>
Co-authored-by: nikunj8866 <[email protected]>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@t-hamano t-hamano added [Type] Enhancement A suggestion for improvement. [Package] Core commands labels Jul 16, 2025
@Mayank-Tripathi32
Copy link
Contributor Author

@t-hamano Would you mind checking this out when available? I want to get this merged and move forward with other open issue in #70624 (which adds up more functionality into search)

Copy link
Contributor

@t-hamano t-hamano left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR!

The key point I think is to not use Dashicons, as it has been proposed to deprecate Dashicon strings: #43725

In other words, I believe we should accept that all post types render plus SVG icons for now as follows:

Image

cc @WordPress/gutenberg-design


// Filter to only include user-created custom post types
// Exclude system post types and core WordPress post types
const systemPostTypes = GLOBAL_SYSTEM_POST_TYPES;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need to consider so many post types?
I think the code below is sufficient:

const excludedPostTypes = [ 'post', 'page', 'attachment' ];

See:

const excludedPostTypes = [ 'attachment' ];

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

got it, I will check it out.

@jasmussen
Copy link
Contributor

I'd agree to avoid dashicons, and if need be fall back to the plus pending another icon being provided by the cpt.

@t-hamano
Copy link
Contributor

t-hamano commented Sep 5, 2025

Hi @Mayank-Tripathi32, we decided to register menu commands based on the Menu API and implemented them in #71476. As a result, the custom CPT's commands are already registered now:

image

I'd like to close this PR, but thank you for your work!

@t-hamano t-hamano closed this Sep 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Enhancement: Add "Add New Post/Page" link to Block Editor header for easier navigation.

3 participants