Bit of background. A while ago, I wrote a plugin to send out an email to contributors when their post went from pending to published, to remind them to promote it. But recently, it stopped working. I was using code that looked a bit like this:
function mda_dn_transition_post_status($new_status, $old_status, $post) {
if ('publish' == $new_status && !empty($post->ID) && in_array($post->post_type, array('post', 'page'))) {
mda_publish_notifier($post->ID);
}
}
add_action('transition_post_status', 'mda_dn_transition_post_status', 10, 3);
These actions are of the form status_to_status where status is one of:
- 'new' - When there's no previous status
- 'publish' - A published post or page
- 'pending' - post in pending review
- 'draft' - a post in draft status
- 'auto-draft' - a newly created post, with no content
- 'future' - a post to publish in the future
- 'private' - not visible to users who are not logged in
- 'inherit' - a revision. see get_children.
- 'trash' - post is in trashbin. added with Version 2.9.
When a pending post is published, the action pending_to_publish is can be triggered.
What isn't clear is how to use these actions in your plugin.
Well here it is:
add_action('pending_to_publish', 'your_function');
Where pending_to_publish is the action and your_function is the function to call when the action is triggered
So in this case, when a post is published from a pending status, the function will be run.
A very basic might look like this :
wp_login_plugin.php
function your_function(){
global $post;
$author = new WP_User($post--->post_author);
$email = $author->data->user_email;
$title = get_bloginfo('title');
$link = get_permalink($post->ID);
$result=wp_mail($email, 'Your post was published',$title.' was published. Click here to view your post '. $link);
}
add_action('pending_to_publish', 'your_function');
SCHEDULED POSTS
If you want your function to trigger when a scheduled post is published you need to ALSO include
add_action('future_to_publish', 'your_function');

