Skip to:
Content

BuddyPress.org

Changeset 13905


Ignore:
Timestamp:
06/04/2024 10:47:30 PM (6 months ago)
Author:
dcavins
Message:

Ensure that bp_email_set_content_type filter is run.

This patch sets the email type explicitly when the BP_Email class is constructed. This ensures that
the filter is run.

It is still possible to set the type after
instantiation using the set_content_type() method.

Props vapvarun.

Fixes #9169.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-core/classes/class-bp-email.php

    r13892 r13905  
    197197        $this->set_from( $from_address, $from_name );
    198198        $this->set_reply_to( bp_get_option( 'admin_email' ), $from_name );
     199
     200        // Prefer HTML emails unless filtered to plaintext.
     201        $this->set_content_type( $this->content_type );
    199202
    200203        /**
  • trunk/tests/phpunit/testcases/core/class-bp-email.php

    r13314 r13905  
    3030    }
    3131
     32    /**
     33     * @ticket BP9169
     34     */
     35    public function test_default_content_type() {
     36        $email = new BP_Email( 'activity-at-message' );
     37
     38        $this->assertSame( 'html', $email->get_content_type() );
     39    }
     40
     41    /**
     42     * @ticket BP9169
     43     */
     44    public function test_set_content_type_to_plaintext() {
     45        $email = new BP_Email( 'activity-at-message' );
     46        $email->set_content_type( 'plaintext' );
     47
     48        $this->assertSame( 'plaintext', $email->get_content_type() );
     49    }
     50
     51    /**
     52     * @ticket BP9169
     53     */
     54    public function test_set_content_type_to_plaintext_via_filter() {
     55        add_filter( 'bp_email_set_content_type', array( $this, 'bp_disable_html_emails' ) );
     56        $email = new BP_Email( 'activity-at-message' );
     57        remove_filter( 'bp_email_set_content_type', array( $this, 'bp_disable_html_emails' ) );
     58
     59        $this->assertSame( 'plaintext', $email->get_content_type() );
     60    }
     61    public function bp_disable_html_emails( $content_type ) {
     62        return 'plaintext';
     63    }
     64
    3265    public function test_valid_html_content() {
    3366        $message = '<b>test</b>';
     
    4881
    4982        $this->assertSame( $message, $email->get_content() );
     83    }
     84
     85    /**
     86     * @ticket BP9169
     87     */
     88    public function test_plaintext_strip_tags() {
     89        $message  = '<b>test</b>';
     90        $plainmsg = 'test';
     91        $email    = new BP_Email( 'activity-at-message' );
     92
     93        $email->set_content_plaintext( $message );
     94        $email->set_content_type( 'plaintext' );
     95
     96        $this->assertSame( $plainmsg, $email->get_content() );
    5097    }
    5198
Note: See TracChangeset for help on using the changeset viewer.