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 writing a plugin that adds some extra thumbnails, checkboxes, etc to the end of a post.

I'm trying to figure out how to use add_filter properly.

Basically, I've got

add_filter('the_content', 'do_some_magic_at_the_end');

And there is a corresponding do_some_magic_at_the_end function that takes $content and appends some stuff to it.

I want this filter to be added after all other filters. I don't want it overwriting any other filter. The docs says default priority is 10, so I assume it is simply being added to a chain of filters that get run on the_content.

If I set the priority to 1, will it overwrite any core functions?

share|improve this question
add comment

2 Answers

You won't overwrite anything. Each priority level is actually a list of filters to use. If you have several different things hooking into the same filter at the same priority, they all get run.

share|improve this answer
add comment

There is no definitive answer to that because there is no limit to priorities high/low. Also plugins can be much less careful than core with this.

  • 11 is good number to be after default priority;
  • 20 to be late;
  • multiple thousands is good to be later than anyone who didn't put more zeros in his thousands;
  • 9 is good number to be slightly earlier than default;
  • 1 to be really early;
  • -1 to be almost definitively first, because very few people remember that priorities can go negative.

Overall if you want to be sure you are before other functions you will have to dump everything that is added to hook in your specific setup and debug through that. You might need to create wrapper function to add your filters at specific load stage or even move other filters around.

And if you are making plugin for distribution you can guess, but you can't be sure.

share|improve this answer
    
A (very inefficient) way to make sure your filter runs last, is to hook into the all action, where you can examine the $wp_filter array and add your filter with the latest priority. So technically you can be sure, but it's not worth it. You could also use PHP_INT_MAX as your priority. –  Jan Fabry Sep 23 '10 at 8:04
    
Good point about all but I'd not use it that way. Terribly inefficient indeed. As for max I'd not go to extremes either... Priority is stored as array key, which can be interpreted both as integer and string by PHP. Going to corner cases might blow up. –  Rarst Sep 23 '10 at 8:20
add comment

Your Answer

 
discard

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