Last active
July 11, 2017 16:51
-
-
Save yoosuf/3890f3789754afe65525 to your computer and use it in GitHub Desktop.
WordPress: When a post is published, trigger an event
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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