Performance: User capability checks
User capability checks affect page interaction responsiveness and conditional content rendering speed.
<?php $can_manage = current_user_can('manage_options'); if($can_manage) { echo '<div>Admin Panel</div>'; } ?>
<?php if(current_user_can('manage_options')) { echo '<div>Admin Panel</div>'; } ?>
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Repeated current_user_can() calls | No direct DOM impact | 0 | 0 | [X] Bad |
| Cached capability check variable | No direct DOM impact | 0 | 0 | [OK] Good |
current_user_can() function in WordPress?current_user_can() is designed to check permissions for the current user.if (current_user_can('delete_posts')) {
echo 'Can delete posts';
} else {
echo 'Cannot delete posts';
}if checks if the user has 'delete_posts' capability.if (current_user_can('edit_post')) {
echo 'User can edit post';
}current_user_can() calls.Pass the test and this pattern moves unknown