Skip to content

Instantly share code, notes, and snippets.

@yoosuf
Last active July 11, 2017 16:51
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save yoosuf/3890f3789754afe65525 to your computer and use it in GitHub Desktop.
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