Skip to content

Instantly share code, notes, and snippets.

@izzygld
Created June 21, 2020 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save izzygld/055b6ccdb3301b553ad0973dc1004071 to your computer and use it in GitHub Desktop.
Save izzygld/055b6ccdb3301b553ad0973dc1004071 to your computer and use it in GitHub Desktop.
Now pending posts get displayed to anyone and private posts are still only visible to admins
/*
* How to make draft posts or posts in review accessible via full url / slug.
* Source: - https://wordpress.stackexchange.com/questions/218168/how-to-make-draft-posts-or-posts-in-review-accessible-via-full-url-slug
*/
function auto_save_post_status( $post_id, $post, $update ) {
if( $post->post_status == "draft" && ! $post->post_name ) {
remove_action( 'save_post', 'auto_save_post_status', 20, 3 );
wp_update_post( array( 'ID' => $post_id, 'post_status' => 'publish' ) );
wp_update_post( array( 'ID' => $post_id, 'post_status' => 'draft' ) );
add_action( 'save_post', 'auto_set_post_status', 20, 3 );
}
}
add_action('save_post', 'auto_save_post_status', 20, 3);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment