Support » Plugins » Hacks » Weird add_action wp_insert_post

  • Resolved edobejar



    I’m using a template that uses the wp_insert_post() function to publish posts from outside the WordPress administrator. Now I’m creating a plugin to send an email to users when a new post is published (actually users who belong to a specific usergroup). From what I understand, I should use the wp_insert_post action hook so the plugin runs everytime a new post is inserted with that function, but somehow it’s not working.

    I’m using
    at the beginning of the plugin but it does not work. No error. It’s just not being triggered.

    When I try
    and I publish a post from the WordPress administrator, plugin works fine and emails are sent. When using this, also plugin isn’t triggered from outside the administrator.

    Any idea on what could be wrong? Which action hook should I try too?

    Thank you for your help.

Viewing 4 replies - 1 through 4 (of 4 total)
  • If I’m getting this right, you’ve only tried the action hook publish_post by posting directly from the admin, how about remotely, via your plugin or whatever?

    Hi, thank you for replying. Yes, when using publish_post I tried also posting from the template, that is outside the admin and plugin isn’t triggered.

    Here’s additional info regarding this problem:

    – Template uses wp_insert_post($post) to publish each new post.
    – The plugin I created uses add_action(‘publish_post’,’function_name’) as hook.
    – Plugin should work each time a new post is published from the template, but it’s not working. Though, if I publish a new post from the admin, it works.
    – I also tested add_action(‘wp_insert_post’,’function_name’) with the same result.

    Any other action hook I should try to make the plugin work?


    For the record, I fixed this. I found that add_action was actually being triggered with publish_post and the problem was using other functions outside the wordpress loop that were not getting the data they were supposed to get.


Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Weird add_action wp_insert_post’ is closed to new replies.