Changeset 7570 for trunk/bp-activity/bp-activity-functions.php
- Timestamp:
- 11/14/2013 03:43:43 PM (13 years ago)
- File:
-
- 1 edited
-
trunk/bp-activity/bp-activity-functions.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/bp-activity/bp-activity-functions.php
r7469 r7570 73 73 // We've found some mentions! Check to see if users exist 74 74 foreach( (array) $usernames as $key => $username ) { 75 if ( bp_is_username_compatibility_mode() ) { 76 $user_id = username_exists( $username ); 77 } else { 78 $user_id = bp_core_get_userid_from_nicename( $username ); 79 } 75 $user_id = bp_activity_get_userid_from_mentionname( $username ); 80 76 81 77 // user ID exists, so let's add it to our array … … 246 242 247 243 return $return; 244 } 245 246 /** 247 * Determine a user's "mentionname", the name used for that user in @-mentions. 248 * 249 * @since BuddyPress (1.9.0) 250 * 251 * @return string User name appropriate for @-mentions. 252 */ 253 function bp_activity_get_user_mentionname( $user_id ) { 254 $mentionname = ''; 255 256 $userdata = bp_core_get_core_userdata( $user_id ); 257 258 if ( $userdata ) { 259 if ( bp_is_username_compatibility_mode() ) { 260 $mentionname = str_replace( ' ', '-', $userdata->user_login ); 261 } else { 262 $mentionname = $userdata->user_nicename; 263 } 264 } 265 266 return $mentionname; 267 } 268 269 /** 270 * Get a user ID from a "mentionname", the name used for a user in @-mentions. 271 * 272 * @since BuddyPress (1.9.0) 273 * 274 * @return int|bool ID of the user, if one is found. Otherwise false. 275 */ 276 function bp_activity_get_userid_from_mentionname( $mentionname ) { 277 $user_id = false; 278 279 // In username compatibility mode, hyphens are ambiguous between 280 // actual hyphens and converted spaces. 281 // 282 // @todo There is the potential for username clashes between 'foo bar' 283 // and 'foo-bar' in compatibility mode. Come up with a system for 284 // unique mentionnames. 285 if ( bp_is_username_compatibility_mode() ) { 286 // First, try the raw username 287 $userdata = get_user_by( 'login', $mentionname ); 288 289 // Doing a direct query to use proper regex. Necessary to 290 // account for hyphens + spaces in the same user_login. 291 if ( empty( $userdata ) || ! is_a( $userdata, 'WP_User' ) ) { 292 global $wpdb; 293 $regex = esc_sql( str_replace( '-', '[ \-]', $mentionname ) ); 294 $user_id = $wpdb->get_var( "SELECT ID FROM {$wpdb->users} WHERE user_login REGEXP '{$regex}'" ); 295 } else { 296 $user_id = $userdata->ID; 297 } 298 299 // When username compatibility mode is disabled, the mentionname is 300 // the same as the nicename 301 } else { 302 $user_id = bp_core_get_userid_from_nicename( $mentionname ); 303 } 304 305 306 return $user_id; 248 307 } 249 308
Note: See TracChangeset
for help on using the changeset viewer.