Limit views to logged in users

By: Connor McGrath | Asked: 08/09/2022
ForumsCategory: General questionsLimit views to logged in users
Connor McGrath asked 2 years ago
Is there any way to make it so views only popup for logged-in users?
3 Answers
Victor Font answered 2 years ago
What do you mean by "popup"? There are many ways to restrict content, but like anything else, how to do it depends on your intentions.
Connor McGrath replied 2 years ago

Hey Victor,

Thanks for the response.

I currently display job applications via a view but would like to restrict the views to only display once the login field has been utilized https://i.imgur.com/bS24RS1.png

Bobby Clapp answered 2 years ago
You can do that by adjusting the page visibility settings in wordpress or via a view parameter with a parameter of default = none. [get param=entry default="none"]
Walter JonesWalter Jones answered 2 years ago
Here is a quick snippit you could use if you don't need anything fancy, add it to Code Snippets Plugin.  You use the shortcode [check-user-role role="subscriber"] your content or view shortcode [/check-user-role]  You can change the role= to whatever your roles are.
<script>
function func_check_user_role( $atts, $content = null ) { $user = wp_get_current_user(); $user_role = $atts['role']; $allowed_roles = []; array_push($allowed_roles , $user_role); if ( is_user_logged_in() && array_intersect($allowed_roles, $user->roles ) ) { return $content; } else { return ''; } } add_shortcode( 'check-user-role', 'func_check_user_role' );</script>


Making the Best WordPress Plugin even better - Together

Take on bigger projects with confidence knowing you have access to an entire community of Formidable Experts and Professionals who have your back when the going gets tough. You got this!
Join the community
crossarrow-right