diff --git bp-activity/bp-activity-functions.php bp-activity/bp-activity-functions.php
index 6e5cb56..ab2feeb 100644
|
|
function bp_activity_find_mentions( $content ) { |
72 | 72 | |
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 | // Note: we always use the nicename for @-mentions, even with |
| 76 | // username_compatibility_mode() |
| 77 | $user_id = bp_core_get_userid_from_nicename( $username ); |
80 | 78 | |
81 | 79 | // user ID exists, so let's add it to our array |
82 | 80 | if ( ! empty( $user_id ) ) { |
diff --git bp-activity/bp-activity-template.php bp-activity/bp-activity-template.php
index a5dd724..75d23f9 100644
|
|
function bp_has_activities( $args = '' ) { |
583 | 583 | } |
584 | 584 | |
585 | 585 | // Start search at @ symbol and stop search at closing tag delimiter. |
586 | | $search_terms = '@' . bp_core_get_username( $user_id ) . '<'; |
| 586 | $search_terms = '@' . bp_members_get_user_nicename( $user_id ) . '<'; |
587 | 587 | $display_comments = 'stream'; |
588 | 588 | $user_id = 0; |
589 | 589 | break; |
… |
… |
function bp_send_public_message_link() { |
2719 | 2719 | if ( bp_is_my_profile() || !is_user_logged_in() ) |
2720 | 2720 | return false; |
2721 | 2721 | |
2722 | | return apply_filters( 'bp_get_send_public_message_link', wp_nonce_url( bp_get_activity_directory_permalink() . '?r=' . bp_core_get_username( bp_displayed_user_id(), bp_get_displayed_user_username(), $bp->displayed_user->userdata->user_login ) ) ); |
| 2722 | return apply_filters( 'bp_get_send_public_message_link', wp_nonce_url( bp_get_activity_directory_permalink() . '?r=' . bp_get_displayed_user_nicename() ) ); |
2723 | 2723 | } |
2724 | 2724 | |
2725 | 2725 | /** |
diff --git bp-members/bp-members-functions.php bp-members/bp-members-functions.php
index 9289d1a..bdaa937 100644
|
|
function bp_core_get_username( $user_id = 0, $user_nicename = false, $user_login |
269 | 269 | $update_cache = false; |
270 | 270 | } |
271 | 271 | |
272 | | // Check $username for empty spaces and default to nicename if found |
273 | | if ( strstr( $username, ' ' ) ) { |
274 | | $username = bp_members_get_user_nicename( $user_id ); |
275 | | } |
276 | | |
277 | 272 | // Add this to cache |
278 | 273 | if ( ( true === $update_cache ) && !empty( $username ) ) { |
279 | 274 | wp_cache_set( 'bp_user_username_' . $user_id, $username, 'bp' ); |
… |
… |
function bp_core_ucfirst( $str ) { |
945 | 940 | } |
946 | 941 | |
947 | 942 | /** |
948 | | * Strips spaces from usernames that are created using add_user() and wp_insert_user() |
949 | | * |
950 | | * @package BuddyPress Core |
951 | | */ |
952 | | function bp_core_strip_username_spaces( $username ) { |
953 | | // Don't alter the user_login of existing users, as it causes user_nicename problems. |
954 | | // See http://trac.buddypress.org/ticket/2642 |
955 | | if ( username_exists( $username ) && ( !bp_is_username_compatibility_mode() ) ) |
956 | | return $username; |
957 | | |
958 | | return str_replace( ' ', '-', $username ); |
959 | | } |
960 | | add_action( 'pre_user_login', 'bp_core_strip_username_spaces' ); |
961 | | |
962 | | /** |
963 | 943 | * When a user logs in, check if they have been marked as a spammer. If yes then simply |
964 | 944 | * redirect them to the home page and stop them from logging in. |
965 | 945 | * |
… |
… |
function bp_core_add_validation_error_messages( WP_Error $errors, $validation_re |
1171 | 1151 | */ |
1172 | 1152 | function bp_core_validate_user_signup( $user_name, $user_email ) { |
1173 | 1153 | |
1174 | | $errors = new WP_Error(); |
1175 | | |
1176 | | // Apply any user_login filters added by BP or other plugins before validating |
1177 | | $user_name = apply_filters( 'pre_user_login', $user_name ); |
1178 | | |
1179 | | if ( empty( $user_name ) ) |
1180 | | $errors->add( 'user_name', __( 'Please enter a username', 'buddypress' ) ); |
1181 | | |
1182 | 1154 | // Make sure illegal names include BuddyPress slugs and values |
1183 | 1155 | bp_core_flush_illegal_names(); |
1184 | 1156 | |
1185 | | $illegal_names = get_site_option( 'illegal_names' ); |
| 1157 | // WordPress Multisite has its own validation. Use it, so that we |
| 1158 | // properly mirror restrictions on username, etc. |
| 1159 | if ( function_exists( 'wpmu_validate_user_signup' ) ) { |
| 1160 | $result = wpmu_validate_user_signup( $user_name, $user_email ); |
| 1161 | |
| 1162 | // What follows reproduces much of the logic of |
| 1163 | // wpmu_validate_user_signup(), minus the multisite-specific |
| 1164 | // restrictions on user_login |
| 1165 | } else { |
| 1166 | $errors = new WP_Error(); |
1186 | 1167 | |
1187 | | if ( in_array( $user_name, (array) $illegal_names ) ) |
1188 | | $errors->add( 'user_name', __( 'That username is not allowed', 'buddypress' ) ); |
| 1168 | // Apply any user_login filters added by BP or other plugins before validating |
| 1169 | $user_name = apply_filters( 'pre_user_login', $user_name ); |
1189 | 1170 | |
1190 | | if ( ! validate_username( $user_name ) ) { |
1191 | | // Check for capital letters when on multisite. |
1192 | | // |
1193 | | // If so, throw a different error message. |
1194 | | // @see #5175 |
1195 | | if ( is_multisite() ) { |
1196 | | $match = array(); |
1197 | | preg_match( '/[A-Z]/', $user_name, $match ); |
1198 | | |
1199 | | if ( ! empty( $match ) ) { |
1200 | | $errors->add( 'user_name', __( 'Username must be in lowercase characters', 'buddypress' ) ); |
1201 | | } |
| 1171 | // User name can't be empty |
| 1172 | if ( empty( $user_name ) ) { |
| 1173 | $errors->add( 'user_name', __( 'Please enter a username', 'buddypress' ) ); |
| 1174 | } |
1202 | 1175 | |
1203 | | } else { |
1204 | | $errors->add( 'user_name', __( 'Usernames can contain only letters, numbers, ., -, and @', 'buddypress' ) ); |
| 1176 | // User name can't be on the blacklist |
| 1177 | $illegal_names = get_site_option( 'illegal_names' ); |
| 1178 | if ( in_array( $user_name, (array) $illegal_names ) ) { |
| 1179 | $errors->add( 'user_name', __( 'That username is not allowed', 'buddypress' ) ); |
1205 | 1180 | } |
1206 | | } |
1207 | 1181 | |
1208 | | if( strlen( $user_name ) < 4 ) |
1209 | | $errors->add( 'user_name', __( 'Username must be at least 4 characters', 'buddypress' ) ); |
| 1182 | // User name must pass WP's check for validity |
| 1183 | if ( ! validate_username( $user_name ) ) { |
| 1184 | $errors->add( 'user_name', __( 'Usernames can contain only letters, numbers, ., -, and @', 'buddypress' ) ); |
| 1185 | } |
1210 | 1186 | |
1211 | | if ( strpos( ' ' . $user_name, '_' ) != false ) |
1212 | | $errors->add( 'user_name', __( 'Sorry, usernames may not contain the character "_"!', 'buddypress' ) ); |
| 1187 | // Minimum of 4 characters |
| 1188 | if ( strlen( $user_name ) < 4 ) { |
| 1189 | $errors->add( 'user_name', __( 'Username must be at least 4 characters', 'buddypress' ) ); |
| 1190 | } |
1213 | 1191 | |
1214 | | // Is the user_name all numeric? |
1215 | | $match = array(); |
1216 | | preg_match( '/[0-9]*/', $user_name, $match ); |
| 1192 | // No underscores. @todo Why? |
| 1193 | if ( false !== strpos( $user_name, '_' ) ) { |
| 1194 | $errors->add( 'user_name', __( 'Sorry, usernames may not contain the character "_"!', 'buddypress' ) ); |
| 1195 | } |
1217 | 1196 | |
1218 | | if ( $match[0] == $user_name ) |
1219 | | $errors->add( 'user_name', __( 'Sorry, usernames must have letters too!', 'buddypress' ) ); |
| 1197 | // Is the user_name all numeric? |
| 1198 | $match = array(); |
| 1199 | preg_match( '/[0-9]*/', $user_name, $match ); |
| 1200 | if ( $match[0] == $user_name ) { |
| 1201 | $errors->add( 'user_name', __( 'Sorry, usernames must have letters too!', 'buddypress' ) ); |
| 1202 | } |
1220 | 1203 | |
1221 | | // Check if the username has been used already. |
1222 | | if ( username_exists( $user_name ) ) |
1223 | | $errors->add( 'user_name', __( 'Sorry, that username already exists!', 'buddypress' ) ); |
| 1204 | // Check if the username has been used already. |
| 1205 | if ( username_exists( $user_name ) ) { |
| 1206 | $errors->add( 'user_name', __( 'Sorry, that username already exists!', 'buddypress' ) ); |
| 1207 | } |
1224 | 1208 | |
1225 | | // Validate the email address and process the validation results into |
1226 | | // error messages |
1227 | | $validate_email = bp_core_validate_email_address( $user_email ); |
1228 | | bp_core_add_validation_error_messages( $errors, $validate_email ); |
| 1209 | // Validate the email address and process the validation results into |
| 1210 | // error messages |
| 1211 | $validate_email = bp_core_validate_email_address( $user_email ); |
| 1212 | bp_core_add_validation_error_messages( $errors, $validate_email ); |
1229 | 1213 | |
1230 | | // Assemble the return array |
1231 | | $result = array( 'user_name' => $user_name, 'user_email' => $user_email, 'errors' => $errors ); |
| 1214 | // Assemble the return array |
| 1215 | $result = array( |
| 1216 | 'user_name' => $user_name, |
| 1217 | 'user_email' => $user_email, |
| 1218 | 'errors' => $errors, |
| 1219 | ); |
1232 | 1220 | |
1233 | | // Apply WPMU legacy filter |
1234 | | $result = apply_filters( 'wpmu_validate_user_signup', $result ); |
| 1221 | // Apply WPMU legacy filter |
| 1222 | $result = apply_filters( 'wpmu_validate_user_signup', $result ); |
| 1223 | } |
1235 | 1224 | |
1236 | 1225 | return apply_filters( 'bp_core_validate_user_signup', $result ); |
1237 | 1226 | } |
diff --git bp-members/bp-members-template.php bp-members/bp-members-template.php
index c971959..27dfbc9 100644
|
|
function bp_displayed_user_username() { |
951 | 951 | return apply_filters( 'bp_get_displayed_user_username', $username ); |
952 | 952 | } |
953 | 953 | |
| 954 | /** |
| 955 | * Output the user_nicename for the displayed user. |
| 956 | * |
| 957 | * @since BuddyPress (1.9.0) |
| 958 | */ |
| 959 | function bp_displayed_user_nicename() { |
| 960 | echo bp_get_displayed_user_nicename(); |
| 961 | } |
| 962 | /** |
| 963 | * Get the user_nicename for the displayed user. |
| 964 | * |
| 965 | * Use this function when you know you need the user_nicename. |
| 966 | * bp_get_displayed_user_username() is a more general function that |
| 967 | * accounts for the use of BP_ENABLE_USERNAME_COMPATIBILITY_MODE and |
| 968 | * other non-standard settings. |
| 969 | * |
| 970 | * @since BuddyPress (1.9.0) |
| 971 | * |
| 972 | * @return string user_nicename for the displayed user, if available. |
| 973 | */ |
| 974 | function bp_get_displayed_user_nicename() { |
| 975 | if ( bp_displayed_user_id() ) { |
| 976 | $user_nicename = buddypress()->displayed_user->userdata->user_nicename; |
| 977 | } else { |
| 978 | $user_nicename = ''; |
| 979 | } |
| 980 | |
| 981 | return apply_filters( 'bp_get_displayed_user_nicename', $user_nicename ); |
| 982 | } |
| 983 | |
954 | 984 | function bp_loggedin_user_username() { |
955 | 985 | echo bp_get_loggedin_user_username(); |
956 | 986 | } |
diff --git bp-messages/bp-messages-functions.php bp-messages/bp-messages-functions.php
index c90c8c3..c97507f 100644
|
|
function messages_new_message( $args = '' ) { |
77 | 77 | // check user_login / nicename columns first |
78 | 78 | // @see http://buddypress.trac.wordpress.org/ticket/5151 |
79 | 79 | if ( bp_is_username_compatibility_mode() ) { |
80 | | $recipient_id = bp_core_get_userid( $recipient ); |
| 80 | $recipient_id = bp_core_get_userid( urldecode( $recipient ) ); |
81 | 81 | } else { |
82 | 82 | $recipient_id = bp_core_get_userid_from_nicename( $recipient ); |
83 | 83 | } |
diff --git bp-templates/bp-legacy/buddypress-functions.php bp-templates/bp-legacy/buddypress-functions.php
index 5b9955c..0cb3153 100644
|
|
function bp_legacy_theme_ajax_messages_autocomplete_results() { |
1335 | 1335 | } |
1336 | 1336 | |
1337 | 1337 | if ( bp_is_username_compatibility_mode() ) { |
1338 | | $username = $ud->user_login; |
| 1338 | // Sanitize for spaces. Use urlencode() rather |
| 1339 | // than rawurlencode() because %20 breaks JS |
| 1340 | $username = urlencode( $ud->user_login ); |
1339 | 1341 | } else { |
1340 | 1342 | $username = $ud->user_nicename; |
1341 | 1343 | } |
diff --git bp-templates/bp-legacy/buddypress/members/single/member-header.php bp-templates/bp-legacy/buddypress/members/single/member-header.php
index a02511a..0e4c01a 100644
|
|
|
22 | 22 | <div id="item-header-content"> |
23 | 23 | |
24 | 24 | <?php if ( bp_is_active( 'activity' ) && bp_activity_do_mentions() ) : ?> |
25 | | <h2 class="user-nicename">@<?php bp_displayed_user_username(); ?></h2> |
| 25 | <h2 class="user-nicename">@<?php bp_displayed_user_nicename(); ?></h2> |
26 | 26 | <?php endif; ?> |
27 | 27 | |
28 | 28 | <span class="activity"><?php bp_last_activity( bp_displayed_user_id() ); ?></span> |
… |
… |
|
62 | 62 | |
63 | 63 | <?php do_action( 'bp_after_member_header' ); ?> |
64 | 64 | |
65 | | <?php do_action( 'template_notices' ); ?> |
66 | | No newline at end of file |
| 65 | <?php do_action( 'template_notices' ); ?> |
diff --git bp-themes/bp-default/_inc/ajax.php bp-themes/bp-default/_inc/ajax.php
index d739a36..ff44529 100644
|
|
function bp_dtheme_ajax_messages_autocomplete_results() { |
982 | 982 | } |
983 | 983 | |
984 | 984 | if ( bp_is_username_compatibility_mode() ) { |
985 | | $username = $ud->user_login; |
| 985 | // Sanitize for spaces |
| 986 | $username = urlencode( $ud->user_login ); |
986 | 987 | } else { |
987 | 988 | $username = $ud->user_nicename; |
988 | 989 | } |
diff --git bp-themes/bp-default/members/single/member-header.php bp-themes/bp-default/members/single/member-header.php
index cfdc4a0..36b3ebf 100644
|
|
|
26 | 26 | </h2> |
27 | 27 | |
28 | 28 | <?php if ( bp_is_active( 'activity' ) && bp_activity_do_mentions() ) : ?> |
29 | | <span class="user-nicename">@<?php bp_displayed_user_username(); ?></span> |
| 29 | <span class="user-nicename">@<?php bp_displayed_user_nicename(); ?></span> |
30 | 30 | <?php endif; ?> |
31 | 31 | |
32 | 32 | <span class="activity"><?php bp_last_activity( bp_displayed_user_id() ); ?></span> |
… |
… |
|
66 | 66 | |
67 | 67 | <?php do_action( 'bp_after_member_header' ); ?> |
68 | 68 | |
69 | | <?php do_action( 'template_notices' ); ?> |
70 | | No newline at end of file |
| 69 | <?php do_action( 'template_notices' ); ?> |