0

I included a file (some-file.php) in my Ajax callback function. In that file I added some actions:

// some-file.php
add_action('load-post.php', 'function1');
add_action('load-post-new.php', 'function2');

But the functions (function1 and function2) never executed, however I'm positively sure that some-file.php is included.

add_action works perfectly if I called it inside my plugin file directly. I have problem with it when I'm calling it inside my Ajax callback.

Why this happens and how can I fix it?

brasofilo
  • 25,496
  • 15
  • 91
  • 179
Pedram Behroozi
  • 2,447
  • 2
  • 27
  • 48
  • Read the documentation http://codex.wordpress.org/Function_Reference/add_action – Bud Damyanov Oct 22 '13 at 14:13
  • Could you please tell me which part of this documentation is related to my question? – Pedram Behroozi Oct 22 '13 at 14:23
  • The use of add_action() – Bud Damyanov Oct 22 '13 at 14:24
  • I updated to be more specific. – Pedram Behroozi Oct 22 '13 at 14:30
  • Are you initializing Wordpress in the Ajax callback? What errors are you seeing in the Ajax? (Look at the request's response body in the developer tools) – Pekka Oct 22 '13 at 14:31
  • No errors. I want to enable some functionality due to user call (e.g. Do sth after a post is published if this feature is enabled). Response is OK and the file will be included too. But the actions does not triggered. – Pedram Behroozi Oct 22 '13 at 14:36
  • Are you 100% sure you have the Wordpress environment loaded in your Ajax callback? – Pekka Oct 22 '13 at 14:41
  • I strongly suspect this ain't gonna work. What `function1` and `function2` are supposed to do? And most important, **where** is this Ajax action being called? – brasofilo Oct 23 '13 at 04:59
  • Check [this answer](http://stackoverflow.com/questions/16704717/how-to-display-wordpress-post-content-in-multiple-block-elements-without-page-re/16707074#16707074), you'll get an idea. – The Alpha Oct 23 '13 at 06:22

0 Answers0