add_filter multiple times with different addon functions?

Hi @Scott B:

Absolutely. That’s part of the design of the system, you can add as many as you need (other plugins do.)

The only issue is if you might need to address which one runs first and that’s when you may have to set the priority. In the below example the third one would run first and the second one would run last:

add_filter('wp_insert_post_data','norm_priority_func'); // 10=default priority 
add_filter('wp_insert_post_data','run_last_funcn', 11 );  
add_filter('wp_insert_post_data','run_first_func', 9 );  

Of course when you have needs to set priorities you can find it may cause conflict with other plugins that set a priority higher or lower. Typical places where this happens is when you want a hook to run either before or after all others. Are 0 and 100 sufficient priorities? Not if another plugin used -1 and 101; see the quandry? Anyway, that’s usually not an issue but when it is, it is.

Leave a Comment