Co-Authors-Plus
Co-Authors-Plus copied to clipboard
Preselect Guest Users when new post is created
There is a filter 'coauthors_default_author' which allows to preselect 1 or multiple WordPress Users in the auto suggest box when a new post is created. This filter does not allow Guest Authors to be preselected in the auto suggest box.
Is there a way to have WordPress users as well as Guest Authors to be preselected in the auto suggest box ?
@lschuyler Can you please look into this?
@lschuyler, any update on this ?
Hi @jaspindersingh91ie,
Yes, you can use the 'coauthors_default_author' filter to specify a guest author to be the default pre-selected in the author box.
Here's how you can do it by specifying a guest author's id from the wp_posts table:
add_filter( 'coauthors_default_author', 'set_a_default_guest_author' );
function set_a_default_guest_author( $default_user ) {
global $coauthors_plus;
// need the post_id for the guest author
return $coauthors_plus->guest_authors->get_guest_author_by( 'ID', 59 );
}
You can also use user_nicename
, user_login
, or user_email
instead of the the id
key (these are defined here).
I've tested this out in a theme's functions.php file with success, adding a test to be sure the plugin is active:
if ( ! function_exists( 'is_plugin_active' ) ) {
include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
}
// if CAP is enabled:
if ( is_plugin_active('co-authors-plus/co-authors-plus.php') ) {
add_filter( 'coauthors_default_author', 'set_a_default_guest_author' );
function set_a_default_guest_author( $default_user ) {
global $coauthors_plus;
// need the post_id for the guest author
return $coauthors_plus->guest_authors->get_guest_author_by( 'ID', 59 );
}
}
Does something like this suit your needs?
@lschuyler, Can we set multiple default authors ??