Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
WordPress: When a post is published, trigger an event
<?php
/*
* Add this function somewhere in functions.php
* You will see there is nothing is magic in WordPress
**/
function on_all_status_transitions( $new_status, $old_status, $post ) {
if ('publish' == $new_status && 'publish' != $old_status && 'trash' != $old_status) {
// Your code comes here
}
}
add_action( 'transition_post_status', 'on_all_status_transitions', 10, 3 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment