Skip to content

Commit fb6a9ed

Browse files
Copilotswissspidy
andcommitted
Add caching and priority sorting to get_hook_actions
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
1 parent 1641517 commit fb6a9ed

1 file changed

Lines changed: 15 additions & 3 deletions

File tree

src/Cron_Event_Command.php

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -625,10 +625,17 @@ private function get_formatter( &$assoc_args ) {
625625
* @return string A comma-separated list of action callbacks, or 'None' if no actions are registered.
626626
*/
627627
protected static function get_hook_actions( $hook_name ) {
628+
static $cache = array();
629+
630+
if ( isset( $cache[ $hook_name ] ) ) {
631+
return $cache[ $hook_name ];
632+
}
633+
628634
global $wp_filter;
629635

630636
if ( ! isset( $wp_filter[ $hook_name ] ) ) {
631-
return 'None';
637+
$cache[ $hook_name ] = 'None';
638+
return $cache[ $hook_name ];
632639
}
633640

634641
$hook = $wp_filter[ $hook_name ];
@@ -642,9 +649,12 @@ protected static function get_hook_actions( $hook_name ) {
642649
}
643650

644651
if ( empty( $callbacks ) ) {
645-
return 'None';
652+
$cache[ $hook_name ] = 'None';
653+
return $cache[ $hook_name ];
646654
}
647655

656+
ksort( $callbacks );
657+
648658
$actions = array();
649659

650660
// Iterate through all priorities
@@ -658,7 +668,9 @@ protected static function get_hook_actions( $hook_name ) {
658668
}
659669
}
660670

661-
return implode( ', ', $actions );
671+
$result = empty( $actions ) ? 'None' : implode( ', ', $actions );
672+
$cache[ $hook_name ] = $result;
673+
return $cache[ $hook_name ];
662674
}
663675

664676
/**

0 commit comments

Comments
 (0)