Skip to content

Instantly share code, notes, and snippets.

@jancbeck
Created September 27, 2016 15:41
Show Gist options
  • Save jancbeck/a253c5fe0f173cc2ecb7696e9ea0b104 to your computer and use it in GitHub Desktop.
Save jancbeck/a253c5fe0f173cc2ecb7696e9ea0b104 to your computer and use it in GitHub Desktop.
Automatically password protect all new custom post types in WordPress
<?php
add_filter( 'wp_insert_post_data', function( $data, $postarr ){
if ( 'book' == $data['post_type'] && 'auto-draft' == $data['post_status'] ) {
$data['post_password'] = wp_generate_password();
}
return $data;
}, '99', 2 );
@jancbeck
Copy link
Author

This will set an automatically generated password for each new post of the type "book" in WordPress. Very handy if you want all your content to be password protected and make sure you don't accidentally publish it without one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment