Improve do_action performance. Make an associative array. Props koopersmith. fixes #10561
git-svn-id: https://develop.svn.wordpress.org/trunk@12464 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
0487cf7225
commit
8b7f26b62c
@ -299,10 +299,13 @@ function add_action($tag, $function_to_add, $priority = 10, $accepted_args = 1)
|
|||||||
function do_action($tag, $arg = '') {
|
function do_action($tag, $arg = '') {
|
||||||
global $wp_filter, $wp_actions, $merged_filters, $wp_current_filter;
|
global $wp_filter, $wp_actions, $merged_filters, $wp_current_filter;
|
||||||
|
|
||||||
if ( is_array($wp_actions) )
|
if ( ! isset($wp_actions) )
|
||||||
$wp_actions[] = $tag;
|
$wp_actions = array();
|
||||||
|
|
||||||
|
if ( ! isset($wp_actions[$tag]) )
|
||||||
|
$wp_actions[$tag] = 1;
|
||||||
else
|
else
|
||||||
$wp_actions = array($tag);
|
++$wp_actions[$tag];
|
||||||
|
|
||||||
$wp_current_filter[] = $tag;
|
$wp_current_filter[] = $tag;
|
||||||
|
|
||||||
@ -357,10 +360,10 @@ function do_action($tag, $arg = '') {
|
|||||||
function did_action($tag) {
|
function did_action($tag) {
|
||||||
global $wp_actions;
|
global $wp_actions;
|
||||||
|
|
||||||
if ( empty($wp_actions) )
|
if ( ! isset( $wp_actions ) || ! isset( $wp_actions[$tag] ) )
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
return count(array_keys($wp_actions, $tag));
|
return $wp_actions[$tag];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -382,10 +385,13 @@ function did_action($tag) {
|
|||||||
function do_action_ref_array($tag, $args) {
|
function do_action_ref_array($tag, $args) {
|
||||||
global $wp_filter, $wp_actions, $merged_filters, $wp_current_filter;
|
global $wp_filter, $wp_actions, $merged_filters, $wp_current_filter;
|
||||||
|
|
||||||
if ( !is_array($wp_actions) )
|
if ( ! isset($wp_actions) )
|
||||||
$wp_actions = array($tag);
|
$wp_actions = array();
|
||||||
|
|
||||||
|
if ( ! isset($wp_actions[$tag]) )
|
||||||
|
$wp_actions[$tag] = 1;
|
||||||
else
|
else
|
||||||
$wp_actions[] = $tag;
|
++$wp_actions[$tag];
|
||||||
|
|
||||||
$wp_current_filter[] = $tag;
|
$wp_current_filter[] = $tag;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user