Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Automatically password protect all new custom post types in WordPress
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 );

This comment has been minimized.

Copy link
Owner Author

@jancbeck jancbeck commented Sep 27, 2016

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