bp_get_userid_from_mentionname( string $mentionname )
Get a user ID from a “mentionname”, the name used for a user in @-mentions.
Description
Parameters
- $mentionname
-
(Required) Username of user in @-mentions.
Return
(int|bool) ID of the user, if one is found. Otherwise false.
Source
File: bp-core/bp-core-functions.php
function bp_get_userid_from_mentionname( $mentionname ) { $user_id = false; /* * In username compatibility mode, hyphens are ambiguous between * actual hyphens and converted spaces. * * @todo There is the potential for username clashes between 'foo bar' * and 'foo-bar' in compatibility mode. Come up with a system for * unique mentionnames. */ if ( bp_is_username_compatibility_mode() ) { // First, try the raw username. $userdata = get_user_by( 'login', $mentionname ); // Doing a direct query to use proper regex. Necessary to // account for hyphens + spaces in the same user_login. if ( empty( $userdata ) || ! is_a( $userdata, 'WP_User' ) ) { global $wpdb; $regex = esc_sql( str_replace( '-', '[ \-]', $mentionname ) ); $user_id = $wpdb->get_var( "SELECT ID FROM {$wpdb->users} WHERE user_login REGEXP '{$regex}'" ); } else { $user_id = $userdata->ID; } // When username compatibility mode is disabled, the mentionname is // the same as the nicename. } else { $user_id = bp_core_get_userid_from_nickname( $mentionname ); } return $user_id; }
Changelog
Version | Description |
---|---|
BuddyBoss 1.2.8 | Introduced. |
Questions?
We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.