1. Home
  2. WP User Frontend Pro
  3. Tutorials
  4. How to password protect a post

How to password protect a post

To password protect a post, you need to give the option to the users. So to that, insert a text field in the form with the meta key post_password and insert this code snippet in your themes functions.php

How to password protect a post

/**
 * Set password on a post
 *
 * @param  array $args
 * @return array
 */
function wpufe_post_passowrd( $args ) {
    if ( isset( $_POST['post_password'] ) ) {
        $args['post_password'] = $_POST['post_password'];
    }

    return $args;
}

add_filter( 'wpuf_add_post_args', 'wpufe_post_passowrd' );
add_filter( 'wpuf_update_post_args', 'wpufe_post_passowrd' );

Was this article helpful to you? Yes 5 No 1

How can we help?