I'm writing a plugin and having a problem. I have add_action('publish_post', 'sender'); and I want this function to run first before the add_filter function, although it won't. Is there a way to do this? I've tried moving the add_filter below add_action but that doesn't work. Also pasting the add_filter one into the add_action function doesn't work. Thanks for the help.

Edit:
For example, if this would work it would be great.

  if (add_action('publish_post', 'sender'))
  {
      add_filter('wp_insert_post_data','changePost','99',2);
  }

But it doesn't and somehow still runs the add_filter function first.

  • Your question doesn't make a lot of sense. add_action and add_filter both just your functions to the hooks to the system, they don't control the order in which hooks are called. – Otto Aug 4 '11 at 19:44
  • in the normal publishing flow wp_insert_post_data is fired by WordPress before publish_post so I'm not sure thats the way to go, what are you trying to do, maybe we can think of another way – Bainternet Aug 4 '11 at 19:49
  • 1
    Take a look at the has_action() function. – kaiser Aug 4 '11 at 20:13
up vote 3 down vote accepted

It doesn't matter the order in which you call add_action() and add_filter().

What matters is the order in which the corresponding do_action() and apply_filters() are called.

So, if apply_filters('wp_insert_post_data') is run before do_action('save_post'), tough luck. You'll have to think of another way to achieve the desired result.

Your Answer

 
discard

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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