Co-Authors-Plus icon indicating copy to clipboard operation
Co-Authors-Plus copied to clipboard

Preselect Guest Users when new post is created

Open jaspindersingh91ie opened this issue 3 years ago • 4 comments

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 ?

jaspindersingh91ie avatar Sep 27 '21 04:09 jaspindersingh91ie

@lschuyler Can you please look into this?

rebeccahum avatar Oct 01 '21 22:10 rebeccahum

@lschuyler, any update on this ?

jaspindersingh91ie avatar Oct 20 '21 11:10 jaspindersingh91ie

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 avatar Nov 06 '21 21:11 lschuyler

@lschuyler, Can we set multiple default authors ??

udaydahale avatar Jun 24 '22 11:06 udaydahale