WordPress: 函數 add_action與add_filter的區別

180

add_filter 程式碼

1
2
3
4
5
6
7
8
9
function add_filter($tag, $function_to_add, $priority = 10, $accepted_args = 1) 
{ global $wp_filter, $merged_filters; $idx = _wp_filter_build_unique_id($tag, $function_to_add, $priority); $wp_filter[$tag][$priority][$idx] = array('function' => $function_to_add, 'accepted_args' => $accepted_args); unset( $merged_filters[ $tag ] ); return true; }

add_action 程式碼

1
2
3
4
5
function add_action($tag, $function_to_add, $priority = 10, $accepted_args = 1) 
{ return add_filter($tag, $function_to_add, $priority, $accepted_args); }

所以結論是無區別