Skip to:
Content

BuddyPress.org

Ticket #6966: 6966.01.patch

File 6966.01.patch, 2.8 KB (added by r-a-y, 9 years ago)
  • src/bp-core/bp-core-filters.php

     
    5959add_filter( 'bp_email_set_content_plaintext', 'wp_strip_all_tags', 6 );
    6060add_filter( 'bp_email_set_subject', 'sanitize_text_field', 6 );
    6161
    62 
    6362/**
    6463 * Template Compatibility.
    6564 *
     
    353352 *
    354353 * @since 2.5.0
    355354 *
    356  * @param string $retval Current email content.
    357  * @param string $prop   Email property to check against.
     355 * @param string $retval    Current email content.
     356 * @param string $prop      Email property to check against.
     357 * @param string $transform Either 'raw' or 'replace-tokens'.
    358358 */
    359 function bp_email_plaintext_entity_decode( $retval, $prop ) {
    360         if ( 'content_plaintext' !== $prop ) {
    361                 return $retval;
    362         }
     359function bp_email_plaintext_entity_decode( $retval, $prop, $transform ) {
     360        switch ( $prop ) {
     361                case 'content_plaintext' :
     362                case 'subject' :
     363                        // Only decode if 'replace-tokens' is the current type.
     364                        if ( 'replace-tokens' === $transform ) {
     365                                return html_entity_decode( $retval, ENT_QUOTES );
     366                        } else {
     367                                return $retval;
     368                        }
     369                        break;
    363370
    364         return html_entity_decode( $retval, ENT_QUOTES );
     371                default :
     372                        return $retval;
     373                        break;
     374        }
    365375}
    366 add_filter( 'bp_email_get_property', 'bp_email_plaintext_entity_decode', 10, 2 );
     376add_filter( 'bp_email_get_property', 'bp_email_plaintext_entity_decode', 10, 3 );
    367377
    368378/**
    369379 * Replace the generated password in the welcome email with '[User Set]'.
  • tests/phpunit/testcases/core/class-bp-email.php

     
    267267
    268268                $this->assertTrue( $result );
    269269        }
     270
     271        public function test_html_entities_are_decoded_in_email_subject() {
     272                // Emulate custom post title for an email post type.
     273                $subject = "It's pretty <new & magical.";
     274
     275                $email = new BP_Email( 'activity-at-message' );
     276                $email->set_subject( $subject )->set_tokens( array( 'poster.name' => 'blah' ) );
     277
     278                // Subject always has to have tokens replaced before sending.
     279                $this->assertSame( $subject, $email->get_subject( 'replace-tokens' ) );
     280        }
     281
     282        public function test_html_entities_are_decoded_in_email_recipient_names() {
     283                // Raw display name.
     284                $name = "Test o'Toole";
     285
     286                // Emulate rendered {poster.name} token.
     287                $token = apply_filters( 'bp_core_get_user_displayname', $name );
     288
     289                $email = new BP_Email( 'activity-at-message' );
     290                $email->set_subject( '{{poster.name}}' )->set_tokens( array( 'poster.name' => $token ) );
     291
     292                // Subject always has to have tokens replaced before sending.
     293                $this->assertSame( $name, $email->get_subject( 'replace-tokens' ) );
     294        }
     295
    270296}