Skip to:
Content

BuddyPress.org

Ticket #5977: 5977.patch

File 5977.patch, 6.2 KB (added by imath, 10 years ago)
  • src/bp-core/bp-core-functions.php

    diff --git src/bp-core/bp-core-functions.php src/bp-core/bp-core-functions.php
    index 5b93f9c..9d2a2d0 100644
    function bp_is_network_activated() { 
    15281528        return (bool) apply_filters( 'bp_is_network_activated', $retval );
    15291529}
    15301530
     1531/**
     1532 * Check wether BuddyPress is activated on the main site
     1533 *
     1534 * @since  BuddyPress (?)
     1535 *
     1536 * @param  int    $site_id the site ID to check.
     1537 * @return bool            true if not multisite or if multisite and BuddyPress
     1538 *                         root blog id is the same than WordPress network main site,
     1539 *                         false otherwise.
     1540 */
     1541function bp_is_network_main_site( $site_id = 0 ) {
     1542        if ( empty( $site_id ) ) {
     1543                $site_id = bp_get_root_blog_id();
     1544        }
     1545
     1546        return (bool) is_main_site( $site_id );
     1547}
     1548
    15311549/** Global Manipulators *******************************************************/
    15321550
    15331551/**
    function bp_core_get_suggestions( $args ) { 
    20342052        }
    20352053
    20362054        return apply_filters( 'bp_core_get_suggestions', $retval, $args );
    2037 }
    2038  No newline at end of file
     2055}
  • src/bp-members/bp-members-admin.php

    diff --git src/bp-members/bp-members-admin.php src/bp-members/bp-members-admin.php
    index 8ca63b7..ad871cf 100644
    class BP_Members_Admin { 
    410410                );
    411411
    412412                // Only show sign-ups where they belong
    413                 if ( ! is_multisite() || is_network_admin() ) {
     413                if ( ! is_multisite() || ( is_network_admin() && ! $this->subsite_activated ) || ( $this->subsite_activated && ! is_network_admin() ) ) {
    414414
    415415                        // Manage signups
    416416                        $hooks['signups'] = $this->signups_page = add_users_page(
  • src/bp-members/bp-members-functions.php

    diff --git src/bp-members/bp-members-functions.php src/bp-members/bp-members-functions.php
    index 1fba30e..88d3ac6 100644
    function bp_core_validate_blog_signup( $blog_url, $blog_title ) { 
    15351535}
    15361536
    15371537/**
     1538 * Specific config : BuddyPress is activated on main site but is not network
     1539 * activated. In this case, we need to add specific usermeta so that the user
     1540 * will also be a member of the main site.
     1541 *
     1542 * Once the signup is activated, WordPress will add the user to the blog if
     1543 * he's not signing up with a blog, else BuddyPress will add the user to main
     1544 * site.
     1545 *
     1546 * @since  BuddyPress (?)
     1547 *
     1548 * @param  array $usermeta the signup meta informations
     1549 * @return array           the signup meta unchanged or with specific ones if needed
     1550 */
     1551function bp_core_get_specific_signup_meta( $usermeta = array() ) {
     1552        if ( ! bp_is_network_activated() && bp_is_network_main_site() ) {
     1553                $usermeta = array_merge( $usermeta, array(
     1554                        'add_to_blog' => bp_get_root_blog_id(),
     1555                        'new_role'    => bp_get_option( 'default_role', 'subscriber' ),
     1556                ) );
     1557        }
     1558
     1559        return (array) apply_filters( 'bp_core_get_specific_signup_meta', $usermeta );
     1560}
     1561
     1562/**
    15381563 * Process data submitted at user registration and convert to a signup object.
    15391564 *
    15401565 * @todo There appears to be a bug in the return value on success.
    function bp_core_signup_user( $user_login, $user_password, $user_email, $usermet 
    15521577        // We need to cast $user_id to pass to the filters
    15531578        $user_id = false;
    15541579
     1580        // Specific config
     1581        $usermeta = bp_core_get_specific_signup_meta( $usermeta );
     1582
    15551583        // Multisite installs have their own install procedure
    15561584        if ( is_multisite() ) {
    15571585                wpmu_signup_user( $user_login, $user_email, $usermeta );
    function bp_core_signup_blog( $blog_domain, $blog_path, $blog_title, $user_name, 
    16221650                return false;
    16231651        }
    16241652
     1653        // Specific config
     1654        $usermeta = bp_core_get_specific_signup_meta( $usermeta );
     1655
    16251656        return apply_filters( 'bp_core_signup_blog', wpmu_signup_blog( $blog_domain, $blog_path, $blog_title, $user_name, $user_email, $usermeta ) );
    16261657}
    16271658
    16281659/**
     1660 * Make sure a user who registered with a blog has a role on the main site
     1661 * if BuddyPress is activated on it but not network activated
     1662 *
     1663 * @since  BuddyPress (?)
     1664 *
     1665 * @param  int     $blog_id      the blog ID the user registered
     1666 * @param  int     $user_id      the user ID
     1667 * @param  string  $password
     1668 * @param  string  $signup_title
     1669 * @param  array   $meta         the signup meta we need.
     1670 */
     1671function bp_core_maybe_activate_user_on_root_blog( $blog_id = 0, $user_id = 0, $password = '', $signup_title = '', $meta = array() ) {
     1672        // Do nothing for regular multisite config
     1673        if ( bp_is_network_activated() ) {
     1674                return;
     1675        }
     1676
     1677        // Bail if we do not have needed signup metas
     1678        if ( empty( $meta['add_to_blog'] ) || empty( $meta['new_role'] ) || empty( $user_id ) ) {
     1679                return;
     1680        }
     1681
     1682        /**
     1683         * Handle the specific config : BuddyPress is not network activated
     1684         * but is activated on the main site.
     1685         */
     1686        if ( bp_is_network_main_site() ) {
     1687                $blog_id = absint( $meta[ 'add_to_blog' ] );
     1688
     1689                // Bail if we don't get BuddyPress root blog
     1690                if ( bp_get_root_blog_id() != $blog_id ) {
     1691                        return;
     1692                }
     1693
     1694                $role = sanitize_text_field( $meta[ 'new_role' ] );
     1695
     1696                // Finally add user to blog without setting it as primary
     1697                add_user_to_blog( $blog_id, $user_id, $role );
     1698        }
     1699}
     1700add_action( 'wpmu_activate_blog', 'bp_core_maybe_activate_user_on_root_blog', 10, 5 );
     1701
     1702/**
    16291703 * Activate a signup, as identified by an activation key.
    16301704 *
    16311705 * @param string $key Activation key.
    function bp_core_activate_signup( $key ) { 
    16361710
    16371711        $user = false;
    16381712
    1639         // Multisite installs have their own activation routine
    1640         if ( is_multisite() ) {
     1713        /**
     1714         * If BuddyPress is activated on the main site of the network, use the
     1715         * multisite activation routine to create user and eventually a blog
     1716         */
     1717        if ( is_multisite() && bp_is_network_main_site() ) {
    16411718                $user = wpmu_activate_signup( $key );
    16421719
    16431720                // If there were errors, add a message and redirect
    function bp_core_activate_signup( $key ) { 
    16471724
    16481725                $user_id = $user['user_id'];
    16491726
     1727        /**
     1728         * Config is not multisite or BuddyPress is activated on a sub site.
     1729         * In this case, we need to give capabilities to the user so that he
     1730         * appears in the users list once activated.
     1731         *
     1732         * When BuddyPress is activated on a sub site, only registering an account
     1733         * is possible.
     1734         */
    16501735        } else {
    16511736                $signups = BP_Signup::get( array(
    16521737                        'activation_key' => $key,