-
Notifications
You must be signed in to change notification settings - Fork 994
Improve command suggestions for taxonomies and post types #6059
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
Improve command suggestions for taxonomies and post types #6059
Conversation
Codecov ReportAttention: Patch coverage is
📢 Thoughts on this report? Let us know! |
Thanks for your PR! I left some early feedback that should help enhance this further. As you can see, some tests are currently failing otherwise. Speaking of, this would definitely benefit from some tests soo. Would you be up for adding some? Perhaps in |
php/WP_CLI/Runner.php
Outdated
|
||
// Suggest appropriate commands for taxonomy or post type. | ||
if ( $this->is_taxonomy( $cmd_path[0] ) ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need the extra methods, we can just use taxonomy_exists()
and post_type_exists()
provided by WordPress.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @swissspidy for the feedback. Im on it and when updated the method as you have mentioned I am always getting a fatal error of undefined function.
if ( taxonomy_exists( $cmd_path[0] ) ) {
return sprintf( "Did you mean 'wp term %s %s'?", $cmd_path[0], isset( $sub_path ) ? $sub_path : 'list' );
} elseif ( post_type_exists( $cmd_path[0] ) ) {
return sprintf( "Did you mean 'wp post <command> --post_type=%s'?", $cmd_path[0] );
}
Please advice. Here is the video
REC-20250305190645.mp4
Also please provide some simple steps to fix the Test Errors.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using \taxonomy_exists()
could solve it, may be?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@swissspidy - Any ideas for the above mentioned error in the video when using taxonomy_exists ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll take a thorough look at the PR shortly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So turns out load_wordpress()
ends up calling find_command_to_run()
again, hence the function not existing.
But because WP-CLI already tries to load WordPress anyway if it's detected, I realized the extra call isn't really needed.
So I now simplified the code a little bit and it should be good to go.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks @swissspidy you are really helpful to learn the contribution easily. Love it.
@swissspidy - Thanks for the updated changes. I understand it now. |
Fixes #5624
Summary
This PR improves user experience by suggesting appropriate WP-CLI commands when a user attempts to run wp or wp <post_type>, which do not exist. Instead of failing with an error, WP-CLI will now provide a helpful "Did you mean" message.
Changes
wp term <command> <taxonomy> for taxonomies.
wp post <command> --post_type=<post_type> for post types.
Testing Instructions
wp category list
(or any taxonomy name instead of category).wp product create
(where product is a post type).wp term
orwp post
command to ensure existing functionality remains unaffected.This PR enhances usability by helping users discover the correct WP-CLI commands efficiently.
Video
REC-20250304201920.mp4