Plugin / Authors Autocomplete Meta Box

Rachel Carden

Description

Description

Replaces the default WordPress Author meta box (that has an author dropdown) with a meta box that allows you to select the post’s, or page’s, author via Autocomplete.

Can really come in handy if you have a lot of authors and are tired of scrolling through that long author dropdown.

Credits

Big shoutout to ereleases.com for commissioning this plugin and letting me share it with the community. Thanks, guys. You rock!

Lots of thanks to Andrew Kurtis from WebHostingHub Support for providing the Spanish translation.

Filters

Filters can really come in handy to nail down specific customizations on a site by site basis. I am what you would consider a power user so I’m a big fan of actions and filters and try to incorporate them into my plugins as much as possible. Here are some pretty helpful filters to get your authors autocomplete meta box working just the way you like.

authors_autocomplete_mb_allow_user_id

This filter allows you to block users from the autocomplete results according to user id. Return true to allow and false to deny.

It passes the user id, along with the post ID and post type. Don’t forget: when using a filter, you MUST return something. Here’s an example to help you get started:

<?php

// return *true* to allow the user and *false* to deny the user from autocomplete results
add_filter( 'authors_autocomplete_mb_allow_user_id', 'filter_authors_autocomplete_mb_allow_user_id', 1, 4 );
function filter_authors_autocomplete_mb_allow_user_id( $allow_user_id, $user_id, $post_id, $post_type ) {
    if ( $user_id == 4 )
        return false;
    return $allow_user_id;
}
?>

authors_autocomplete_mb_allow_user_role

This filter allows you to block users from the autocomplete results according to user role. Return true to allow and false to deny.

It passes the user role, along with the post ID and post type. Don’t forget: when using a filter, you MUST return something. Here’s an example to help you get started:

<?php

// return *true* to allow the user and *false* to deny the user from autocomplete results
add_filter( 'authors_autocomplete_mb_allow_user_role', 'filter_authors_autocomplete_mb_allow_user_role', 1, 4 );
function filter_authors_autocomplete_mb_allow_user_role( $allow_user_role, $user_role, $post_id, $post_type ) {
    if ( $user_role == 'administrator' )
        return false;
    return $allow_user_role;
}
?>

authors_autocomplete_mb_author_capability

When checking to see if a user has author privileges, and should therefore be included in the autocomplete results, the plugin checks the user’s capabilities. If the user is editing a page, then the user is added if they have the capability to edit_pages, otherwise the user is added if they have the capability to edit_posts.

If you would like to change the author privilege capability, then this filter is for you. It passes the default capability, along with the post ID and post type. Don’t forget: when using a filter, you MUST return something. Here’s an example to help you get started:

<?php
// changing the author capability according to post type
add_filter( 'authors_autocomplete_mb_author_capability', 'filter_authors_autocomplete_mb_author_capability', 1, 3 );
function filter_authors_autocomplete_mb_author_capability( $author_capability, $post_id, $post_type ) {
    if ( $post_type == 'movies' )
        return 'edit_movies';
    return $author_capability;
}
?>

authors_autocomplete_mb_custom_user_search_user_ids

Want the autocomplete box to search information besides the default user_login, display_name and user_email? This is the filter for you.

Use this filter to run whatever search you like and simply return the user IDs from your results.

It passes a blank array to get you started, the search term, post ID and post type. Don’t forget: when using a filter, you MUST return something.

Here’s an example from me helping a user search their CIMY User Extra Fields:

<?php
// search CIMY User Extra Fields with search term and return user IDs
add_filter( 'authors_autocomplete_mb_custom_user_search_user_ids', 'authors_autocomplete_custom_user_search', 1, 4 );
function authors_autocomplete_custom_user_search( $user_ids, $search_term, $post_id, $post_type ) {
   global $wpdb;
   return $wpdb->get_col( "SELECT users.ID, cimy_uef_data.VALUE FROM $wpdb->users users LEFT JOIN {$wpdb->prefix}cimy_uef_data cimy_uef_data ON cimy_uef_data.USER_ID = users.ID WHERE ( cimy_uef_data.VALUE LIKE '%$search_term%' OR users.user_login LIKE '%$search_term%' OR users.display_name LIKE '%$search_term%' OR users.user_email LIKE '%$search_term%' ) ORDER BY users.ID ASC" );
}
?>

DIRECTORY DISCLAIMER

The information provided in this THEME/PLUGIN DIRECTORY is made available for information purposes only, and intended to serve as a resource to enable visitors to select a relevant theme or plugin. wpSocket gives no warranty of any kind, express or implied with regard to the information, including without limitation any warranty that the particular theme or plugin that you select is qualified on your situation.

The information in the individual theme or plugin displayed in the Directory is provided by the owners and contributors themselves. wpSocket gives no warranty as to the accuracy of the information and will not be liable to you for any loss or damage suffered by you as a consequence of your reliance on the information.

Links to respective sites are offered to assist in accessing additional information. The links may be outdated or broken. Connect to outside sites at your own risk. The Theme/Plugin Directory does not endorse the content or accuracy of any listing or external website.

While information is made available, no guarantee is given that the details provided are correct, complete or up-to-date.

wpSocket is not related to the theme or plugin, and also not responsible and expressly disclaims all liability for, damages of any kind, arising out of the use, reference to, or reliance on, any information or business listed throughout our site.

Keep Leading Your Followers!
Share it for them.