Skip to content

Instantly share code, notes, and snippets.

@stracker-phil
Created April 1, 2019 21:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stracker-phil/16170175f10a40129c2b01dd86d5fcef to your computer and use it in GitHub Desktop.
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.
<?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