Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to add commands to the command palette #164

Closed
bph opened this issue Sep 7, 2023 Discussed in #157 · 11 comments
Closed

How to add commands to the command palette #164

bph opened this issue Sep 7, 2023 Discussed in #157 · 11 comments

Comments

@bph
Copy link
Collaborator

bph commented Sep 7, 2023

Discussed in #157

Originally posted by richtabor August 14, 2023
We have this resource here, but it's highly technical (as it should be).

I think having a guide with a few types of commands would be nice. Like a command to toggle on a block editor preference, go to an external help guide article, open a plugin sidebar, etc. Even commands to open up internal admin pages; like a host adding a command to view hosting config, or builders adding a command to open another plugin's admin page, etc.

Not only to show how, but give ideas on what folks can add commands for. Inspire a bit.

It doesn't have to be complex, perhaps simple like how we write about block style variations.

What's the easiest way for existing plugins to add commands to the command palette?

@justintadlock
Copy link

I'm going to pick this one up.

@bph
Copy link
Collaborator Author

bph commented Nov 8, 2023

Thank you @justintadlock for stepping up to the plate! 👏

@justintadlock
Copy link

justintadlock commented Nov 13, 2023

I think, at least for now, I'm going to stick with the basics as outlined by @richtabor in the topic proposal with registercommand/useCommand. I thought about diving more deeply with dynamic commands, but I think an intro to add some basic commands would be a great start because there is currently no easy, plug-and-play documentation for this at all (the linked Dev Note doesn't really teach much and will break just plugging it in).

If we want to follow this up with a more advanced tutorial, we can always do a part 2.

@justintadlock
Copy link

Test repo here: https://github.com/justintadlock/dev-blog-command-palette-api

@bph bph moved this from To-do to In Progress in Developer Blog Content Board Nov 14, 2023
@justintadlock
Copy link

@justintadlock justintadlock moved this from In Progress to Needs 1st review in Developer Blog Content Board Nov 15, 2023
@justintadlock
Copy link

@bph
Copy link
Collaborator Author

bph commented Nov 17, 2023

@justintadlock It's a great introduction to the Commands API! Thank you! I test all examples. Apart from the missing build step, everything was working as 'advertised' :-) See my comment in the Google Doc.

@justintadlock justintadlock moved this from Needs 1st review to Ready to publish in Developer Blog Content Board Nov 20, 2023
@justintadlock
Copy link

Published!

Social Copy:

Have you ever wanted to add custom commands to the WordPress Command Palette? Get started with this tutorial on the Developer Blog:

https://developer.wordpress.org/news/2023/11/getting-started-with-the-command-palette-api/

@justintadlock justintadlock moved this from Ready to publish to Published (Done) in Developer Blog Content Board Nov 20, 2023
@bph
Copy link
Collaborator Author

bph commented Nov 22, 2023

Didn't test this before, but I just opened the site editor with the command palette plugin activated and ran into an error:
Screenshot 2023-11-22 at 11 07 26

The code in question:

			return select( 'core/edit-post' ).isEditorPanelEnabled( 
				'discussion-panel' 
			);```

@justintadlock
Copy link

Ah, it looks like that's an issue on the Site Editor when accessing that via the hook. I didn't think to test it there since the normal action function works.

Anyway, it's corrected in the post with a check for undefined !== wp.editPost since it's only run on the post editor.

@ndiego
Copy link
Member

ndiego commented Jan 29, 2024

Social post scheduled.

@bph bph removed the flow: needs writer the idea/pitch needs a writer label Jan 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Published (Done)
Development

No branches or pull requests

3 participants