Skip Navigation

[Resolved] remove edit link for anyone but author

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

Problem:
remove edit link for anyone but author

Solution:
You can use [wpv-conditional] shortcode in order to check the post author ID with the current logged in user ID.

You can find the proposed solution in this case with the following reply:
https://toolset.com/forums/topic/remove-edit-link-for-anyone-but-author/#post-1153657

Relevant Documentation:
=> https://toolset.com/documentation/views-shortcodes/#wpv-conditional
=> https://toolset.com/documentation/user-guides/conditional-html-output-in-views/
=> https://toolset.com/documentation/views-shortcodes/#wpv-current-user

This support ticket is created 5 years, 12 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
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10: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/Kolkata (GMT+05:30)

Tagged: 

This topic contains 9 replies, has 2 voices.

Last updated by iain macgillivray 5 years, 12 months ago.

Assisted by: Minesh.

Author
Posts
#1153022

Hi,

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.

thanks,

Iain

#1153066

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Well - could you please tell me how you are displaying your edit and delete post links using what shortcodes and exactly where?

#1153076

Hi Minesh,

thanks, see the attached debug info ..

re how I'm using the edit link etc..

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.

I hope that helps find a solution.

cheers,

Iain

#1153088

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

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]

More info:
=> https://toolset.com/documentation/views-shortcodes/#wpv-conditional
=> https://toolset.com/documentation/user-guides/conditional-html-output-in-views/
=> https://toolset.com/documentation/views-shortcodes/#wpv-current-user

#1153095

HI Minesh,

thanks for these..

can I clarify something please..?

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.

cheers,

Iain

#1153105

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

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]

Please check following related ticket that might help you:
=> https://toolset.com/forums/topic/wpv-conditional-doesnt-fire-check-current-user-against-post-author/#post-407504

#1153180
mymealssingleposttemplate.jpg
mymealssingleposttemplate-nonauthorloggedin.jpg

Thanks Minesh,

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

#1153197

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

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.

#1153657

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

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.

#1153782

My issue is resolved now. Thank you!