Introduce wp db users command for user management#303
Conversation
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
This comment was marked as resolved.
This comment was marked as resolved.
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
…utput.txt Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
This comment was marked as resolved.
This comment was marked as resolved.
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
This comment was marked as resolved.
This comment was marked as resolved.
There was a problem hiding this comment.
Code Review
This pull request introduces a new wp db users create command for managing MySQL users, which is a valuable addition to WP-CLI's database management capabilities. The implementation is well-structured, extending the existing DB_Command and reusing its functionality where appropriate. Security has been carefully considered, with proper SQL escaping for user-provided identifiers and passwords. The new command is also well-tested with Behat scenarios covering various use cases. My review includes a couple of minor suggestions to improve code clarity by removing redundant PHPDoc comments. Overall, this is a high-quality contribution.
| /** @var string $username_escaped */ | ||
| /** @var string $host_escaped */ |
There was a problem hiding this comment.
These @var annotations are redundant. The self::esc_sql_ident() method's PHPDoc already specifies that it returns a string when a string is passed as an argument. Modern static analysis tools can infer the types of $username_escaped and $host_escaped correctly without these comments. Removing them will make the code cleaner.
Implementation Plan
Summary
Implemented
wp db users createcommand that allows database administrators to easily create MySQL user accounts with optional privileges on the WordPress database. The implementation extendsDB_Commandfor consistency, follows WP-CLI patterns, and includes comprehensive tests. Latest changes remove assert() calls and improve SQL string escaping to follow MySQL's documented string literal escaping rules, handling special characters like null bytes, newlines, carriage returns, quotes, and control characters.Original prompt
wp db users#138💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.