Performance: User roles and permissions
This affects page load speed and interaction responsiveness by controlling access to backend features and frontend content rendering.
Jump into concepts and practice - no test required
<?php $is_admin = current_user_can('administrator'); if($is_admin) { echo '<div>Admin content</div>'; } ?>
<?php if(current_user_can('administrator')) { echo '<div>Admin content</div>'; } ?>
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Repeated current_user_can() calls | Minimal DOM nodes but repeated server queries | 0 | Low | [X] Bad |
| Cached permission check variable | Minimal DOM nodes with single server query | 0 | Low | [OK] Good |
add_role().add_user_role() or create_role() do not exist in WordPress core.if (current_user_can('edit_posts')) {
echo 'Can edit posts';
} else {
echo 'Cannot edit posts';
}remove_role('editor');