| 878 | | if (isset($wp_filter[$tag])) { |
|---|
| 879 | | foreach ($wp_filter[$tag] as $priority => $functions) { |
|---|
| 880 | | if (!is_null($functions)) { |
|---|
| 881 | | foreach($functions as $function) { |
|---|
| 882 | | $accepted_args = 1; |
|---|
| 883 | | $all_args = array_merge(array($string), $args); |
|---|
| 884 | | |
|---|
| 885 | | if (!is_array($function)) { |
|---|
| 886 | | $args_marker = strrpos($function, ':'); |
|---|
| 887 | | if ($args_marker > 0) { |
|---|
| 888 | | $accepted_args = intval(substr($function, $args_marker+1)); |
|---|
| 889 | | $function = substr($function, 0, $args_marker); |
|---|
| 890 | | } |
|---|
| 891 | | } else { |
|---|
| 892 | | $args_marker = strrpos($function[1], ':'); |
|---|
| 893 | | if ($args_marker > 0) { |
|---|
| 894 | | $accepted_args = intval(substr($function[1], $args_marker+1)); |
|---|
| 895 | | $function[1] = substr($function[1], 0, $args_marker); |
|---|
| 896 | | } |
|---|
| 897 | | } |
|---|
| 898 | | |
|---|
| 899 | | if ($accepted_args > 0) { |
|---|
| 900 | | $args = array_slice($all_args, 0, $accepted_args); |
|---|
| 901 | | } elseif($accepted_args == 0) { |
|---|
| 902 | | $args = NULL; |
|---|
| 903 | | } else { |
|---|
| 904 | | $args = $all_args; |
|---|
| 905 | | } |
|---|
| 906 | | |
|---|
| 907 | | $string = call_user_func_array($function, $args); |
|---|
| | 878 | if (!isset($wp_filter[$tag])) { |
|---|
| | 879 | return $string; |
|---|
| | 880 | } |
|---|
| | 881 | foreach ($wp_filter[$tag] as $priority => $functions) { |
|---|
| | 882 | if (!is_null($functions)) { |
|---|
| | 883 | foreach($functions as $function) { |
|---|
| | 884 | |
|---|
| | 885 | $all_args = array_merge(array($string), $args); |
|---|
| | 886 | $function_name = $function['function']; |
|---|
| | 887 | $accepted_args = $function['accepted_args']; |
|---|
| | 888 | |
|---|
| | 889 | if ($accepted_args > 0) { |
|---|
| | 890 | $args = array_slice($all_args, 0, $accepted_args); |
|---|
| | 891 | } elseif($accepted_args == 0) { |
|---|
| | 892 | $args = NULL; |
|---|
| | 893 | } else { |
|---|
| | 894 | $args = $all_args; |
|---|
| 917 | | // So the format is wp_filter['tag']['array of priorities']['array of functions'] |
|---|
| 918 | | if (!@in_array($function_to_add, $wp_filter[$tag]["$priority"])) { |
|---|
| 919 | | $wp_filter[$tag]["$priority"][] = $function_to_add; |
|---|
| | 906 | |
|---|
| | 907 | list($function, $accepted_args) = _parse_incoming_filter($function, $accepted_args); |
|---|
| | 908 | |
|---|
| | 909 | // check that we don't already have the same filter at the same priority |
|---|
| | 910 | if (isset($wp_filter[$tag]["$priority"])) { |
|---|
| | 911 | foreach($wp_filter[$tag]["$priority"] as $filter) { |
|---|
| | 912 | // uncomment if we want to match function AND accepted_args |
|---|
| | 913 | //if ($filter == array($function, $accepted_args)) { |
|---|
| | 914 | if ($filter['function'] == $function) { |
|---|
| | 915 | return true; |
|---|
| | 916 | } |
|---|
| | 917 | } |
|---|
| 926 | | if (@in_array($function_to_remove, $wp_filter[$tag]["$priority"])) { |
|---|
| 927 | | foreach ($wp_filter[$tag]["$priority"] as $function) { |
|---|
| 928 | | if ($function_to_remove != $function) { |
|---|
| | 927 | |
|---|
| | 928 | list($function, $accepted_args) = _parse_incoming_filter($function, $accepted_args); |
|---|
| | 929 | |
|---|
| | 930 | // rebuild the list of filters |
|---|
| | 931 | if (isset($wp_filter[$tag]["$priority"])) { |
|---|
| | 932 | foreach($wp_filter[$tag]["$priority"] as $filter) { |
|---|
| | 933 | if ($filter['function'] != $function) { |
|---|
| | 942 | function _parse_incoming_filter($function, $accepted_args) { |
|---|
| | 943 | // parse for the presence of :X in $function, where X is $accepted_args |
|---|
| | 944 | if (!is_array($function)) { |
|---|
| | 945 | $args_marker = strrpos($function, ':'); |
|---|
| | 946 | if ($args_marker > 0) { |
|---|
| | 947 | $accepted_args = intval(substr($function, $args_marker+1)); |
|---|
| | 948 | $function = substr($function, 0, $args_marker); |
|---|
| | 949 | } |
|---|
| | 950 | } else { |
|---|
| | 951 | $args_marker = strrpos($function[1], ':'); |
|---|
| | 952 | if ($args_marker > 0) { |
|---|
| | 953 | $accepted_args = intval(substr($function[1], $args_marker+1)); |
|---|
| | 954 | $function[1] = substr($function[1], 0, $args_marker); |
|---|
| | 955 | } |
|---|
| | 956 | } |
|---|
| | 957 | return array($function, $accepted_args); |
|---|
| | 958 | } |
|---|
| | 959 | |
|---|
| 950 | | if (isset($wp_filter[$tag])) { |
|---|
| 951 | | foreach ($wp_filter[$tag] as $priority => $functions) { |
|---|
| 952 | | if (!is_null($functions)) { |
|---|
| 953 | | foreach($functions as $function) { |
|---|
| 954 | | $string = call_user_func_array($function, $args); |
|---|
| | 972 | if (!isset($wp_filter[$tag])) { |
|---|
| | 973 | return; |
|---|
| | 974 | } |
|---|
| | 975 | foreach ($wp_filter[$tag] as $priority => $functions) { |
|---|
| | 976 | if (!is_null($functions)) { |
|---|
| | 977 | foreach($functions as $function) { |
|---|
| | 978 | |
|---|
| | 979 | $all_args = array_merge(array($string), $args); |
|---|
| | 980 | $function_name = $function['function']; |
|---|
| | 981 | $accepted_args = $function['accepted_args']; |
|---|
| | 982 | |
|---|
| | 983 | if ($accepted_args > 0) { |
|---|
| | 984 | $args = array_slice($all_args, 0, $accepted_args); |
|---|
| | 985 | } elseif($accepted_args == 0) { |
|---|
| | 986 | $args = NULL; |
|---|
| | 987 | } else { |
|---|
| | 988 | $args = $all_args; |
|---|
| 961 | | function add_action($tag, $function_to_add, $priority = 10) { |
|---|
| 962 | | add_filter($tag, $function_to_add, $priority); |
|---|
| | 997 | function add_action($tag, $function_to_add, $priority = 10, $accepted_args = 1) { |
|---|
| | 998 | add_filter($tag, $function_to_add, $priority, $accepted_args); |
|---|
| 965 | | function remove_action($tag, $function_to_remove, $priority = 10) { |
|---|
| 966 | | remove_filter($tag, $function_to_remove, $priority); |
|---|
| | 1001 | function remove_action($tag, $function_to_remove, $priority = 10, $accepted_args = 1) { |
|---|
| | 1002 | remove_filter($tag, $function_to_remove, $priority, $accepted_args); |
|---|