-
-
Save nateplusplus/56ae36d2fe07ac75476eec20747ecd8d to your computer and use it in GitHub Desktop.
Wordpress - Password protect a custom post type programmatically
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 | |
//Password Protect programmatically | |
function passwordProtectPosts( $post_object ) { | |
//Checks if current post is a specific custom post type | |
if ( $post_object->post_type !== 'tutorial' ) { | |
return; | |
} | |
$post_object->post_password = 'your_password'; | |
} | |
add_action( 'the_post', 'passwordProtectPosts' ); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment