0

How to write conditions on capabilities not on user role?

2
  • 2
    Capabilities are far easier to test than user roles. How were you testing user roles?
    – Rup
    Commented May 18, 2021 at 9:24
  • I was implementing that in a plugin and was getting error, added if(!function_exists('wp_get_current_user')) { include(ABSPATH . "wp-includes/pluggable.php"); } above that and it worked
    – Ricky
    Commented May 27, 2021 at 9:17

1 Answer 1

1

With current_user_can(), or $user->has_cap() for other users:.

if ( ! current_user_can( 'delete_post', $post_id ) ) {
    wp_die( __( 'Sorry, you are not allowed to move this item to the Trash.' ) );
}
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.