Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save FrancoStino/cb7a0b5d1e840013e3807e11f0f7a292 to your computer and use it in GitHub Desktop.
Save FrancoStino/cb7a0b5d1e840013e3807e11f0f7a292 to your computer and use it in GitHub Desktop.
Convert "Draft" post to "Publish" after save post
<?
/*
* Convert "Draft" post to "Publish" after save post
*/
add_action( 'save_post', 'change_post_status', 20, 2 );
function change_post_status( $post_id ){
$my_post = array(
'ID' => $post_id,
'post_status' => 'publish',
);
// unhook this function, making sure to use the same priority, so it doesn't loop infinitely
remove_action('save_post', 'change_post_status', 20, 2 );
if( get_post_status() != 'publish'){
wp_update_post( $my_post );
}
// re-hook this function with the initial priority
add_action('save_post', 'change_post_status', 20, 2 );
}
/* --- */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment