The get_editable_authors WordPress PHP filter allows you to modify the list of authors who have permission to edit posts.
Usage
add_filter( 'get_editable_authors', 'your_function_name', 10, 1 );
function your_function_name( $authors ) {
// your custom code here
return $authors;
}
Parameters
- $authors (array|false) – List of editable authors. Returns
falseif there are no editable users.
More information
See WordPress Developer Resources: get_editable_authors
Examples
Limit authors based on user role
Only allow authors with the “editor” role to edit posts.
add_filter( 'get_editable_authors', 'limit_authors_by_role', 10, 1 );
function limit_authors_by_role( $authors ) {
foreach ( $authors as $key => $author ) {
if ( !in_array( 'editor', $author->roles ) ) {
unset( $authors[ $key ] );
}
}
return $authors;
}
Exclude specific authors
Exclude specific authors from the list of editable authors by their user IDs.
add_filter( 'get_editable_authors', 'exclude_specific_authors', 10, 1 );
function exclude_specific_authors( $authors ) {
$exclude_ids = array( 3, 5, 7 ); // User IDs to exclude
foreach ( $authors as $key => $author ) {
if ( in_array( $author->ID, $exclude_ids ) ) {
unset( $authors[ $key ] );
}
}
return $authors;
}
Add custom authors
Add custom authors to the list of editable authors.
add_filter( 'get_editable_authors', 'add_custom_authors', 10, 1 );
function add_custom_authors( $authors ) {
$custom_authors = array( 9, 11, 13 ); // User IDs of custom authors
foreach ( $custom_authors as $user_id ) {
$user = get_userdata( $user_id );
if ( $user ) {
$authors[] = $user;
}
}
return $authors;
}
Limit authors based on post count
Only allow authors who have written at least 5 posts to edit posts.
add_filter( 'get_editable_authors', 'limit_authors_by_post_count', 10, 1 );
function limit_authors_by_post_count( $authors ) {
foreach ( $authors as $key => $author ) {
if ( count_user_posts( $author->ID ) < 5 ) {
unset( $authors[ $key ] );
}
}
return $authors;
}
Limit authors based on registration date
Only allow authors who registered more than 30 days ago to edit posts.
add_filter( 'get_editable_authors', 'limit_authors_by_registration_date', 10, 1 );
function limit_authors_by_registration_date( $authors ) {
$date_limit = strtotime( '-30 days' );
foreach ( $authors as $key => $author ) {
if ( strtotime( $author->user_registered ) > $date_limit ) {
unset( $authors[ $key ] );
}
}
return $authors;
}