Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
04/28/2021 11:49:31 PM (5 months ago)
Author:
dcavins
Message:

BP_Optout: Prevent bp_send_email() delivery to opted-out address.

In BP_Email::validate() ensure that the recipient has
not opted out from communications from this site.

See #8448.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/testcases/core/optouts.php

    r12903 r12913  
    182182    }
    183183
     184    public function test_bp_optout_prevents_bp_email_send() {
     185        $old_current_user = get_current_user_id();
     186
     187        $u1 = $this->factory->user->create();
     188        $this->set_current_user( $u1 );
     189        // Create an opt-out.
     190        $args = array(
     191            'email_address'     => 'test2@example.com',
     192            'user_id'           => $u1,
     193            'email_type'        => 'annoyance'
     194        );
     195        $i1 = bp_add_optout( $args );
     196        $email = new BP_Email( 'activity-at-message' );
     197        $email->set_from( 'test1@example.com' )->set_to( 'test2@example.com' )->set_subject( 'testing' );
     198        $email->set_content_html( 'testing' )->set_tokens( array( 'poster.name' => 'example' ) );
     199
     200        $this->assertTrue( is_wp_error( $email->validate() ) );
     201        $this->set_current_user( $old_current_user );
     202    }
     203
    184204}
Note: See TracChangeset for help on using the changeset viewer.