Hello @vincredible
You can try the following codes:
if( UM()->access()->is_restricted( $post_id) ){
// display restricted message
}else{
// show actual content
}
Regards,
Hello @aswingiri
I have already tried this function, it’s useful to show a restricted message to users who aren’t allowed to see the actual content.
What I need is to show, on a category page, to every user (regardless of whether the user is restricted or not) if an article is restricted or not, before eventually clicking to open it.
If any user is on a category page, he has to know, for every article listed, if that is a “restricted” kind of article or not, before opening it.
Example:
Article 1 listed in a category page (set as restricted to logged in users)
Article 2 listed in a category page (not set as restricted)
Every user who is on the category page has to read:
Article 1: “Premium content”
Article 2: “Free content”
I think it’s obtainable by checking if the post has the “restricted access” option enable or not.
Hello @aswingiri
is there an UM function that can achieve it?
@vincredible There is no single function that can be used but you will have to write custom codes. If are trying to display text next to the title, you might have to filter the title but the logic for checking restricted posts remains same, please check the example below:
add_filter( 'the_title', array( &$this, function( $title, $id= null ){
if(is_category() && UM()->access()->is_restricted( $id) ){
$title = $title.' (Premium content)';
}else{
$title = $title.' (Free content)';
}
return $title;
}), 10, 2 );
This is just an example, you might have to modify the codes for your requirement.