Created
August 15, 2021 09:38
-
-
Save FrancoStino/cb7a0b5d1e840013e3807e11f0f7a292 to your computer and use it in GitHub Desktop.
Convert "Draft" post to "Publish" after save post
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
<? | |
/* | |
* 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