add_filter multiple times with different addon functions?

I’m adding this filter when the condition is true. Can I add another function on the same filter when the 2nd condition is true or will the last one cancel out the previous one?

if(get_option('my_nofollow_flag'){
    add_filter('wp_insert_post_data', 'save_add_nofollow' );
}

if(get_option('my_second_option'){
    add_filter('wp_insert_post_data', 'another_function' );
}

Related posts

Leave a Reply

1 comment

  1. 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.