Skip to:
Content

BuddyPress.org

Ticket #6913: 6913.patch

File 6913.patch, 6.6 KB (added by imath, 9 years ago)
  • src/bp-core/bp-core-filters.php

    diff --git src/bp-core/bp-core-filters.php src/bp-core/bp-core-filters.php
    index 2fe8efa..3e78a43 100644
    function bp_core_activation_signup_blog_notification( $domain, $path, $title, $u 
    464464                        'user.email'        => $user_email,
    465465                ),
    466466        );
    467         bp_send_email( 'core-user-registration-with-blog', $user_email, $args );
     467        bp_send_email( 'core-user-registration-with-blog', array( array( $user_email => $user ) ), $args );
    468468
    469469        // Return false to stop the original WPMU function from continuing.
    470470        return false;
    function bp_core_activation_signup_user_notification( $user, $user_email, $key, 
    519519                        'user.email'   => $user_email,
    520520                ),
    521521        );
    522         bp_send_email( 'core-user-registration', $user_email, $args );
     522        bp_send_email( 'core-user-registration', array( array( $user_email => $user ) ), $args );
    523523
    524524        // Return false to stop the original WPMU function from continuing.
    525525        return false;
  • src/bp-members/bp-members-functions.php

    diff --git src/bp-members/bp-members-functions.php src/bp-members/bp-members-functions.php
    index 542fedd..f53f26e 100644
    function bp_core_signup_user( $user_login, $user_password, $user_email, $usermet 
    18391839                 *                               signup data, xprofile data, etc).
    18401840                 */
    18411841                if ( apply_filters( 'bp_core_signup_send_activation_key', true, $user_id, $user_email, $activation_key, $usermeta ) ) {
    1842                         bp_core_signup_send_validation_email( $user_id, $user_email, $activation_key );
     1842                        bp_core_signup_send_validation_email( $user_id, $user_email, $activation_key, $user_login );
    18431843                }
    18441844        }
    18451845
    function bp_core_signup_avatar_upload_dir() { 
    21992199/**
    22002200 * Send activation email to a newly registered user.
    22012201 *
    2202  * @param int    $user_id    ID of the new user.
    2203  * @param string $user_email Email address of the new user.
    2204  * @param string $key        Activation key.
     2202 * @since  2.5.0 Add the $user_login parameter.
     2203 *
     2204 * @param int|bool $user_id    ID of the new user, false if BP_SIGNUPS_SKIP_USER_CREATION is true.
     2205 * @param string   $user_email Email address of the new user.
     2206 * @param string   $key        Activation key.
     2207 * @param string   $user_login The user login.
    22052208 */
    2206 function bp_core_signup_send_validation_email( $user_id, $user_email, $key ) {
     2209function bp_core_signup_send_validation_email( $user_id, $user_email, $key, $user_login = '' ) {
    22072210        $args = array(
    22082211                'tokens' => array(
    22092212                        'activate.url' => esc_url( trailingslashit( bp_get_activation_page() ) . "{$key}/" ),
    function bp_core_signup_send_validation_email( $user_id, $user_email, $key ) { 
    22132216                        'user.id'      => $user_id,
    22142217                ),
    22152218        );
    2216         bp_send_email( 'core-user-registration', $user_id, $args );
     2219
     2220        if ( empty( $user_id ) ) {
     2221                $to = array( array( $user_email => $user_login ) );
     2222        } else {
     2223                $to = $user_id;
     2224        }
     2225        bp_send_email( 'core-user-registration', $to, $args );
    22172226}
    22182227
    22192228/**
  • src/bp-members/classes/class-bp-signup.php

    diff --git src/bp-members/classes/class-bp-signup.php src/bp-members/classes/class-bp-signup.php
    index 6f38d4f..4113fe8 100644
    class BP_Signup { 
    586586
    587587                                // Send the validation email.
    588588                                } else {
    589                                         bp_core_signup_send_validation_email( false, $signup->user_email, $signup->activation_key );
     589                                        bp_core_signup_send_validation_email( false, $signup->user_email, $signup->activation_key, $signup->user_login );
    590590                                }
    591591                        }
    592592
  • tests/phpunit/testcases/core/functions.php

    diff --git tests/phpunit/testcases/core/functions.php tests/phpunit/testcases/core/functions.php
    index c541c02..cab801e 100644
    class BP_Tests_Core_Functions extends BP_UnitTestCase { 
    721721                $result      = bp_email_add_link_color_to_template( $content, 'template', 'add-content' );
    722722                $this->assertContains( $link_color, $result );
    723723        }
     724
     725        /**
     726         * @group bp_core_signup_send_validation_email
     727         * @group bp_core_activation_signup_user_notification
     728         * @group bp_core_activation_signup_blog_notification
     729         */
     730        public function test_send_account_validation_email() {
     731                $this->signup_to = array();
     732                $old_user = get_current_user_id();
     733                $this->email = false;
     734
     735                $email_type = get_term_by( 'slug', 'core-user-registration', bp_get_email_tax_type() );
     736
     737                $this->set_current_user( 1 );
     738
     739                // Signup
     740                $this->factory->post->create( array(
     741                        'post_type' => bp_get_email_post_type(),
     742                        'post_content' => 'hi {{recipient.name}}',
     743                        'tax_input' => array(
     744                                bp_get_email_tax_type() => array( $email_type->term_id )
     745                        ),
     746                ) );
     747
     748                if ( is_multisite() ) {
     749                        $email_type = get_term_by( 'slug', 'core-user-registration-with-blog', bp_get_email_tax_type() );
     750
     751                        // Signup with blog
     752                        $this->factory->post->create( array(
     753                                'post_type' => bp_get_email_post_type(),
     754                                'post_content' => 'hi {{recipient.name}}',
     755                                'tax_input' => array(
     756                                        bp_get_email_tax_type() => array( $email_type->term_id )
     757                                ),
     758                        ) );
     759                }
     760
     761                $this->set_current_user( $old_user );
     762
     763                add_filter( 'bp_email_set_to', array( $this, 'catch_email_and_name' ), 10, 1 );
     764
     765                if ( is_multisite() ) {
     766                        bp_core_signup_user( 'foologin', 'foopass', 'foo@bar.com', array() );
     767                        $this->assertTrue( (bool) is_email( key( $this->signup_to ) ) );
     768                        $this->assertTrue( 'foologin' === $this->signup_to['foo@bar.com'], 'Hi User Login is missing.' );
     769
     770                        $this->signup_to = array();
     771
     772                        bp_core_signup_blog( 'bar', '/', 'Bar', 'barlogin', 'bar@foo.com', array() );
     773                        $this->assertTrue( (bool) is_email( key( $this->signup_to ) ) );
     774                        $this->assertTrue( 'barlogin' === $this->signup_to['bar@foo.com'], 'Hi User Login is missing.' );
     775
     776                } else {
     777                        bp_core_signup_user( 'foologin', 'foopass', 'foo@bar.com', array() );
     778                        $this->assertTrue( (bool) is_email( key( $this->signup_to ) ) );
     779                        $this->assertTrue( 'foologin' === $this->signup_to['foo@bar.com'], 'Hi User Login is missing.' );
     780
     781                        $this->signup_to = array();
     782
     783                        define( 'BP_SIGNUPS_SKIP_USER_CREATION', true );
     784
     785                        bp_core_signup_user( 'barlogin', 'barpass', 'bar@foo.com', array() );
     786                        $this->assertTrue( (bool) is_email( key( $this->signup_to ) ), 'When BP_SIGNUPS_SKIP_USER_CREATION is true, the User is not created so we need to use the user_email to send the email.' );
     787                        $this->assertTrue( 'barlogin' === $this->signup_to['bar@foo.com'], 'Hi User Login is missing.' );
     788                }
     789
     790                remove_filter( 'bp_email_set_to', array( $this, 'catch_email_and_name' ), 10, 1 );
     791        }
     792
     793        public function catch_email_and_name( $to ) {
     794                $recipient = array_shift( $to );
     795                $this->signup_to = array( $recipient->get_address() => $recipient->get_name() );
     796
     797                return $to;
     798        }
    724799}