Skip Navigation

[Resolved] Access control not restricting visibility of posts

This support ticket is created 3 years, 2 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/Karachi (GMT+05:00)

This topic contains 1 reply, has 2 voices.

Last updated by Waqar 3 years, 2 months ago.

Assisted by: Waqar.

Author
Posts
#1952649
Students access control copy.jpeg

I am trying to hide the Students post type from being viewed by users who are not logged in

Link to a page where the issue can be seen: hidden link

I expected to see no records appear.

Instead, I see the test record that I have created.

#1953367

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi Greig,

Thank you for contacting us and I'd be happy to assist.

By default, Access restrictions do not affect the output of a post View. Access controls affect the visibility of single posts or posts shown in an archive.

To be able to apply Access restrictions (including from Post Groups for individual posts) to the output of a View you can register a custom shortcode that uses the Access API to check whether the current user has read rights for the current post, and then apply that custom shortcode in a conditional shortcode or conditional block.

Note: Please remember to register the custom shortcode "allowed" at Toolset > Settings > Front-end content.


/**
 * Check permission to read post
 */
add_shortcode('allowed', function () {
 
    $userid = get_current_user_id();
    global $post;
 
    $allowed = apply_filters( 'toolset_access_api_get_post_permissions', true, $post, 'read', $userid, ICL_LANGUAGE_CODE );
 
    $return = ( $allowed ) ? 1:0;
 
    return $return;
});

The output of the View loop item can then be wrapped conditionally, e.g.


<wpv-loop>
[wpv-conditional if="( '[allowed]' eq '1' )"]
// view's loop item content
[/wpv-conditional]
</wpv-loop>

I hope this helps and please let me know if you need any further assistance around this.

regards,
Waqar

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.