Skip to:
Content

BuddyPress.org

Ticket #4676: 4676.04.patch

File 4676.04.patch, 4.8 KB (added by boonebgorges, 11 years ago)
  • bp-members/bp-members-functions.php

    diff --git bp-members/bp-members-functions.php bp-members/bp-members-functions.php
    index 2158c2f..67bfe62 100644
    function bp_core_signup_send_validation_email( $user_id, $user_email, $key ) { 
    17111711}
    17121712
    17131713/**
    1714  * Stop user accounts logging in that have not been activated yet (user_status = 2).
     1714 * Display a "resend email" link when an unregistered user attempts to log in.
    17151715 *
    1716  * Note: This is only applicable for single site WordPress installs.
    1717  * Multisite has their own DB table - 'wp_signups' - dedicated for unactivated users.
    1718  * See {@link wpmu_signup_user()} and {@link wpmu_validate_user_signup()}.
    1719  *
    1720  * @param WP_User|WP_Error $user Either the WP_User object or the WP_Error object
    1721  * @return WP_User|WP_Error If the user is not a spammer, return the WP_User object. Otherwise a new WP_Error object.
     1716 * @param WP_User|WP_Error $user Either the WP_User or the WP_Error object
     1717 * @param string $username The inputted, attempted username.
     1718 * @param string $password The inputted, attempted password.
     1719 * @return WP_User|WP_Error
    17221720 *
    17231721 * @since BuddyPress (1.2.2)
    17241722 */
    1725 function bp_core_signup_disable_inactive( $user ) {
    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 ) )
     1723function bp_core_signup_disable_inactive( $user = null, $username = '', $password ='' ) {
     1724        // login form not used
     1725        if ( empty( $username ) && empty( $password ) ) {
    17281726                return $user;
     1727        }
    17291728
    1730         // the user exists; now do a check to see if the user has activated their account or not
    1731         // NOTE: this is only applicable for single site WordPress installs!
    1732         // if unactivated, stop the login now!
    1733         if ( is_a( $user, 'WP_User' ) && 2 == $user->user_status )
    1734                 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' ) );
     1729        // An existing WP_User with a user_status of 2 is either a legacy
     1730        // signup, or is a user created for backward compatibility. See
     1731        // {@link bp_core_signup_user()} for more details.
     1732        if ( is_a( $user, 'WP_User' ) && 2 == $user->user_status ) {
     1733                $user_login = $user->user_login;
    17351734
    1736         // user has activated their account! all clear!
    1737         return $user;
     1735        // If no WP_User is found corresponding to the username, this
     1736        // is a potential signup
     1737        } elseif ( is_wp_error( $user ) && 'invalid_username' == $user->get_error_code() ) {
     1738                $user_login = $username;
     1739
     1740        // This is an activated user, so bail
     1741        } else {
     1742                return $user;
     1743        }
     1744
     1745        // Look for the unactivated signup corresponding to the login name
     1746        $signup = BP_Signup::get( array( 'user_login' => sanitize_user( $user_login ) ) );
     1747
     1748        // No signup or more than one, something is wrong. Let's bail.
     1749        if ( empty( $signup['signups'][0] ) || $signup['total'] > 1 ) {
     1750                return $user;
     1751        }
     1752
     1753        // Unactivated user account found!
     1754        // Set up the feedback message
     1755        $signup_id = $signup['signups'][0]->signup_id;
     1756
     1757        $resend_url_params = array(
     1758                'action' => 'bp-resend-activation',
     1759                'id'     => $signup_id,
     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}
     1771add_filter( 'authenticate', 'bp_core_signup_disable_inactive', 30, 3 );
     1772
     1773/**
     1774 * On the login screen, resends the activation email for a user.
     1775 *
     1776 * @since BuddyPress (2.0.0)
     1777 *
     1778 * @see bp_core_signup_disable_inactive()
     1779 */
     1780function bp_members_login_resend_activation_email() {
     1781        global $error;
     1782
     1783        if ( empty( $_GET['id'] ) || empty( $_GET['_wpnonce'] ) ) {
     1784                return;
     1785        }
     1786
     1787        // verify nonce
     1788        if ( ! wp_verify_nonce( $_GET['_wpnonce'], 'bp-resend-activation' ) ) {
     1789                die( 'Security check' );
     1790        }
     1791
     1792        $signup_id = (int) $_GET['id'];
     1793
     1794        // resend the activation email
     1795        // also updates the 'last sent' and '# of emails sent' values
     1796        $resend = BP_Signup::resend( array( $signup_id ) );
     1797
     1798        // add feedback message
     1799        if ( ! empty( $resend['errors'] ) ) {
     1800                $error = __( '<strong>ERROR</strong>: Your account has already been activated.', 'buddypress' );
     1801        } else {
     1802                $error = __( 'Activation email resent!  Please check your inbox or spam folder.', 'buddypress' );
     1803        }
    17381804}
    1739 add_filter( 'authenticate', 'bp_core_signup_disable_inactive', 30 );
     1805add_action( 'login_form_bp-resend-activation', 'bp_members_login_resend_activation_email' );
    17401806
    17411807/**
    17421808 * Kill the wp-signup.php if custom registration signup templates are present