I have a custom post type for meals where authors can decide to share with the community - i.e. make their meal Private or Public.
I have a post grid of community meals (all Public meals, all users) and any member (site user) can click through to the individual Meal post.
This is where it gets complicated, as the meal post has an edit link in it for the author to change it if they choose, also a delete post and add new link.
I discovered that the edit link still works for other users and anyone in the community can therefore edit the post, presumably delete it too..not what we need.
Can you tell me how I hide the edit and delete links from them and only show for the Meal post author.. is there a conditional I can use to achieve this, or other solution.
shortcode is as follows, set up in a Beaver builder text field module on the single post content template for this CPT.
[toolset-edit-post-link content_template_slug="edit-member-meals"]Edit[/toolset-edit-post-link] Add New View All [cred_delete_post_link action='trash' text='Delete' redirect='19296' message='Are you sure you want to delete this meal?' message_show='1' class='cred-refresh-after-delete']
[cred-form-message]
Add New is a link to the Cred form to add a new meal, and View All is a link back to a page showing all meals for the individual.
Well - Toolset offers [wpv-conditional] shortcode using which you can check the current user role.
First option - (This needs Toolset Access plugin installed and activated):
- you can use [toolset_access] shortcode. For example:
[toolset_access role="customer" operator="allow"]
display info for customer role only
[/toolset_access]
[toolset_access role="dealer" operator="allow"]
display info for dealer role only
[/toolset_access]
[toolset_access role="editor" operator="deny"]
hide/deny info for editor role only
[/toolset_access]
Second option:
- You can use View's [wpv-current-user] shortcode to get current logged in user information:
So, if you want to check current user role - for example:
[wpv–conditional if="( '[wpv-current-user info='role']' ne 'editor' )"]
This information will be displayed to all users who will not have Editor role
[/wpv–conditional]
does "editor" recognise the author only and would it reject any other user..?
also when talking about roles - what is the method to differentiate between the author of a post and any other current user... i.e. what role identifies someone as not the author of a post..?
If editor does indeed identify the author then I might be in business.
In the meantime I will try your code out and see how I go.
As I understand, you want to compare current post author's role = logged in users role.
To compare the role with current post author - you can use following code:
[wpv–conditional if="('[wpv-current-user info="role"]' eq '[wpv-post-author format="meta" meta="role"]')"]
above condition will check current user role = post author role then and then this information will be displayed
[/wpv–conditional]
I tried that and also the id version you referred to in the related ticket.
Using this code..
[wpv–conditional if="('[wpv-current-user info="id"]' eq '[wpv-post-author format="meta" meta="id"]')"]
TEST
[/wpv–conditional]##However, it is not executing, only showing the code as seen in the attached screenshots
could you please share problem URL and access details so I can look at the issue.
*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.
I would additionally need your permission to de- and re-activate Plugins and the Theme, and to change configurations on the site. This is also a reason the backup is really important. If you agree to this, please use the form fields I have enabled below to provide temporary access details (wp-admin and FTP).
I have set the next reply to private which means only you and I have access to it.
Ok - I've added one test conditional statement as given under:
[wpv-conditional if="( '34' eq '[wpv-post-author format='meta' meta='ID']' )"]
Test for 34
[/wpv-conditional]
And I see it used to work, please try to add a conditional statement using button "conditional output" - that will be available when you switch to Text mode:
=> hidden link
Once you added conditional statement - try to adjust the conditional as per your need.