The get_editable_authors() WordPress PHP function retrieves a list of author users who can edit posts.
Usage
To use the get_editable_authors() function, simply provide the user ID as an argument:
$authors = get_editable_authors( $user_id );
Parameters
$user_id(int) – Required. The user ID for which you want to retrieve the list of editable authors.
More information
See WordPress Developer Resources: get_editable_authors()
Examples
Get a list of editable authors for a specific user
This example retrieves a list of editable authors for the user with ID 1 and then displays their names.
$user_id = 1;
$authors = get_editable_authors( $user_id );
foreach ( $authors as $author ) {
echo $author->display_name . '<br>';
}
Create a dropdown list of editable authors
This example creates a dropdown list of editable authors for the user with ID 2.
$user_id = 2;
$authors = get_editable_authors( $user_id );
echo '<select name="authors">';
foreach ( $authors as $author ) {
echo '<option value="' . $author->ID . '">' . $author->display_name . '</option>';
}
echo '</select>';
Check if a specific author is editable by a user
This example checks if the author with ID 3 is editable by the user with ID 1.
$user_id = 1;
$author_id = 3;
$authors = get_editable_authors( $user_id );
$is_editable = false;
foreach ( $authors as $author ) {
if ( $author->ID == $author_id ) {
$is_editable = true;
break;
}
}
echo $is_editable ? 'Editable' : 'Not editable';
Count the number of editable authors for a user
This example counts the number of editable authors for the user with ID 2.
$user_id = 2; $authors = get_editable_authors( $user_id ); echo 'Number of editable authors: ' . count( $authors );
Display a list of editable authors with their email addresses
This example retrieves a list of editable authors for the user with ID 1 and displays their names and email addresses.
$user_id = 1;
$authors = get_editable_authors( $user_id );
foreach ( $authors as $author ) {
echo $author->display_name . ' (' . $author->user_email . ')<br>';
}