Skip Navigation

[Resolved] Password Protect Individual Posts

This thread is resolved. Here is a description of the problem and solution.

Problem:

I am creating a site which lists rental properties for a charity.

They want to be able to send people to view an individual property but not have it publicly available.

Is there a way for them to set a password in the Post Form?

Solution:

There isn't such kind of built-in feature within Toolset Forms plugin, but it is possible with little custom codes, for example:

https://toolset.com/forums/topic/password-protect-individual-posts/#post-2266231

Relevant Documentation:

https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data

This support ticket is created 2 years, 11 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

This topic contains 2 replies, has 2 voices.

Last updated by janeC-2 2 years, 11 months ago.

Assisted by: Luo Yang.

Author
Posts
#2266133

Hi,
I am creating a site which lists rental properties for a charity.
They want to be able to send people to view an individual property but not have it publicly available.
Is there a way for them to set a password in the Post Form?
So that a person can be given the URL (with password) for one property only and not be able to view other properties.

thanx,
Jane

#2266231
wpv_post_password.jpg

Hello,

There isn't such kind of built-in feature within Toolset Forms plugin, but it is possible with little custom codes, for example:
1) In your post form, add a generic single line field "wpv_post_password", see my screenshot wpv_post_password.JPG
2) Add below PHP codes into your theme file functions.php:

add_action('cred_save_data', function($post_id, $form_data)
{
    // Change the ID below to the ID of your Toolset Form
    if ($form_data['id']== 123 ) {
        if ( isset($_POST['wpv_post_password']) && !empty($_POST['wpv_post_password'])) {
            $password = $_POST['wpv_post_password'];
            //update the post with the new password
            $my_post = array(
              'ID'    => $post_id,
              'post_password'  => $password
            );
              
            // Update the post into the database
            $res = wp_update_post( $my_post );
        }
    }
},10,2);

Please replace 123 with your post form's ID

More help:
https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data

#2268013

My issue is resolved now. Thank you!