Make WordPress Core

Opened 10 months ago

Last modified 9 months ago

#58887 new enhancement

Add a Pattern menu item to the "+ New" menu in the WP admin toolbar

Reported by: poena's profile poena Owned by:
Milestone: Future Release Priority: normal
Severity: normal Version:
Component: Toolbar Keywords: has-patch has-testing-info has-screenshots 2nd-opinion
Focuses: Cc:

Description

The WP admin toolbar has a menu with the text "New" and a dropdown with
links to adding a new post, media, page and user.

Consider adding a link to the patterns creation interface to this menu.
The new menu item should only be visible for users with the correct permissions.

Attachments (4)

toolbar-new.2.png (35.3 KB) - added by poena 10 months ago.
The current menu in the WP admin toolbar
58887.diff (556 bytes) - added by khokansardar 10 months ago.
Patch added. Thanks.
new-pattern-link-classic-editor.png (19.9 KB) - added by sabernhardt 9 months ago.
Pattern link appears even when Classic Editor disables blocks for all users
58887.1.diff (1.4 KB) - added by khokansardar 9 months ago.
I have updated the patch. Please check.

Download all attachments as: .zip

Change History (20)

@poena
10 months ago

The current menu in the WP admin toolbar

#1 @audrasjb
10 months ago

  • Milestone changed from Awaiting Review to 6.4
  • Version trunk deleted

Moving for 6.4 consideration.

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


10 months ago
#2

  • Keywords has-patch added

Trac ticket: #58887

@khokansardar
10 months ago

Patch added. Thanks.

#3 @huzaifaalmesbah
10 months ago

After Applying the Patch. It looks good. Thanks @khokansardar for the patch.

Result
https://i.ibb.co/z8ySrZH/Screenshot-2023-08-13-at-2-39-23-PM.png

@sabernhardt
9 months ago

Pattern link appears even when Classic Editor disables blocks for all users

#4 @sabernhardt
9 months ago

Thanks for the patch! This Pattern link is available for Authors and Editors but not Contributors or Subscribers (requires publish_posts capability). However, I think it still needs to have a condition.

The link appears even when using the Disable Gutenberg plugin or when disabling blocks for all users with the Classic Editor plugin. New patterns usually would not be appropriate without the block editor (unless a JS error renders the editor unusable and a pattern needs correcting before the editor can be fixed). A conditional statement could check whether the block editor is in use and/or whether a pattern exists already.

Last edited 9 months ago by sabernhardt (previous) (diff)

@khokansardar
9 months ago

I have updated the patch. Please check.

#5 @khokansardar
9 months ago

  • Keywords needs-testing added

@sabernhardt yes you are right, we need to check conditional statement also. So, I have updated the patch. Now it should work with all condition. Thanks.

#7 @Ankit K Gupta
9 months ago

Test Report

Patch tested: https://core.trac.wordpress.org/attachment/ticket/58887/58887.1.diff

Env

  • WordPress - 6.4-alpha-20230817.203813
  • Web Server: Nginx
  • Chrome Version - 115
  • OS - macOS
  • Theme: Twenty Twenty-Three
  • PHP - 7.4.0
  • Active Plugin - Tested with/without "Disable Gutenberg"

Test result

The test focused on assessing the availability and functionality of the 'Pattern' option in the Nav Bar under various scenarios. The results indicate the following:

  1. With the 'Disable Gutenberg' plugin active and the Block Editor disabled site-wide, the Pattern option correctly does not appear in the Nav Bar. ✅
  1. When the Block Editor is active, the Pattern option is appropriately displayed in the Nav Bar. ✅
  1. Clicking on 'Pattern' under the "+ New" tab successfully reveals the Pattern Tab. ✅
  1. Clicking on 'Pattern' leads to the expected redirection to the create Pattern Screen. ✅
  1. The Pattern option is appropriately available to users with the 'publish_posts' capability. ✅

✅ Suggested Enhancement works with patch.

After the patch-

https://i.imgur.com/6Qm9uX4.jpg

Please note that I have examined all possible scenarios based on my understanding. If there are any additional scenarios that need to be confirmed or checked, please do let me know. Thank you!

#8 @Ankit K Gupta
9 months ago

  • Keywords has-testing-info has-screenshots added; needs-testing removed

#9 @poena
9 months ago

Pinging @richtabor @jameskoster @joen in case you have any input about adding admin toolbar shortcut to the pattern creation screen.

Also, I am not sure core should be making changes to support the classic editor plugin. Should it not be up to the plugin to remove the menu items it does not support? The block editor is the default.

#10 @sabernhardt
9 months ago

I do not like tacking on another item that those plugins would need to remove, but adding something like the following code to a plugin is probably easier than the removal of some stylesheets or the duotone SVGs has been for them.

function wptrac_remove_toolbar_pattern_link_node( $wp_admin_bar ) {
	$wp_admin_bar->remove_node( 'new-wp_block' );
}
function wptrac_revise_new_content_menu() {
	add_action( 'admin_bar_menu', 'wptrac_remove_toolbar_pattern_link_node', 70 );
}
add_action( 'add_admin_bar_menus', 'wptrac_revise_new_content_menu' );

Then the first patch might be fine.

Last edited 9 months ago by sabernhardt (previous) (diff)

#11 @Joen
9 months ago

Thanks for the ping! I'm not sure the use case for this; when I create a new post, the action is clearly benefitting from an empty canvas, however a new pattern I nearly always create first in the block editor and then save as a pattern after the fact. In that light, I'd be reluctant to adding this, honestly.

#12 @poena
9 months ago

If you already know what kind of pattern you need, it is not intuitive or fast to create a new post or page, add the blocks, select the "create pattern" toolbar option, complete the options, and then trash the page.

#13 @Joen
9 months ago

That would just be the in-the-flow bonus way to do it, though. The main way to create a pattern is to go into the site editor, into Patterns, then click the "add new" button. To that end it still makes sense to me to have just that, the site editor, as the central destination linked from the toolbar, and otherwise keep it lean. To me it's about balancing how often you do each of those actions; new post or new page you'd presumably do very often, whereas new patterns I would think a rarity. Having it in that dropdown would — not by a lot, mind you — but still add just that nanosecond of extra thinking, "which button do I click", and even afford you a mis-click.

#14 @poena
9 months ago

On many sites, creating patterns will be more frequently used than adding a new user.
Not all sites have the Site Editor enabled either.

#15 @poena
9 months ago

  • Keywords 2nd-opinion added

#16 @poena
9 months ago

  • Milestone changed from 6.4 to Future Release
Note: See TracTickets for help on using tickets.