Skip Navigation

[Resolved] Allowing users to edit their own posts

This support ticket is created 5 years, 9 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
- - 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00
- - - - - - -

Supporter timezone: Asia/Ho_Chi_Minh (GMT+07:00)

Author
Posts
#1233056

Tell us what you are trying to do?
We are creating a member website using Toolset and elementor and are wanting to create a custom post type to display member organisation profiles like this:

hidden link

hidden link

We will be setting two main member groups 1 who will just have read access to the member section and another higher level group that will be able to edit their member directory/profile posts.

Is it possible to allow users to be able to edit and view their directory/profile post and not other members?

We are wanting to do this through a front-end form in the members area:
hidden link

Is there any documentation that you are following?

Is there a similar example that we can see?

What is the link to your site?
The development website is hidden link

#1233163

These are in fact 2 steps to take. Control who can read what, and then control who can use the forms to edit/create it.

For example, you could do this as outlined below:

1. Control who can read what
If you specifically want the author of the post be the only user to view, and edit the post, then you can create a View, list all those posts, and set a Query Filter that filters only posts where the author is equal to the current user
https://toolset.com/documentation/user-guides/filtering-views-query-by-author/#post-author-is-the-same-as-the-logged-in-user
In that loop create the layout for the posts as you designed in the mockup, using Custom HTML for each item in the loop.
This View can be inserted to any page, and will only show posts if the user is also the author of those posts.

2. Control who can edit what
After creating the edit form, head to Toolset Access > Form Control and check all the User Roles you want to be able to editing and submitting this form. This is not yet an "only authors" filter, it's jsut to ensure no other role but the designed one can see this form at all.

Insert this form to a Content Template, by passing a special URL parameter to the Post To Edit Attribute of the shortcode of Forms:
[cred_form form='your_form' post='[wpv-search-term param="your_parameter"]']
Change your_form to the slug of your form, your_parameter to anything you like to describe the Post ID we will receive from here later. Remember this your_parameter.
Now create a Page, name it anything you like (name-of-page) and assign the above Content Template to it.

Finally create another View (or use the one of #1 above) and insert an HTML link to edit the posts like this:
Edit [wpv-post-title]
Change again name-of-page to the slug of the page you created, and your_parameter to the parameter you chose.
This View must also have the same Query by Author as described in #1

Now you can insert this View to any page (or visit the page of step #1) and you will see the posts, and edit links to those posts that are clickable (visible) only if the current user is the author.

To avoid someone guessing the Post ID when visiting your-page-name you can wrap the entire Form in the Content Template in an HTML condition (https://toolset.com/documentation/user-guides/conditional-html-output-in-views/) where you control if there is no your_parameter or your_parameter is an ID of a Post you are not the author of, to not display the form at all.

That would require a small PHP code snippet as well, to make the condition lighter as otherwise, we will fail on over nested ShortCodes. The custom code snippet would need to return the ID of the Author of a post by ID.
This is possible in Toolset however in an HTML condition it's breaking the syntax.

If you struggle with any specific step above, please let me know so I can go into more detail!