Install
This is the repository archive. It installs, but the folder name will carry the branch suffix and updates will not flow.
Install straight from GitHub with WP-CLI:
wp plugin install https://github.com/macdudeuk2/ox-content-blocker/archive/refs/heads/master.zipA comprehensive WordPress plugin for fine-grained content restriction based on user login status and access tags. Control access to posts, pages, menu items, and content with an intuitive interface.
Features
- Post/Page-level restrictions - Restrict entire posts or pages to specific access tags
- Menu item restrictions - Hide menu items from users without proper permissions
- Shortcode support - Wrap any content with tag-based restrictions
- Access tag management - Create and manage custom access tags for flexible permissions
- Administrator override - Admins can always see all content regardless of restrictions
- User tag assignment - Assign access tags to users through the admin interface
- Bulk operations - Apply restrictions to multiple posts at once based on post type and category
- Floating login window - Elegant login modal for users accessing restricted content
- Password reset functionality - Built-in "Lost your password?" feature in the login modal
- Smart redirects - Automatic redirects after successful login based on user permissions
Installation
- Upload the
ox-content-blockerfolder to your/wp-content/plugins/directory - Activate the plugin through the 'Plugins' menu in WordPress
- The plugin will automatically set up the necessary database tables and meta fields
Usage
Post/Page Restrictions
Setting Restrictions in the Classic Editor
- Open a post or page in the WordPress classic editor
- Look for the "OX Content Blocker" meta box in the right sidebar
- Configure restrictions:
- Require Login: Check this to require users to be logged in
- Block Logged-in Users: Check this to hide content from logged-in users (useful for "Login" links)
- Required Access Tags: Select one or more access tags that can access this content
- Save your changes - restrictions are automatically applied
Note: The classic editor support works with common content post types including posts, pages, events (The Events Calendar), products (WooCommerce), and other content-focused post types. For other custom post types, you can add support using the filter shown in the Customization section.
Events Calendar Integration: The plugin includes special support for The Events Calendar plugin, blocking both the main event content and event meta information (details, tickets, etc.) when restrictions are applied.
How It Works
- Logged out users: See an elegant login prompt with a floating login window
- After successful login: Users are automatically redirected back to the requested content (if they have permission) or to the home page (if they don't have the required tags)
- Logged in users without required tags: See a "You do not have permission to view this content" message
- Logged in users when "Block logged-in users" is enabled: See a "This content is only available to visitors who are not logged in" message
- Users with required tags: See the full content
- Administrators: Always see all content regardless of restrictions
Menu Item Restrictions
Setting Menu Restrictions
- Go to Appearance → Menus in your WordPress admin
- Select or create a menu to edit
- Add menu items as usual
- Expand a menu item by clicking the arrow next to it
- Scroll down to find the "OX Content Blocker" section
- Configure restrictions:
- Require Login: Check to require users to be logged in
- Block Logged-in Users: Check to hide menu item from logged-in users (useful for "Login" links)
- Required Access Tags: Select tags that can see this menu item
- Save the menu - restricted items will be hidden from unauthorized users
How It Works
- Menu items with restrictions are completely hidden from users without proper permissions
- Menu items with "Block logged-in users" are hidden from logged-in users (useful for "Login" links)
- No broken links - the menu structure adjusts automatically
- Administrators can see all menu items regardless of restrictions
Shortcode Restrictions
Using the Shortcode
Wrap any content with the [oxcb_restrict] shortcode:
[oxcb_restrict login="true" tags="premium,member"]
This content is only visible to logged-in users with premium or member tags.
[/oxcb_restrict]
Shortcode Parameters
login(optional): Set to "true" to require login, "false" to allow public accessblock_logged_in(optional): Set to "true" to hide content from logged-in userstags(optional): Comma-separated list of access tags that can access the content
Examples
Require login only:
[oxcb_restrict login="true"]
This content requires login but any user can access it.
[/oxcb_restrict]
Specific tags only:
[oxcb_restrict tags="premium,member"]
This content is only visible to users with premium or member tags.
[/oxcb_restrict]
Block logged-in users:
[oxcb_restrict block_logged_in="true"]
This content is only visible to visitors who are not logged in.
[/oxcb_restrict]
Supported by default:
post,page(WordPress core)event,events(The Events Calendar)product(WooCommerce)course,lesson(Learning management systems)portfolio,project(Portfolio plugins)recipe(Recipe plugins)listing,property(Real estate plugins)job,resume(Job board plugins)
Floating Login Window
The plugin now includes an elegant floating login window that appears when users try to access restricted content. This provides a much better user experience than simple text messages.
Features
- Modern design - Clean, responsive modal with smooth animations
- AJAX login - No page reloads during login process
- Password reset - Built-in "Lost your password?" functionality with email reset
- Smart redirects - Users are automatically redirected to the content they were trying to access
- Fallback handling - If a user logs in but doesn't have the required tags, they're redirected to the home page
- Keyboard support - Close modal with Escape key
- Mobile responsive - Works perfectly on all device sizes
- Dark mode support - Automatically adapts to user's system preferences
How It Works
- User visits restricted content - A login prompt appears with a "Login" button
- User clicks "Login" - A floating modal appears with login form
- User enters credentials - AJAX request handles authentication
- Password reset option - Users can click "Lost your password?" to reset via email
- Successful login - User is automatically redirected to the requested content
- Insufficient permissions - User is redirected to home page with appropriate message
Password Reset Flow
The floating login window includes a complete password reset workflow:
- User clicks "Lost your password?" - Modal switches to password reset form
- User enters email address - Form validates email format
- System sends reset email - Uses WordPress core password reset functionality
- User receives email - Contains secure reset link with 24-hour expiration
- User clicks reset link - Redirected to WordPress password reset page
- User sets new password - Can then return to login and access content
Bulk Operations
Setting Bulk Restrictions
The bulk operations feature allows you to apply content restrictions to multiple posts at once based on post type and category.
- Go to Settings → OX Tag Management in your WordPress admin
- Scroll to the "Bulk Block Set" section (located above the cleanup tools)
- Select criteria:
- Post Type: Choose the type of content to restrict (posts, pages, custom post types)
- Category: Optionally select a specific category to filter posts
- Term: Optionally select a specific term within the category
- Configure restrictions:
- Require Login: Check to require users to be logged in
- Block Logged-in Users: Check to hide content from logged-in users
- Required Access Tags: Select one or more access tags that can access the content
- Review the count of posts that will be affected
- Click "Apply Restrictions" to execute the bulk operation
How Bulk Operations Work
- Real-time counting: The interface shows exactly how many posts will be affected as you change your selections
- Same restriction format: Bulk operations use the identical restriction format as individual posts
- Batch processing: Large operations are processed efficiently to avoid timeouts
- Validation: The system validates all inputs and prevents invalid operations
- Confirmation: You must confirm the action before it executes
- Feedback: Clear success/error messages show the results of the operation
Use Cases
- Category-wide restrictions: Apply login requirements to all posts in a specific category
- Post type restrictions: Make all pages require premium access tags
- Event restrictions: Restrict all events in a specific category to members only
- Product restrictions: Apply access controls to all products in a specific category
Styling Blocked Content Messages
You can customize the appearance of blocked content messages by adding CSS to your theme:
.oxcb-blocked-message {
background: #f8f9fa;
border: 1px solid #dee2e6;
border-radius: 4px;
padding: 15px;
margin: 10px 0;
color: #6c757d;
text-align: center;
}
Modifying Restriction Logic
The plugin uses WordPress hooks and filters, making it easy to extend:
// Example: Add custom restriction logic
add_filter('oxcb_user_can_access_content', function($can_access, $user_id, $required_tags) {
// Your custom logic here
return $can_access;
}, 10, 3);
Customization
Adding Support for Custom Post Types
To extend the plugin to work with custom post types that aren't supported by default:
// Add this to your theme's functions.php or a custom plugin
add_filter('oxcb_supported_post_types', function($post_types) {
// Add your custom post type
$post_types[] = 'your_custom_post_type';
return $post_types;
});
Customizing Blocked Content Messages
You can customize the appearance and content of blocked content messages:
// Modify the blocked content message
add_filter('oxcb_blocked_message', function($message, $reason) {
if ($reason === 'login_required') {
return 'This content requires you to be logged in. Please <a href="#" class="oxcb-show-login-modal">login here</a>.';
}
return $message;
}, 10, 2);
Extending Access Control Logic
For advanced use cases, you can hook into the access control system:
// Custom access control logic
add_filter('oxcb_user_can_access_content', function($can_access, $user_id, $restriction) {
// Example: Allow access based on custom user meta
$custom_access = get_user_meta($user_id, '_custom_access_level', true);
if ($custom_access === 'premium') {
return true;
}
return $can_access;
}, 10, 3);
Troubleshooting
Common Issues
Q: I can't see the OX Content Blocker meta box in the classic editor A: Make sure you're editing a post or page. The meta box appears in the right sidebar. For custom post types, you may need to add them using the filter shown in the Customization section.
Q: Menu restrictions aren't working A: Check that you've saved the menu after setting restrictions. Also ensure the menu is assigned to a location in your theme.
Q: Users can't see content they should have access to A: Verify that the user has been assigned the correct access tags in the user edit screen. Check that the tag names match exactly (case-sensitive).
Q: Shortcodes aren't working A: Make sure the shortcode syntax is correct and that you're using the exact tag names as they appear in the admin interface.
Q: No access tags are available in the restriction options A: Create some access tags first in Settings → OX Content Blocker before setting up restrictions.
Q: Bulk operations aren't working A: Make sure you have selected a post type and at least one restriction type. The bulk operations require proper permissions and valid access tags.
Debug Mode
To enable detailed logging for troubleshooting:
- Edit the plugin files and uncomment the debug lines (remove
//from// error_log(...)statements) - Check your WordPress debug log for detailed information about restriction checks
- Remember to comment out debug lines in production
Performance Considerations
- Tag checks are cached for the duration of the page load
- Menu filtering happens once per menu display
- Content filtering is applied only when restrictions are set
- No database queries are made for unrestricted content
Technical Details
Database Tables
The plugin uses WordPress post meta and user meta tables:
_oxcb_post_restriction: Stores post/page restrictions_oxcb_menu_item_restriction: Stores menu item restrictions_oxcb_access_tags: Stores user access tagsoxcb_access_tags: Stores available access tags (in wp_options)
Hooks and Filters
The plugin provides several hooks for developers:
// Filter user tags before checking access
add_filter('oxcb_user_tags', function($tags, $user_id) {
return $tags;
}, 10, 2);
// Filter content restriction results
add_filter('oxcb_can_access_content', function($can_access, $user_id, $restriction) {
return $can_access;
}, 10, 3);
// Modify blocked content message
add_filter('oxcb_blocked_message', function($message, $reason) {
return $message;
}, 10, 2);
Security
- Nonce verification is used for all form submissions
- Capability checks ensure only authorized users can modify restrictions
- Data sanitization is applied to all inputs
- SQL injection protection through WordPress prepared statements
Development
Contributing
This plugin is open source and contributions are welcome!
GitHub Repository: https://github.com/macdudeuk2/ox-content-blocker
To contribute:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
Local Development
Requirements:
- WordPress 5.0+
- PHP 7.4+
- MySQL 5.6+ or MariaDB 10.1+
Setup:
- Clone the repository:
git clone https://github.com/macdudeuk2/ox-content-blocker.git - Copy to your WordPress plugins directory:
wp-content/plugins/ox-content-blocker/ - Activate the plugin in WordPress admin
- Start developing!
Building for Distribution
The plugin is ready for distribution as-is. No build process required.
Support
For support, feature requests, or bug reports, please contact the plugin developer.
Changelog
Version 2.3.0
- Password reset functionality - Added "Lost your password?" feature to the floating login window
- Enhanced user experience - Users can now reset passwords without leaving the login modal
- WordPress core integration - Uses built-in password reset functionality for security
- Seamless form switching - Smooth transitions between login and password reset forms
- Improved accessibility - Better focus management and keyboard navigation
- Mobile responsive - Password reset form works perfectly on all devices
Version 2.0.0
- Complete architecture overhaul - Replaced role-based system with access tags
- Removed block-level restrictions - Simplified to focus on working features
- New access tag management - Create and manage custom access tags
- Cleaner user interface - Simplified tag assignment and content restriction
- Better separation of concerns - Access tags are independent of WordPress roles
- Improved performance - Removed complex role checking logic
- Enhanced flexibility - Users can have multiple tags without role conflicts
Version 1.5.0
- Improved role management to only show OX Content Blocker-created roles in user profiles
- Added role tracking system to distinguish between plugin-created and other plugin roles
- Enhanced role management interface with role origin indicators ("OX Created" vs "Other Plugin")
- Fixed potential confusion between WooCommerce roles and additional roles
- Content restriction options still include all WordPress roles for maximum flexibility
Version 1.4.0
- Added cleanup tools to the role management admin page
- New "Remove All Additional Roles" tool to clean up user meta data
- New "Remove All Content Restrictions" tool to clean up all restriction data
- Enhanced admin interface with warning messages and confirmation dialogs
- Improved database cleanup with proper error handling and success messages
Version 1.3.0
- Added "Block logged-in users" option to all protection mechanisms
- New option allows hiding content/menu items from logged-in users
- Useful for hiding "Login" links and other visitor-only content
- Added to post/page restrictions, menu restrictions, and shortcodes
- Updated classic editor meta box with new option
- Enhanced shortcode with
block_logged_inparameter
Version 1.0.5
- Added comprehensive Events Calendar integration
- Blocks event meta information and tickets when restrictions are applied
- Enhanced content blocking for Events Calendar plugin
Version 1.0.4
- Fixed post type name for The Events Calendar (tribe_events)
- Updated author information
Version 1.0.3
- Fixed post type name for The Events Calendar (tribe-events)
- Updated author information
Version 1.0.2
- Fixed post type name for The Events Calendar (tribe_events)
- Updated author information
Version 1.0.1
- Added classic editor support with meta box integration
- Support for custom post types via filter hook
- Improved compatibility with plugins using classic editor (e.g., The Events Calendar)
Version 1.0.0
- Initial release
- Post/page-level content restrictions
- Menu item restrictions
- Shortcode support
- Dynamic role management
- User role assignment interface
- Administrator override functionality
License
This plugin is licensed under the GPL v2 or later.
OX Content Blocker - Secure, flexible content restriction for WordPress.