Simple Membership Plugin › Forums › Simple Membership Plugin › Set post protection via PHP?
Tagged: protection post PHP
- This topic has 5 replies, 3 voices, and was last updated 9 years, 10 months ago by
rwdrummond.
-
AuthorPosts
-
May 31, 2016 at 10:17 pm #7070
rwdrummond
ParticipantHi, I have a front-end form on my site that allows select users to submit information which I then use to create a post. I would like to programmatically apply swpm protection to that post. Is there a function in the plugin I can call to do that?
If not, it appears that I can add the post_id to the field post_list in the swpm membership_tbl for the desired membership level and that will do it. Are there other steps I need to take?
Thanks!
June 1, 2016 at 12:35 am #7075mbrsolution
ModeratorHi, I am not sure if this will help you. The following example code was posted by someone in the forum.
If you already have a dummy login setup on a part of your site just simply add name attributes as needed.
<form name="swpm-login-form" method="post"> <input type="text" class="" placeholder="User Name: " name="swpm_user_name"> <input type="password" class="" placeholder="Password: " name="swpm_password"> <input type="submit" class="" value="Login" name="swpm-login"> </form>June 1, 2016 at 3:50 pm #7081rwdrummond
ParticipantThanks, but that’s not what I’m asking. Let me see if I can give a better description of what I’d like to do.
I have an existing member who is logged in. I created am HTML form with a textbox – when the member submits the form, I create a new post (by calling wp_insert_post) using the contents of the textbox as the post content. So what I have done is to allow this member to post to the site without having access to the admin back-end. This is all working.
When I create the new post, it is of course, not protected by SWPM. So everyone can see it regardless of whether they are logged in. What I would like to do is to apply SWPM protection to this post, restricting it to a given membership level(s). I can edit the post and do that manually, but I need to do it programmatically when creating the post.
So in essence, my question is, what database changes occur when you select the “Yes, Protect this content” radio button and check one or more membership levels? I want to write a PHP function to allow me to enable content restriction for a given post ID to a given membership level(s).
I’m sure the capability is there, if the developers can point me to the right class/function?
Hope that’s clear!
June 1, 2016 at 10:31 pm #7082mbrsolution
ModeratorHi, thank you for clarifying further your question. The plugin developers will investigate further your request.
Thank you
June 2, 2016 at 9:01 am #7087admin
KeymasterRead the code from the following function in the “classes/class.simple-wp-membership.php” class and that will tell you what happens when you apply protection and save the post/page (using WP editor):
function save_postdata($post_id)June 2, 2016 at 3:43 pm #7088rwdrummond
ParticipantThanks for pointing me in the right direction. I’ll see if I can sort through it!
-
AuthorPosts
- You must be logged in to reply to this topic.