Skip to:
Content

BuddyPress.org

Ticket #5332: 5332-illegal-names.diff

File 5332-illegal-names.diff, 1.5 KB (added by imath, 11 years ago)
  • bp-members/bp-members-filters.php

     
    5252}
    5353add_action( 'bp_loaded', 'bp_members_signup_sanitization' );
    5454
     55
    5556/**
     57 * Make sure the username is not the blog slug in case of root profile & subdirectory blog
     58 *
     59 * If BP_ENABLE_ROOT_PROFILES is defined & multisite config is set to subdirectories,
     60 * then there is a chance site.url/username == site.url/blogslug. If so, user's profile
     61 * is not reachable, instead the blog is displayed. This filter makes sure the signup username
     62 * is not the same than the blog slug for this particular config.
     63 *
     64 * @since  BuddyPress (?)
     65 * @param  array  $illegal_names
     66 * @return array
     67 */
     68function bp_members_signup_with_subdirectory_blog( $illegal_names = array() ) {
     69        if( ! bp_core_enable_root_profiles() )
     70                return $illegal_names;
     71
     72        if( is_network_admin() && isset( $_POST['blog'] ) ) {
     73                $blog = $_POST['blog'];
     74                $domain = '';
     75                if ( preg_match( '|^([a-zA-Z0-9-])+$|', $blog['domain'] ) )
     76                        $domain = strtolower( $blog['domain'] );
     77
     78                if( username_exists( $domain ) )
     79                        $illegal_names[] = $domain;
     80
     81        } else {
     82                $illegal_names[] = buddypress()->signup->username;
     83        }
     84
     85        return $illegal_names;
     86}
     87
     88add_filter( 'subdirectory_reserved_names', 'bp_members_signup_with_subdirectory_blog', 10, 1 );
     89
     90/**
    5691 * Filter the user profile URL to point to BuddyPress profile edit
    5792 *
    5893 * @since BuddyPress 1.6