Skip to:
Content

BuddyPress.org

Changeset 8684


Ignore:
Timestamp:
07/23/2014 09:11:04 PM (10 years ago)
Author:
imath
Message:

Avoid a conflict between member's profile url and member's blog url

When root profiles are enabled on a subdirectory multisite config, we need to make sure the member's profile url is different than the member's blog url. To do so the username needs to be an illegal blog name on this particular config.

fixes #5332

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-members/bp-members-filters.php

    r8318 r8684  
    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 *
Note: See TracChangeset for help on using the changeset viewer.