[Resolved] Showing lock-icon in front of listed post title for restricted users
This support ticket is created 4 years, 7 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.
No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.
I have restricted content for registered members. The restriction of the content and levels happen using Ultimate Membership Pro.
I'm trying to show a little lock-icon (see screen) before title of restricted content for non registered users. I'm using this code below to achieve this.
<?php
function pmsc_add_icon_next_to_restricted_post($post_title, $post_id) {
if (is_admin()) {
return '';
}
if (pms_is_post_restricted($post_id)) {
I see the lock appears in the archive pages listings (see archive.png) but I don't see it appear on the front page listings (see front.png)
Is there special html code that has to be added in toolset so that the title can append an icon?
Any help or clue from your side would be highly appreciated
We can actually get this to work in views if we wrap it as a custom shortcode. Add the following to your custom code in Toolset -> Settings -> Custom Code and ensure that it is enabled
Once you have done this you should be able to use the shortcode [wp_cust_icon] which will generate the lock icon beside your post titles if they are restricted.
2- I added the shortcode before my title in one view module to test the results
3- I got the lock icon now in front of all titles instead of only the restricted ones. I expected the icon to appear only before the restricted content for unregistered visitors and not before the free ones too.
My apologies, I forgot to mention that the shortcode also takes the current post's ID as a parameter. To make this work in the view you will need to format the shortcode like this
[wp_cust_icon id="[wpv-post-id]"][wpv-post-title]
Where you are passing the id into the shortcode to determine if the lock icon should be there or not.
Please let me know if this new format helps.
Thanks,
Shane
Which would be the one above that uses the pms_is_post_restricted function. Also the is_user_logged_in() function doesn't take a parameter and would display the lock beside every post when the user is not logged in. Also the log won't display if the user is logged in.
So for the function to put the lock on the post if the user is NOT logged it. It would be.
So indeed this is the code I'm using now in the snippet section and I use the shortcode as you instructed but still not satisfactory outcome. Because as I mentioned, with this solution the lock-icon appears before all post titles; restricted and not restricted.
This will in fact happen if the user is Logged out.
If they are logged out then the lock will appear because of the logic of the code. For clarity is it that you want the lock to appear when the user is logged out and if that post is restricted? This means that the lock will only appear on these posts ?
Use it like this now [wp_cust_icon id="[wpv-post-id]"][wpv-post-title]
If this doesn't work please let me know as well as provide me with admin access so that I can debug the issue further. Please provide a link to the page to test this as well.