Title: password protection function
Last modified: August 20, 2016

---

# password protection function

 *  [astima](https://wordpress.org/support/users/astima/)
 * (@astima)
 * [14 years, 3 months ago](https://wordpress.org/support/topic/password-protection-function/)
 * I know you can make a post password-protected if you select that option when 
   creating a post. The issue I am having is that I want to post via e-mail and 
   I have to go back and change this setting each time. Which of course defeats 
   the purpose of posting via e-mail.
 * I am trying to find the function for the password protect option to see I can
   somehow change it to make all posts in a certain category password-protected.
   Does anyone know where I can find this function?
 * Thanks

Viewing 1 replies (of 1 total)

 *  Thread Starter [astima](https://wordpress.org/support/users/astima/)
 * (@astima)
 * [14 years, 3 months ago](https://wordpress.org/support/topic/password-protection-function/#post-2569349)
 * I think I found the functioning, but not sure if I am entering the right code.
   I want all posts that appear in category 12 to automatically be password-protected.
   I will be posting to this category via e-mail and don’t want to have to go in
   each time and select this option. Below is my altered code. Is that correct?
 *     ```
       function post_password_required( $post = null ) {
       	$post = get_post($post);
   
       	if ( empty($post->post_password) )
       		return false;
       	if is_category( '12' )
       		return true;
   
       	if ( !isset($_COOKIE['wp-postpass_' . COOKIEHASH]) )
       		return true;
   
       	if ( stripslashes( $_COOKIE['wp-postpass_' . COOKIEHASH] ) != $post->post_password )
       		return true;
   
       	return false;
       }
       ```
   

Viewing 1 replies (of 1 total)

The topic ‘password protection function’ is closed to new replies.

 * 1 reply
 * 1 participant
 * Last reply from: [astima](https://wordpress.org/support/users/astima/)
 * Last activity: [14 years, 3 months ago](https://wordpress.org/support/topic/password-protection-function/#post-2569349)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
