Created
February 12, 2013 04:29
-
-
Save lgedeon/4760250 to your computer and use it in GitHub Desktop.
strips control characters from feed content
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// non-prefixed version submited to core as patch | |
function tc_strip_for_xml( $string ) { | |
// Store the site charset as a static to avoid multiple calls to get_option() | |
static $is_utf8; | |
if ( ! isset( $is_utf8 ) ) { | |
$is_utf8 = in_array( get_option( 'blog_charset' ), array( 'utf8', 'utf-8', 'UTF8', 'UTF-8' ) ); | |
} | |
if ( ! $is_utf8 ) { | |
return $string; | |
} | |
return preg_replace( '/[^\x{0009}\x{000a}\x{000d}\x{0020}-\x{D7FF}\x{E000}-\x{FFFD}]+/u', ' ', $string ); | |
} | |
function tc_the_content_strip_for_xml( $content ) { | |
if ( is_feed() ) | |
$content = tc_strip_for_xml( $content ); | |
return $content; | |
} | |
add_filter( 'the_content', 'tc_the_content_strip_for_xml' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment