Skip to:
Content

BuddyPress.org

Ticket #5185: 5185.02.patch

File 5185.02.patch, 12.8 KB (added by boonebgorges, 11 years ago)
  • bp-activity/bp-activity-functions.php

    diff --git bp-activity/bp-activity-functions.php bp-activity/bp-activity-functions.php
    index 6e5cb56..ab2feeb 100644
    function bp_activity_find_mentions( $content ) { 
    7272
    7373        // We've found some mentions! Check to see if users exist
    7474        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 );
    8078
    8179                // user ID exists, so let's add it to our array
    8280                if ( ! empty( $user_id ) ) {
  • bp-activity/bp-activity-template.php

    diff --git bp-activity/bp-activity-template.php bp-activity/bp-activity-template.php
    index a5dd724..75d23f9 100644
    function bp_has_activities( $args = '' ) { 
    583583                                        }
    584584
    585585                                        // 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 ) . '<';
    587587                                        $display_comments = 'stream';
    588588                                        $user_id = 0;
    589589                                        break;
    function bp_send_public_message_link() { 
    27192719                if ( bp_is_my_profile() || !is_user_logged_in() )
    27202720                        return false;
    27212721
    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() ) );
    27232723        }
    27242724
    27252725/**
  • bp-members/bp-members-functions.php

    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 
    269269                $update_cache = false;
    270270        }
    271271
    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 
    277272        // Add this to cache
    278273        if ( ( true === $update_cache ) && !empty( $username ) ) {
    279274                wp_cache_set( 'bp_user_username_' . $user_id, $username, 'bp' );
    function bp_core_ucfirst( $str ) { 
    945940}
    946941
    947942/**
    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 /**
    963943 * When a user logs in, check if they have been marked as a spammer. If yes then simply
    964944 * redirect them to the home page and stop them from logging in.
    965945 *
    function bp_core_add_validation_error_messages( WP_Error $errors, $validation_re 
    11711151 */
    11721152function bp_core_validate_user_signup( $user_name, $user_email ) {
    11731153
    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 
    11821154        // Make sure illegal names include BuddyPress slugs and values
    11831155        bp_core_flush_illegal_names();
    11841156
    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();
    11861167
    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 );
    11891170
    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                }
    12021175
    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' ) );
    12051180                }
    1206         }
    12071181
    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                }
    12101186
    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                }
    12131191
    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                }
    12171196
    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                }
    12201203
    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                }
    12241208
    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 );
    12291213
    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                );
    12321220
    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        }
    12351224
    12361225        return apply_filters( 'bp_core_validate_user_signup', $result );
    12371226}
  • bp-members/bp-members-template.php

    diff --git bp-members/bp-members-template.php bp-members/bp-members-template.php
    index c971959..27dfbc9 100644
    function bp_displayed_user_username() { 
    951951                return apply_filters( 'bp_get_displayed_user_username', $username );
    952952        }
    953953
     954/**
     955 * Output the user_nicename for the displayed user.
     956 *
     957 * @since BuddyPress (1.9.0)
     958 */
     959function 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
    954984function bp_loggedin_user_username() {
    955985        echo bp_get_loggedin_user_username();
    956986}
  • bp-messages/bp-messages-functions.php

    diff --git bp-messages/bp-messages-functions.php bp-messages/bp-messages-functions.php
    index c90c8c3..c97507f 100644
    function messages_new_message( $args = '' ) { 
    7777                        // check user_login / nicename columns first
    7878                        // @see http://buddypress.trac.wordpress.org/ticket/5151
    7979                        if ( bp_is_username_compatibility_mode() ) {
    80                                 $recipient_id = bp_core_get_userid( $recipient );
     80                                $recipient_id = bp_core_get_userid( urldecode( $recipient ) );
    8181                        } else {
    8282                                $recipient_id = bp_core_get_userid_from_nicename( $recipient );
    8383                        }
  • bp-templates/bp-legacy/buddypress-functions.php

    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() { 
    13351335                        }
    13361336
    13371337                        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 );
    13391341                        } else {
    13401342                                $username = $ud->user_nicename;
    13411343                        }
  • bp-templates/bp-legacy/buddypress/members/single/member-header.php

    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
     
    2222<div id="item-header-content">
    2323
    2424        <?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>
    2626        <?php endif; ?>
    2727
    2828        <span class="activity"><?php bp_last_activity( bp_displayed_user_id() ); ?></span>
     
    6262
    6363<?php do_action( 'bp_after_member_header' ); ?>
    6464
    65 <?php do_action( 'template_notices' ); ?>
    66  No newline at end of file
     65<?php do_action( 'template_notices' ); ?>
  • bp-themes/bp-default/_inc/ajax.php

    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() { 
    982982                        }
    983983
    984984                        if ( bp_is_username_compatibility_mode() ) {
    985                                 $username = $ud->user_login;
     985                                // Sanitize for spaces
     986                                $username = urlencode( $ud->user_login );
    986987                        } else {
    987988                                $username = $ud->user_nicename;
    988989                        }
  • bp-themes/bp-default/members/single/member-header.php

    diff --git bp-themes/bp-default/members/single/member-header.php bp-themes/bp-default/members/single/member-header.php
    index cfdc4a0..36b3ebf 100644
     
    2626        </h2>
    2727
    2828        <?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>
    3030        <?php endif; ?>
    3131
    3232        <span class="activity"><?php bp_last_activity( bp_displayed_user_id() ); ?></span>
     
    6666
    6767<?php do_action( 'bp_after_member_header' ); ?>
    6868
    69 <?php do_action( 'template_notices' ); ?>
    70  No newline at end of file
     69<?php do_action( 'template_notices' ); ?>