Skip Navigation

[Resolved] Unable to hide post edit link from non-authors using shortcode

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

Problem:

I want to hide the edit post link from non authors along with other data.

Solution:

You can try wpv-conditional shortcode like this:

https://toolset.com/forums/topic/unable-to-hide-post-edit-link-from-non-authors-using-shortcode/#post-1876529

Relevant Documentation:

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

Tagged: 

This topic contains 8 replies, has 2 voices.

Last updated by himanshuS 3 years, 11 months ago.

Assisted by: Luo Yang.

Author
Posts
#1876343

I want to hide the edit post link from non authors along with other data. I am using the following shortcode:
[wpv-conditional if="( [wpv-post-author format='meta' meta='id'] eq [wpv-current-user format='meta' info='id'] )"]
Current User is post author[/wpv-conditional]
But the code does not work.

Am I missing something here?

Reference post: https://toolset.com/forums/topic/how-to-show-toolset-edit-post-link-for-only-admin-and-post-owner/

#1876529

Hello,

Please try to modify the shortcodes as below:

[wpv-conditional if="( '[wpv-post-author format="meta" meta="ID"]' eq '[wpv-current-user info="id"]' )" ]
Current User is post author
[/wpv-conditional]

And test again.

More help:
https://toolset.com/documentation/programmer-reference/views/views-shortcodes/#wpv-current-user
https://toolset.com/documentation/programmer-reference/views/views-shortcodes/#wpv-post-author
https://toolset.com/documentation/programmer-reference/views/views-shortcodes/#wpv-conditional

#1877341
79f4919aee224626cd83345c6ce2dc25.png

I tried this:
[wpv-conditional if="( '[wpv-post-author format="meta" meta="ID"]' eq '[wpv-current-user info="id"]' )" ]
Current User is post author
[/wpv-conditional]

Still does not work. Image uploaded.

#1877661

I have tried above codes in my localhost with a fresh WP installation + the latest version of Toolset Blocks plugin, it works fine,

Please check these:
1) Make sure you are using the latest version of Toolset plugins(especially the Toolset Blocks plugin), you can download them here:
https://toolset.com/account/downloads/

2) In case it is a compatibility problem, please deactivate all other plugins, and switch to wordpress default theme 2020, and test again

You can provide your website credentials in below private message box, also point out the problem page URL.

#1878803

Thanks for the details, I can login your website, but it seems you are also working on that elementor, please update here when your website is ready for debug.

#1878807

You can take control now. I gave control for that page to you.

#1878853

It seems that elementor shortcode widget does not support shortcode within shortcode feature, but there is a workaround, I have setup a demo in your website:
1) Create a content template, display the same shortcode:
hidden link

[wpv-conditional if="( '[wpv-post-author format="meta" meta="ID"]' eq '[wpv-current-user info="id"]' )" ]
Current User is post author
[/wpv-conditional]

[wpv-conditional if="( '[wpv-post-author format="meta" meta="ID"]' ne '[wpv-current-user info="id"]' )" ]
Current User is not post author
[/wpv-conditional]

2) Display above content template in elementor template:

[wpv-post-body view_template="test-ct"]

Please test again, check if it is fixed, thanks

#1879413

Thanks Luo. That works. Although I found a less complicated solution by writing my own shortcode.

<?php global $wpdb;
$current_user = get_current_user_id();
global $post;
$author_id = $post->post_author;
$output = 0;
If($current_user == $author_id)
{ $output = 1;
}
echo $output;
?>

#1879433

My issue is resolved now. Thank you!