Ticket #19867: wp_suggest_users.alpha.1.diff
File wp_suggest_users.alpha.1.diff, 7.4 KB (added by , 12 years ago) |
---|
-
wp-includes/user.php
1023 1023 'include' => '', 'exclude' => '', 'multi' => 0, 1024 1024 'show' => 'display_name', 'echo' => 1, 1025 1025 'selected' => 0, 'name' => 'user', 'class' => '', 'id' => '', 1026 'blog_id' => $GLOBALS['blog_id'], 'who' => '', 'include_selected' => false 1026 'blog_id' => $GLOBALS['blog_id'], 'who' => '', 'include_selected' => false, 1027 'select_max' => 1000, 'suggest_max' => false, 'autocomplete' => false, 1027 1028 ); 1028 1029 1029 1030 $defaults['selected'] = is_author() ? get_query_var( 'author' ) : 0; 1030 1031 1031 1032 $r = wp_parse_args( $args, $defaults ); 1033 1034 //lets bail if we have a large network or a ton of users 1035 $site_user_count = get_user_count(); 1036 if( $site_user_count > $r['select_max'] OR @$r['autocomplete'] ) 1037 return wp_suggest_users( $r ); 1038 1032 1039 extract( $r, EXTR_SKIP ); 1033 1040 1034 1041 $query_args = wp_array_slice_assoc( $r, array( 'blog_id', 'include', 'exclude', 'orderby', 'order', 'who' ) ); … … 1082 1089 } 1083 1090 1084 1091 /** 1092 * Create an autocomplete HTML field for users. 1093 * 1094 * The content can either be displayed, which it is by default or retrieved by 1095 * setting the 'echo' argument. The 'include' and 'exclude' arguments do not 1096 * need to be used; all users will be displayed in that case. Only one can be 1097 * used, either 'include' or 'exclude', but not both. 1098 * @todo Document options 1099 * @todo pass include exclude values to JS 1100 * @todo test front end usage 1101 * 1102 **/ 1103 function wp_suggest_users( $args ) { 1104 $defaults = array( 1105 'include' => '', 'exclude' => '', 'multi' => 0, 'type'=> 'search', 1106 'show' => 'display_name', 'echo' => 1, 'selected' => 0, 1107 'name' => 'user', 'class' => '', 'id' => 'user', 1108 'blog_id' => $GLOBALS['blog_id'], 'who' => '', 'include_selected' => false, 1109 'table_wrap' => true, 'limit' => 1000, 1110 ); 1111 1112 $defaults['selected'] = is_author() ? get_query_var( 'author' ) : 0; 1113 1114 extract( wp_parse_args( $args, $defaults ), EXTR_SKIP ); 1115 1116 wp_enqueue_script('user-suggest'); 1117 1118 //if a selected user was passed lets's get their display fiels 1119 if( $selected > 0 ) { 1120 if( is_array( $selected ) ) { 1121 $users = array(); 1122 foreach( $selected as $user ) { 1123 $user = get_userdata( $user ); 1124 $users[] = $user->data->$show; 1125 } 1126 $selected = implode(', ', $users); 1127 } else { 1128 $user = get_userdata( $selected ); 1129 $selected = $user->data->$show; 1130 $selected_value = $user->data->ID; 1131 } 1132 } else { 1133 $selected = false; 1134 } 1135 1136 1137 $output = ''; 1138 $label = __('E-mail or Username'); 1139 $label = "<label for='post_author'>$label</label>"; 1140 $input = "<input name='$name' type='text' id='$id' class='wp-suggest-user $class' data-original='$selected' data-target='$name' data-type='$type' data-limit='$limit' data-return-field='$show' data-include='$include' data-exclude='$exclude' value='$selected' />\n"; 1141 1142 //if we're in the admin lets wrap in the standard form table class 1143 if( is_admin() OR @$table_wrap ) 1144 $output = "<table class='form-table'><tr class='form-field'>\n<th scope='row'>$label</th>\n<td>$input\n</td>\n</tr></table>"; 1145 else 1146 $output = "$label\n$input"; 1147 1148 $output = apply_filters( 'wp-suggest-users', $output ); 1149 1150 if( $echo ) 1151 echo $output; 1152 1153 return $output; 1154 } 1155 1156 /** 1085 1157 * Sanitize user field based on context. 1086 1158 * 1087 1159 * Possible context values are: 'raw', 'edit', 'db', 'display', 'attribute' and 'js'. The -
wp-admin/includes/ajax-actions.php
167 167 168 168 $include_blog_users = ( $type == 'search' ? get_users( array( 'blog_id' => $id, 'fields' => 'ID' ) ) : array() ); 169 169 $exclude_blog_users = ( $type == 'add' ? get_users( array( 'blog_id' => $id, 'fields' => 'ID' ) ) : array() ); 170 171 $number = @$_REQUEST['number'] ?: ''; 170 172 171 173 $users = get_users( array( 172 174 'blog_id' => false, … … 174 176 'include' => $include_blog_users, 175 177 'exclude' => $exclude_blog_users, 176 178 'search_columns' => array( 'user_login', 'user_nicename', 'user_email' ), 179 'number' => $number, 177 180 ) ); 178 181 182 $return_field = @$_REQUEST['return_field'] ?: 'user_login'; 183 179 184 foreach ( $users as $user ) { 180 185 $return[] = array( 181 186 /* translators: 1: user_login, 2: user_email */ 182 187 'label' => sprintf( __( '%1$s (%2$s)' ), $user->user_login, $user->user_email ), 183 'value' => $user-> user_login,188 'value' => $user->$return_field, 184 189 ); 190 185 191 } 186 192 187 193 wp_die( json_encode( $return ) ); -
wp-admin/includes/post.php
56 56 $post_data['user_ID'] = $GLOBALS['user_ID']; 57 57 58 58 if (!empty ( $post_data['post_author_override'] ) ) { 59 if( is_string( $post_data['post_author_override'] ) ) { 60 //check for commas cuz we can only have one 61 $postauthor = $post_data['post_author_override']; 62 if( strpos( $postpostauthor , ',') ) 63 $postauthor = substr( $postauthor , 0, strpos( $postauthor , ',') ); 64 $postauthor = get_user_by( 'login', $postauthor ); 65 $post_data['post_author_override'] = $postauthor->data->ID; 66 } 59 67 $post_data['post_author'] = (int) $post_data['post_author_override']; 60 68 } else { 61 69 if (!empty ( $post_data['post_author'] ) ) { -
wp-admin/includes/meta-boxes.php
591 591 'who' => 'authors', 592 592 'name' => 'post_author_override', 593 593 'selected' => empty($post->ID) ? $user_ID : $post->post_author, 594 'include_selected' => true 594 'include_selected' => true, 595 'limit' => 100, 596 'show' => 'user_login', 595 597 ) ); 596 598 } 597 599 … … 979 981 function post_thumbnail_meta_box( $post ) { 980 982 $thumbnail_id = get_post_meta( $post->ID, '_thumbnail_id', true ); 981 983 echo _wp_post_thumbnail_html( $thumbnail_id, $post->ID ); 982 } 983 No newline at end of file 984 } -
wp-admin/js/user-suggest.js
1 1 (function($) { 2 2 var id = 'undefined' !== typeof current_site_id ? '&site_id=' + current_site_id : ''; 3 $(document).ready( function() { 3 $(document).ready( function() { 4 var type = $('.wp-suggest-user').attr('data-type'); 5 type = 'undefined' !== typeof type ? '&autocomplete_type=' + type : ''; 6 var return_field = $('.wp-suggest-user').attr('data-return-field'); 7 return_field = 'undefined' !== typeof return_field ? '&return_field=' + return_field : ''; 8 var limit = $('.wp-suggest-user').attr('data-limit'); 9 limit = 'undefined' !== typeof limit ? '&number=' + limit : '' ; 10 4 11 $( '.wp-suggest-user' ).autocomplete({ 5 source: ajaxurl + '?action=autocomplete-user &autocomplete_type=add' + id,12 source: ajaxurl + '?action=autocomplete-user' + type + id + return_field + limit, 6 13 delay: 500, 7 14 minLength: 2, 8 15 position: ( 'undefined' !== typeof isRtl && isRtl ) ? { my: 'right top', at: 'right bottom', offset: '0, -1' } : { offset: '0, -1' }, … … 10 17 close: function() { $(this).removeClass('open'); } 11 18 }); 12 19 }); 13 })(jQuery); 14 No newline at end of file 20 })(jQuery);