Skip to content

Commit 7fc996a

Browse files
authored
Include hook details in documentation (#501)
When a command specifies a non-default hook, include those details in handbook documentation for the command. Related: wp-cli/wp-cli#5921 Fixes: wp-cli/wp-cli#5838
1 parent ba887c8 commit 7fc996a

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

‎bin/command.php‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,16 @@ private static function gen_cmd_pages( $cmd, $parent = [], $verbose = false ) {
399399
}
400400
$binding['has-subcommands'] = isset( $cmd['subcommands'] ) ? [ true ] : false;
401401

402+
$hook_name = $cmd['hook'];
403+
$hook_description = $hook_name ? Utils\get_hook_description( $hook_name ) : null;
404+
if ( $hook_description && 'after_wp_load' !== $hook_name ) {
405+
if ( $binding['has-subcommands'] ) {
406+
$binding['description'] .= "\n\nUnless overridden, these commands run on the `$hook_name` hook, $hook_description";
407+
} else {
408+
$binding['description'] .= "\n\nThis command runs on the `$hook_name` hook, $hook_description";
409+
}
410+
}
411+
402412
if ( $cmd['longdesc'] ) {
403413
$docs = $cmd['longdesc'];
404414
$docs = htmlspecialchars( $docs, ENT_COMPAT, 'UTF-8' );

0 commit comments

Comments
 (0)