Skip to:
Content

BuddyPress.org

Ticket #7084: 7084.01.patch

File 7084.01.patch, 2.4 KB (added by r-a-y, 3 years ago)
  • src/bp-core/bp-core-filters.php

     
    7878// Prevent DB query for WP's main loop.
    7979add_filter( 'posts_pre_query', 'bp_core_filter_wp_query', 10, 2 );
    8080
     81// oEmbeds.
     82add_filter( 'bp_embed_oembed_html', 'bp_embed_filter_at_mention_oembed_html' );
     83
    8184/**
    8285 * Prevent specific pages (eg 'Activate') from showing on page listings.
    8386 *
  • src/bp-core/bp-core-functions.php

     
    17701770        return ! empty( $retval ) ? $retval : false;
    17711771}
    17721772
     1773/**
     1774 * Replace the "@" sign in oEmbed responses with the HTML equivalent '@'
     1775 *
     1776 * If an oEmbed response returns a string such as "This is awesome,
     1777 * @twitteruser", we shouldn't convert "@twitteruser" into a link. Since our
     1778 * at-mention filter looks explicitly for the "@" character, let's replace
     1779 * the "@" character with "@", which ensure our filter will skip these
     1780 * instances.
     1781 *
     1782 * @since 2.7.0
     1783 *
     1784 * @param string $retval Current oEmbed HTML.
     1785 */
     1786function bp_embed_filter_at_mention_oembed_html( $retval ) {
     1787        // No "@" sign, so skip!
     1788        if ( false === strpos( $retval, '@' ) ) {
     1789                return $retval;
     1790        }
     1791
     1792        return preg_replace( '/@(?![^<]*<\/a>)/', '&#64;', $retval );
     1793}
     1794
    17731795/** Admin *********************************************************************/
    17741796
    17751797/**
  • new file tests/phpunit/testcases/core/functions/bpEmbedFilterAtMentionOEmbedHTML.php

    new file mode 100644
    - +  
     1<?php
     2
     3/**
     4 * @group core
     5 * @group functions
     6 * @group embed
     7 * @group bp_embed_filter_at_mention_oembed_html
     8 */
     9class BP_Tests_Core_Functions_BPEmbedFilterAtMentionOEmbedHTML extends BP_UnitTestCase {
     10
     11        public function test_only_replace_non_at_mention_links() {
     12                $retval = 'This is an @mention for me.
     13
     14This is <a href="http://buddypress.org">@shouldnotbeconverted</a>.
     15
     16This is an @mention for me.';
     17
     18                $replaced = bp_embed_filter_at_mention_oembed_html( $retval );
     19
     20                $this->assertFalse( strpos( $replaced, '&#64;shouldnotbeconverted' ) );
     21                $this->assertEquals( 2, substr_count( $replaced, '&#64;mention' ) );
     22        }
     23}