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 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This comment has been minimized.
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.