Skip to:
Content

BuddyPress.org

Ticket #7461: 7461.diff

File 7461.diff, 3.7 KB (added by espellcaste, 8 years ago)
  • src/bp-members/bp-members-functions.php

    diff --git src/bp-members/bp-members-functions.php src/bp-members/bp-members-functions.php
    index 462f1d12d..7846718ee 100644
    function bp_core_get_illegal_names( $value = '', $oldvalue = '' ) { 
    15561556                'settings',
    15571557                'notifications',
    15581558                'register',
    1559                 'activate'
     1559                'activate',
    15601560        );
    15611561
    15621562        // Core constants.
    function bp_core_get_illegal_names( $value = '', $oldvalue = '' ) { 
    15741574                'BP_REGISTER_SLUG',
    15751575                'BP_ACTIVATION_SLUG',
    15761576        );
    1577         foreach( $slug_constants as $constant ) {
     1577        foreach ( $slug_constants as $constant ) {
    15781578                if ( defined( $constant ) ) {
    15791579                        $bp_component_slugs[] = constant( $constant );
    15801580                }
    15811581        }
    15821582
    15831583        /**
    1584          * Filters the array of default illegal usernames.
     1584         * Filters the array of default illegal usernames from BuddyPress.
    15851585         *
    15861586         * @since 1.2.2
    15871587         *
    15881588         * @param array $value Merged and unique array of illegal usernames.
    15891589         */
    1590         $filtered_illegal_names = apply_filters( 'bp_core_illegal_usernames', array_merge( array( 'www', 'web', 'root', 'admin', 'main', 'invite', 'administrator' ), $bp_component_slugs ) );
     1590        $filtered_illegal_names = (array) apply_filters( 'bp_core_illegal_usernames', array_merge( array( 'www', 'web', 'root', 'admin', 'main', 'invite', 'administrator' ), $bp_component_slugs ) );
    15911591
    1592         // Merge the arrays together.
    1593         $merged_names           = array_merge( (array) $filtered_illegal_names, (array) $db_illegal_names );
     1592        /**
     1593         * Filters the list of illegal usernames from WordPress.
     1594         *
     1595         * @since 3.0
     1596         *
     1597         * @param array Array of illegal usernames.
     1598         */
     1599        $wp_filtered_illegal_names = apply_filters( 'illegal_user_logins', array() );
     1600
     1601        // First merge BuddyPress illegal names.
     1602        $bp_merged_names           = array_merge( (array) $filtered_illegal_names, (array) $db_illegal_names );
     1603
     1604        // Then merge WordPress and BuddyPress illegal names.
     1605        $merged_names              = array_merge( (array) $wp_filtered_illegal_names, (array) $bp_merged_names );
    15941606
    15951607        // Remove duplicates.
    1596         $illegal_names          = array_unique( (array) $merged_names );
     1608        $illegal_names             = array_unique( (array) $merged_names );
    15971609
    15981610        /**
    15991611         * Filters the array of default illegal names.
  • tests/phpunit/testcases/members/functions.php

    diff --git tests/phpunit/testcases/members/functions.php tests/phpunit/testcases/members/functions.php
    index 823df65e8..941927f16 100644
    class BP_Tests_Members_Functions extends BP_UnitTestCase { 
    637637
    638638                $wpdb->suppress_errors( $suppress );
    639639        }
     640
     641        /**
     642         * @ticket BP7461
     643         *
     644         * Test function before and after adding custom illegal names from WordPress.
     645         */
     646        function test_bp_core_get_illegal_names() {
     647
     648                // Marking sure BP custom illegals are in the array.
     649                $this->assertTrue( in_array( 'profile', bp_core_get_illegal_names(), true ) );
     650                $this->assertTrue( in_array( 'forums', bp_core_get_illegal_names(), true ) );
     651
     652                add_filter( 'illegal_user_logins', array( $this, '_illegal_user_logins' ) );
     653
     654                // Testing fake custom illegal names.
     655                $this->assertTrue( in_array( 'testuser', bp_core_get_illegal_names(), true ) );
     656                $this->assertTrue( in_array( 'admins', bp_core_get_illegal_names(), true ) );
     657                $this->assertFalse( in_array( 'buddypresss', bp_core_get_illegal_names(), true ) );
     658
     659                // Marking sure BP custom illegals are in the array after including the custom ones.
     660                $this->assertTrue( in_array( 'profile', bp_core_get_illegal_names(), true ) );
     661                $this->assertTrue( in_array( 'forums', bp_core_get_illegal_names(), true ) );
     662
     663                remove_filter( 'illegal_user_logins', array( $this, '_illegal_user_logins' ) );
     664        }
     665
     666        function _illegal_user_logins() {
     667                return  array( 'testuser', 'admins', 'buddypress' );
     668        }
    640669}