👥 Never Give Admin to Everyone
Admin has all powers. User roles limit access. Editor writes, Author edits own, Subscriber reads only. Least privilege principle.
📝 Default Roles
Administrator: - Full control over site - Add/delete users, install plugins, edit themes - Risk: Can break everything Editor: - Publish and manage all posts/pages - Moderate comments, manage categories - Cannot install plugins or change theme Author: - Publish and manage own posts - Upload files - Cannot edit others' posts Contributor: - Write and edit own posts (not published) - No upload rights - Editor/Admin must publish Subscriber: - Read-only access - Manage own profile only
🎯 Custom Roles
// Add custom role
add_role('store_manager', 'Store Manager', array(
'read' => true,
'edit_products' => true,
'publish_products' => true,
'edit_orders' => true
));
// Check capabilities
if (current_user_can('edit_products')) {
// Show product editor
}
// Capability check in template
if (is_user_logged_in() && user_can($user_id, 'publish_posts')) {
echo '<a href="post-new.php">New Post</a>';
}
💡 Best Practices
- Only 1-2 Administrator accounts (use for maintenance only)
- Regular users as Subscriber or Contributor
- Use plugins to audit user capabilities
- Never give admin to untrusted users
“Content writer accidentally deleted plugin. Changed role to Author (can’t access plugins). Problem solved. Least privilege saves headaches.”
