Created
September 27, 2016 15:41
-
-
Save jancbeck/a253c5fe0f173cc2ecb7696e9ea0b104 to your computer and use it in GitHub Desktop.
Automatically password protect all new custom post types in WordPress
This file contains 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
<?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 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.