Created
April 1, 2019 21:32
-
-
Save stracker-phil/16170175f10a40129c2b01dd86d5fcef to your computer and use it in GitHub Desktop.
Determine the name and priority of the currently called action/filter callback in WordPress.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Output the current action name and priority. | |
*/ | |
function pst_action_and_priority() { | |
global $wp_filter, $wp_current_filter; | |
// Find the currently running WP action/filter name. | |
$action = end( $wp_current_filter ); | |
// Get the corresponding WP_Hook object of that filter. | |
$filter = $wp_filter[ $action ]; | |
// Determine the priority of the current filter callback. | |
$prio = $filter->current_priority(); | |
echo "Action $action [Prio $prio]\n"; | |
} | |
add_action( 'login_init', 'pst_action_and_priority' ); | |
add_action( 'login_form', 'pst_action_and_priority' ); | |
add_action( 'login_form', 'pst_action_and_priority', 1 ); | |
add_action( 'login_form', 'pst_action_and_priority', 100 ); | |
/* | |
Output: | |
Action login_init [Prio 10] | |
Action login_form [Prio 1] | |
Action login_form [Prio 10] | |
Action login_form [Prio 100] | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment