Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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' );
}
share|improve this question

1 Answer 1

up vote 8 down vote accepted

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.

share|improve this answer
    
Easy enough. Thanks Mike! –  Scott B Jan 28 '11 at 18:32

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.