Skip Navigation

[Resolved] Update Post Between Password-Protected and Public

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

Problem:

Update password protected posts to published using Toolset Forms.

Solution:

You need to remove the post_password after submit the edit post form, for example:

https://toolset.com/forums/topic/update-post-between-password-protected-and-public/#post-1850381

Relevant Documentation:

This support ticket is created 3 years, 5 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.

Our next available supporter will start replying to tickets in about 0.18 hours from now. Thank you for your understanding.

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 6 replies, has 2 voices.

Last updated by aaronW-4 3 years, 5 months ago.

Assisted by: Luo Yang.

Author
Posts
#1846719

Tell us what you are trying to do?
I used a great script from one of your team members to allow a custom post to be password protected and to pull the password from a form field. But I also wanted to see if there is a way to allow the post to be updated to "public" using an edit form so that the user can change their post between password-protected and public.

Is there any documentation that you are following?
https://toolset.com/forums/topic/password-protect-custom-posts-with-toolset-forms/#post-1452647
Is there a similar example that we can see?

What is the link to your site?

#1846835

Hello,

You can setup a post form for editing post, option "Set this post status" choose "Published":
https://toolset.com/course-lesson/front-end-forms-for-editing-content/

So after user submit above edit post form, the post will be changed to "Published"

#1848677

I am actually wondering about the "visibility" setting of the post, not the "status" of the post. I am using the script provided in the other forum post to set the visibility setting to "Password-protected" and to pull the password from a form field. At this point, I wanted to see about getting help in setting the visibility back to "public" using a form field.

#1849343

There are 8 kinds of built-in post status within WordPress, see WP document:
https://wordpress.org/support/article/post-status/

If you setup a post as published then it will be viewable by everyone
https://wordpress.org/support/article/post-status/#publish
And it should be able to override "visibility" setting of the post

#1849859

I set it up to publish, but in the post edit form, it is publishing a second version of the post rather than just updating the status of the current post.

#1850381

Thanks for the details, I have tried it in my localhost, you need to remove the post_password after submit the edit post form, for example, add below codes into your theme file:

add_action('cred_save_data', 'remove_password_action',10,2);
function remove_password_action($post_id, $form_data)
{
    // Change the ID below to the ID of your Toolset Form
    if ($form_data['id']==123) {
		$my_post = array(
		  'ID'    => $post_id,
		  'post_password'  => ''
		);
		  
		// Insert the post into the database
		wp_update_post( $my_post );
    }
}

Please replace 123 with your edit post form's ID, and test again

#1850813

That was perfect. Thank you for the help!

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.