The get_editable_user_ids() WordPress PHP function retrieves the IDs of users who have the capability to edit posts.
Usage
get_editable_user_ids($user_id, $exclude_zeros = true);
Parameters
$user_id
(int) – Required User ID.$exclude_zeros
(bool) – Optional. Whether to exclude zeroes. Default: true.
More information
See WordPress Developer Resources: get_editable_user_ids()
Examples
Get editable user IDs for a specific user
Retrieve the editable user IDs for user ID 3.
$editable_user_ids = get_editable_user_ids(3); print_r($editable_user_ids); // Outputs the editable user IDs array.
Include zero user IDs in the result
Get editable user IDs including zero user IDs for user ID 5.
$editable_user_ids = get_editable_user_ids(5, false); print_r($editable_user_ids); // Outputs the editable user IDs array including zeroes.
Display user names for editable users
Retrieve the editable user IDs for user ID 7 and display their user names.
$editable_user_ids = get_editable_user_ids(7); foreach ($editable_user_ids as $user_id) { $user_info = get_userdata($user_id); echo "User ID: " . $user_id . " - User name: " . $user_info->user_login . "<br>"; }
Count editable users for a specific user
Count the number of editable users for user ID 10.
$editable_user_ids = get_editable_user_ids(10); $editable_users_count = count($editable_user_ids); echo "Number of editable users for user ID 10: " . $editable_users_count;
Check if a specific user is editable by another user
Determine if user ID 2 can edit user ID 4.
$editable_user_ids = get_editable_user_ids(2); if (in_array(4, $editable_user_ids)) { echo "User ID 2 can edit User ID 4."; } else { echo "User ID 2 cannot edit User ID 4."; }