Skip to content

Commit 844f0bd

Browse files
Copilotswissspidy
andcommitted
Refine documentation and remove redundant validation
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
1 parent 81e5e72 commit 844f0bd

1 file changed

Lines changed: 5 additions & 8 deletions

File tree

‎src/Shell_Command.php‎

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ class Shell_Command extends WP_CLI_Command {
2020
* PsySH PHP REPLs are available.
2121
*
2222
* [--hook=<hook>]
23-
* : Attach the shell to a specific WordPress action or filter hook.
23+
* : Ensure that a specific WordPress action hook has fired before starting the shell.
24+
* This validates that the preconditions associated with that hook are met.
25+
* Only hooks that have already been triggered can be used (e.g., init, plugins_loaded, wp_loaded).
2426
* ---
2527
* default: ''
2628
* ---
@@ -32,18 +34,13 @@ class Shell_Command extends WP_CLI_Command {
3234
* wp> get_bloginfo( 'name' );
3335
* => string(6) "WP-CLI"
3436
*
35-
* # Start a shell after the 'init' action has fired.
37+
* # Start a shell, ensuring the 'init' hook has already fired.
3638
* $ wp shell --hook=init
3739
*/
3840
public function __invoke( $_, $assoc_args ) {
3941
$hook = Utils\get_flag_value( $assoc_args, 'hook', '' );
4042

4143
if ( $hook ) {
42-
// Validate hook parameter.
43-
if ( ! is_string( $hook ) || '' === trim( $hook ) ) {
44-
WP_CLI::error( 'The --hook parameter must be a non-empty string.' );
45-
}
46-
4744
// Check if the hook has already fired.
4845
if ( did_action( $hook ) ) {
4946
// Hook already fired, start the shell immediately.
@@ -52,7 +49,7 @@ public function __invoke( $_, $assoc_args ) {
5249
// Hook hasn't fired yet.
5350
WP_CLI::error(
5451
sprintf(
55-
"The '%s' hook has not fired yet. The shell command runs after WordPress is loaded, so only hooks that have already been triggered can be used. Common hooks that are available include: init, plugins_loaded, wp_loaded, admin_init.",
52+
"The '%s' hook has not fired yet. The shell command runs after WordPress is loaded, so only hooks that have already been triggered can be used. Common hooks that are available include: init, plugins_loaded, wp_loaded.",
5653
$hook
5754
)
5855
);

0 commit comments

Comments
 (0)