Ticket #7084: 7084.01.patch
File 7084.01.patch, 2.4 KB (added by , 7 years ago) |
---|
-
src/bp-core/bp-core-filters.php
78 78 // Prevent DB query for WP's main loop. 79 79 add_filter( 'posts_pre_query', 'bp_core_filter_wp_query', 10, 2 ); 80 80 81 // oEmbeds. 82 add_filter( 'bp_embed_oembed_html', 'bp_embed_filter_at_mention_oembed_html' ); 83 81 84 /** 82 85 * Prevent specific pages (eg 'Activate') from showing on page listings. 83 86 * -
src/bp-core/bp-core-functions.php
1770 1770 return ! empty( $retval ) ? $retval : false; 1771 1771 } 1772 1772 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 */ 1786 function 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>)/', '@', $retval ); 1793 } 1794 1773 1795 /** Admin *********************************************************************/ 1774 1796 1775 1797 /** -
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 */ 9 class 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 14 This is <a href="http://buddypress.org">@shouldnotbeconverted</a>. 15 16 This is an @mention for me.'; 17 18 $replaced = bp_embed_filter_at_mention_oembed_html( $retval ); 19 20 $this->assertFalse( strpos( $replaced, '@shouldnotbeconverted' ) ); 21 $this->assertEquals( 2, substr_count( $replaced, '@mention' ) ); 22 } 23 }