Title: Plugin/API (add_action(&#8216;publish_post&#8217;)
Last modified: August 18, 2016

---

# Plugin/API (add_action(‘publish_post’)

 *  [briangroce](https://wordpress.org/support/users/briangroce/)
 * (@briangroce)
 * [21 years, 10 months ago](https://wordpress.org/support/topic/pluginapi-add_actionpublish_post/)
 * Maybe someone can help me here…
    I have a plugin which I’ve setup using the Plugin
   API as follows: `add_action('publish_post', 'send_notification', 5); ` But I’m
   having a problem…every time a post is published AND edited, the function runs(
   thus in this case, sending out an e-mail every time). It needs to only be ran
   the first time a post is published. Looking at the API [http://wiki.wordpress.
   org/Plugin/API] it states that `publish_post` is “called when a post status is
   changed from anything to publish or when a post is published for the first time.”
   From what I’m seeing it should more accurately read, “`publish_post` is called
   when a post status is publish or when a post is published for the first time.”
   Does anyone know if this is a correct assessment of how it works? Or am I missing
   something?

Viewing 2 replies - 1 through 2 (of 2 total)

 *  Thread Starter [briangroce](https://wordpress.org/support/users/briangroce/)
 * (@briangroce)
 * [21 years, 10 months ago](https://wordpress.org/support/topic/pluginapi-add_actionpublish_post/#post-74031)
 * FYI: This is how you can do it…
    `function your_function() { $prev_status = $
   _POST['prev_status']; $post_status = $_POST['post_status']; if (isset($_POST['
   publish'])) $post_status = 'publish'; if ($prev_status != 'publish' && $post_status
   == 'publish') { Do things here... } }
 *  [angsuman](https://wordpress.org/support/users/angsuman/)
 * (@angsuman)
 * [20 years, 11 months ago](https://wordpress.org/support/topic/pluginapi-add_actionpublish_post/#post-74445)
 * Is it the same still? has the code been fixed?

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Plugin/API (add_action(‘publish_post’)’ is closed to new replies.

 * 2 replies
 * 2 participants
 * Last reply from: [angsuman](https://wordpress.org/support/users/angsuman/)
 * Last activity: [20 years, 11 months ago](https://wordpress.org/support/topic/pluginapi-add_actionpublish_post/#post-74445)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
