Stop loading “collaborators” users on add new post or page?

So our website has about 20k “collaborators” type of users and we’d like to stop loading all of them on the select box on the “add new post” or “add new page” PAGE. Maybe load only authors and above type of users using functions.php

Could anybody help? =)

1 Answer
1

This meta box is using the function wp_dropdown_users() to list all users. It has only one filter to change the output: wp_dropdown_users.

But this filter offers just the complete markup and users. It’s neither easy nor fast to parse this via regex for user names, check their roles and then give back an new HTML.

I think the best way is to deactivate this meta box.

remove_meta_box('authordiv', 'post', 'normal');

And then you create a custom meta box via plugin and list the authors of your blog only.

This small plugin does exactly that.

<?php
/**
 * Plugin Name: Author Meta Box only with authors
 * Plugin URI:  http://wordpress.stackexchange.com/questions/60429/stop-loading-collaborators-users-on-add-new-post-or-page
 * Description: 
 * Author:      Frank Bültge
 * Author URI:  http://bueltge.de
 * License:     GPLv3
 */
add_action( 'admin_menu', 'fb_remove_author_meta_boxes' );
function fb_remove_author_meta_boxes() {

    remove_meta_box('authordiv', 'post', 'normal');
    add_meta_box('fb_authordiv', __('Author'), 'fb_post_author_meta_box', 'post', 'normal', 'core');
}

function fb_post_author_meta_box( $post ) {
    global $user_ID;

    // get all authors
    $wp_user_search = new WP_User_Search( '', '', 'author' );
    $authors        = join( ', ', $wp_user_search->get_results() ); // user IDs
    ?>
    <label class="screen-reader-text" for="post_author_override"><?php _e('Author'); ?></label>
    <?php
    wp_dropdown_users( array(
        'include' => $authors,
        'who' => 'authors',
        'name' => 'post_author_override',
        'selected' => empty($post->ID) ? $user_ID : $post->post_author,
        'include_selected' => true
    ) );
}

Gist 3225957 for Download

Leave a Comment