- Installing SureDash
- Download and Access Your SureDash License
- Updating SureDash
- Understanding Spaces and Space Groups in SureDash
- Add a Space Content Type in SureDash
- How to Set Up a SureDash Course Space
- How to Set Up Google Login in SureDash: A Step-by-Step Guide
- How to Set Up Facebook Login in SureDash: A Step-by-Step Guide
- Understanding the Customize Portal in SureDash
- How To Add a Logo To The SureDash Portal
- Setting up Space Groups
- Hidden Spaces in SureDash
- How to Create a Feed Space
- How to Set up “Course” space in SureDash?
- How to Create a “Discussion” Space in SureDash
- How To Set Up A Private Discussion Space In SureDash
- Creating a “Single Post/Page” Space in SureDash
- How to Set Up a “Link” Space in SureDash
- How to Configure SureDash Space Layouts
- Understanding the “Single Post/Page” Space Type in SureDash
- How to Regenerate the Default SureDash Pages
- Recommended Hosting for SureDash
- Customizing the Portal Slug Using a Filter
- How to Edit SureDash Space or Post with Any Page Builder
- How to Use the Profile URLs in SureDash
- How to Manage Navigation Sidebar Top Sticky Offset in SureDash
- Custom Classes Used in Site Editor and Their Purpose
How to Restrict Any Space or Post from SureDash?
SureDash is built with flexibility in mind, and developers can easily control access to Spaces or individual Posts using custom code.
This guide will help third-party developers or advanced users add restrictions to any Space or Post within SureDash, based on their own rules (like user roles, meta fields, or any custom logic).
Use Case
You might want to restrict a:
- Specific Space (e.g. only visible to logged-in users)
- Individual Post inside a Space (e.g. available to users with a particular role or membership)
This can be done by using a custom filter and redirecting the user when your condition is not met.
Code Example
Below is a sample code snippet that you can copy into your plugin or your child theme’s functions.php file. This code restricts access to a specific Space and Post, and redirects users to a custom URL if they do not meet the condition.
Gist Link: SureDash Restrict Access Snippet
add_action( 'template_redirect', function () {
// Get current post and check if it's a SureDash Space or Post
if ( is_singular( 'suredash_space' ) || is_singular( 'suredash_post' ) ) {
$post_id = get_the_ID();
// Your custom logic goes here
// Example: Check if user is logged in
if ( ! is_user_logged_in() ) {
// Optional: Add exceptions for specific Space/Post IDs
$excluded_ids = [ 123, 456 ]; // Replace with your own IDs
if ( in_array( $post_id, $excluded_ids ) ) {
return;
}
// Redirect to a custom page
wp_redirect( home_url( '/restricted-access/' ) );
exit;
}
}
} );
What This Code Does
- It checks if the current page is a SureDash Space or SureDash Post.
- Then, it runs a check using your custom logic (e.g. whether the user is logged in).
- If the condition is not met, it redirects the user to a specific page like /restricted-access/.
Customize It Further
You can replace the logic inside the code to suit your needs:
Check for specific user roles:
if ( ! current_user_can( 'subscriber' ) ) {
Use SureMembers Access Groups (if using SureMembers):
if ( ! function_exists( 'suremembers_user_has_access_group' ) || ! suremembers_user_has_access_group( get_current_user_id(), 101 ) ) {
Important Notes
- Make sure the page you’re redirecting to (/restricted-access/) exists and gives users a proper message.
- Use this only if you’re comfortable editing PHP code or building custom plugins.
- Test this on a staging site first to avoid accidental lockouts.
If you’re building an integration or plugin that extends SureDash, this method lets you fully control who sees what content, with full flexibility on how you define your conditions.
We don't respond to the article feedback, we use it to improve our support content.