Skip to:
Content

BuddyPress.org

Ticket #5332: 5332-illegal-names.02.patch

File 5332-illegal-names.02.patch, 1.6 KB (added by imath, 11 years ago)
  • src/bp-members/bp-members-filters.php

    diff --git src/bp-members/bp-members-filters.php src/bp-members/bp-members-filters.php
    index fed76b6..6d23601 100644
    function bp_members_signup_sanitization() { 
    5454add_action( 'bp_loaded', 'bp_members_signup_sanitization' );
    5555
    5656/**
     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 (2.1.0)
     65 * @param  array $illegal_names
     66 * @return array $illegal_names
     67 */
     68function bp_members_signup_with_subdirectory_blog( $illegal_names = array() ) {
     69        if ( ! bp_core_enable_root_profiles() ) {
     70                return $illegal_names;
     71        }
     72
     73        if ( is_network_admin() && isset( $_POST['blog'] ) ) {
     74                $blog = $_POST['blog'];
     75                $domain = '';
     76
     77                if ( preg_match( '|^([a-zA-Z0-9-])$|', $blog['domain'] ) ) {
     78                        $domain = strtolower( $blog['domain'] );
     79                }
     80
     81                if ( username_exists( $domain ) ) {
     82                        $illegal_names[] = $domain;
     83                }
     84
     85        } else {
     86                $illegal_names[] = buddypress()->signup->username;
     87        }
     88
     89        return $illegal_names;
     90}
     91add_filter( 'subdirectory_reserved_names', 'bp_members_signup_with_subdirectory_blog', 10, 1 );
     92
     93/**
    5794 * Filter the user profile URL to point to BuddyPress profile edit.
    5895 *
    5996 * @since BuddyPress (1.6.0)