jQuery.noConflict()(function(){ // Handle autocomplete for authors jQuery( '#authors_autocomplete_mb_authordiv' ).each( function() { // this is the authors autocomplete input var $authors_autocomplete_mb_input = jQuery( 'input#authors_autocomplete_mb_post_author' ); // remove the hidden authors dropdown to remove any $_POST confusion jQuery( '#authors_autocomplete_mb_dropdown' ).remove(); // autocomplete new tags if ( $authors_autocomplete_mb_input.size() > 0 ) { $authors_autocomplete_mb_input.autocomplete({ delay: 100, minLength: 1, source: function( $request, $response ){ jQuery.ajax({ url: ajaxurl, type: 'POST', async: true, cache: false, dataType: 'json', data: { action: 'authors_autocomplete_mb_autocomplete_callback', authors_autocomplete_mb_search_term: $request.term }, success: function( $data ){ $response( jQuery.map( $data, function( $item ) { return { user_id: $item.user_id, user_login: $item.user_login, display_name: $item.display_name, email: $item.email, value: $item.label, label: $item.label }; })); } }); }, search: function( $event, $ui ) { authors_autocomplete_mb_remove_error_message(); }, select: function( $event, $ui ) { // stop the loading spinner authors_autocomplete_mb_stop_loading_spinner(); // make sure any errors are removed authors_autocomplete_mb_remove_error_message(); // change the saved post author authors_autocomplete_mb_change_post_author( $ui.item.user_id, $ui.item.display_name ); }, response: function( $event, $ui ) { authors_autocomplete_mb_stop_loading_spinner(); }, focus: function( $event, $ui ) { authors_autocomplete_mb_stop_loading_spinner(); }, close: function( $event, $ui ) { authors_autocomplete_mb_stop_loading_spinner(); }, change: function( $event, $ui ) { // stop the loading spinner authors_autocomplete_mb_stop_loading_spinner(); // remove any existing message authors_autocomplete_mb_remove_error_message(); // get the saved author display name. we'll need it later. var $saved_author_display_name = jQuery( '#authors_autocomplete_mb_post_author_override_display_name' ).val(); // convert to saved author display name if ( $authors_autocomplete_mb_input.val() == '' ) $authors_autocomplete_mb_input.val( $saved_author_display_name ); // see if what they entered is actual user else { // save what the user entered var $entered_user_value = $authors_autocomplete_mb_input.val(); // see if the user exists jQuery.ajax({ url: ajaxurl, type: 'POST', async: true, cache: false, dataType: 'json', data: { action: 'authors_autocomplete_mb_if_user_exists_by_value', authors_autocomplete_mb_user_value: $entered_user_value }, success: function( $user ){ // if the user exists if ( $user ) { // change the saved post author authors_autocomplete_mb_change_post_author( $user.ID, $user.display_name ); } else { // convert to saved author display name $authors_autocomplete_mb_input.val( $saved_author_display_name ); // show an error message authors_autocomplete_mb_add_error_message( "The author '" + $entered_user_value + "' does not exist." ); } } }); } } }).data( "ui-autocomplete" )._renderItem = function( $ul, $item ) { return jQuery( '