Skip to:
Content

BuddyPress.org

Ticket #4676: 4676.02.diff

File 4676.02.diff, 4.4 KB (added by imath, 10 years ago)
  • bp-members/bp-members-functions.php

    diff --git bp-members/bp-members-functions.php bp-members/bp-members-functions.php
    index a34129e..154d33c 100644
    function bp_core_signup_send_validation_email( $user_id, $user_email, $key ) { 
    17181718 *
    17191719 * @since BuddyPress (1.2.2)
    17201720 */
    1721 function bp_core_signup_disable_inactive( $user ) {
    1722         // check to see if the $user has already failed logging in, if so return $user as-is
    1723         if ( is_wp_error( $user ) || empty( $user ) )
     1721function bp_core_signup_disable_inactive( $user = null, $username = '', $password ='' ) {
     1722        // The login form was not used
     1723        if( empty( $username ) && empty( $password ) )
    17241724                return $user;
     1725       
     1726        // check to see if the $user has already failed logging in, if so return $user as-is
     1727        if ( is_wp_error( $user ) || empty( $user ) ) {
     1728                /**
     1729                 * The user doesn't exist. But this could be a multisite signup or
     1730                 * a BP_SIGNUPS_SKIP_USER_CREATION regular config signup. Since
     1731                 * changeset 8119, signups are handled in a similar way on non-multisite
     1732                 * and multisite config. If BP_SIGNUPS_SKIP_USER_CREATION is not defined,
     1733                 * the user creation process will happen for backcompat reasons on non-multisite
     1734                 * config.
     1735                 */
     1736                $signup = BP_Signup::get( array( 'user_login' => sanitize_user( $username ) ) );
     1737               
     1738
     1739                // No signup or more than one, something is wrong let's bail.
     1740                if ( empty( $signup['signups'][0] ) || $signup['total'] > 1 )
     1741                        return $user;
     1742
     1743                $user_login = $signup['signups'][0]->user_login;
     1744        }
    17251745
    17261746        // the user exists; now do a check to see if the user has activated their account or not
    1727         // NOTE: this is only applicable for single site WordPress installs!
     1747        // NOTE: this is only applicable for single site WordPress installs that have not defined
     1748        // the BP_SIGNUPS_SKIP_USER_CREATION constant !
    17281749        // if unactivated, stop the login now!
    1729         if ( is_a( $user, 'WP_User' ) && 2 == $user->user_status )
    1730                 return new WP_Error( 'bp_account_not_activated', __( '<strong>ERROR</strong>: Your account has not been activated. Check your email for the activation link.', 'buddypress' ) );
     1750        if ( is_a( $user, 'WP_User' ) && 2 == $user->user_status ) {
     1751                $user_login = $user->user_login;
     1752        }
     1753
     1754        // We've found a login in signups, user needs to activate his account
     1755        if ( ! empty( $user_login ) ) {
     1756
     1757                $resend_url_params = array(
     1758                        'action' => 'bp-resend-activation',
     1759                        'user'   => $user_login,
     1760                );
     1761
     1762                $resend_url = wp_nonce_url(
     1763                        add_query_arg( $resend_url_params, wp_login_url() ),
     1764                        'bp-resend-activation'
     1765                );
     1766
     1767                $resend_string = '<br /><br />' .  sprintf( __( 'If you have not received an email yet, <a href="%s">click here to resend it</a>.', 'buddypress' ), $resend_url );
     1768
     1769                return new WP_Error( 'bp_account_not_activated', __( '<strong>ERROR</strong>: Your account has not been activated. Check your email for the activation link.', 'buddypress' ) . $resend_string );
     1770        }
    17311771
    17321772        // user has activated their account! all clear!
    17331773        return $user;
    17341774}
    1735 add_filter( 'authenticate', 'bp_core_signup_disable_inactive', 30 );
     1775add_filter( 'authenticate', 'bp_core_signup_disable_inactive', 30, 3 );
     1776
     1777/**
     1778 * On the login screen, resends the activation email for a user.
     1779 *
     1780 * @since BuddyPress (2.0.0)
     1781 *
     1782 * @see bp_core_signup_disable_inactive()
     1783 */
     1784function bp_members_login_resend_activation_email() {
     1785        global $error;
     1786
     1787        if ( empty( $_GET['user'] ) || empty( $_GET['_wpnonce'] ) ) {
     1788                return;
     1789        }
     1790
     1791        // verify nonce
     1792        if ( ! wp_verify_nonce( $_GET['_wpnonce'], 'bp-resend-activation' ) ) {
     1793                die( 'Security check' );
     1794        }
     1795
     1796        // fetch the signup ID
     1797        // note: this is different than the user ID
     1798        $signup_query = BP_Signup::get( array(
     1799                'user_login' => $_GET['user']
     1800        ) );
     1801
     1802        // no match, stop now!
     1803        if ( empty( $signup_query['signups'][0] ) ) {
     1804                return;
     1805        }
     1806
     1807        // resend the activation email
     1808        // also updates the 'last sent' and '# of emails sent' values
     1809        $resend = BP_Signup::resend( array( $signup_query['signups'][0]->signup_id ) );
     1810
     1811        // add feedback message
     1812        if ( ! empty( $resend['errors'] ) ) {
     1813                $error = __( '<strong>ERROR</strong>: Your account has already been activated.', 'buddypress' );
     1814        } else {
     1815                $error = __( 'Activation email resent!', 'buddypress' );
     1816        }
     1817}
     1818add_action( 'login_form_bp-resend-activation', 'bp_members_login_resend_activation_email' );
    17361819
    17371820/**
    17381821 * Kill the wp-signup.php if custom registration signup templates are present