WordPress SimplePie modifications

SimplePie in WordPress uses the built-in kses sanitization, rather than SimplePie’s. Instead, you can filter on wp_kses_allowed_html and add your elements there. Keep in mind that this will occur for all post santization, not just via SimplePie.

function se87359_add_allowed_tags($tags) {
    $tags['mytag'] = array('myattr' => true);
    return $tags;
}
add_filter('wp_kses_allowed_html', 'se87359_add_allowed_tags');

If you want to do it just for feeds, something like the following should work:

/**
 * Add in our filter when we run fetch_feed()
 */
function se87359_add_filter( &$feed, $url ) {
    add_filter('wp_kses_allowed_html', 'se87359_add_allowed_tags');
}
add_filter( 'wp_feed_options', 'se87359_add_filter', 10, 2 );

function se87359_add_allowed_tags($tags) {
    // Ensure we remove it so it doesn't run on anything else
    remove_filter('wp_kses_allowed_html', 'se87359_add_allowed_tags');

    $tags['mytag'] = array('myattr' => true);
    return $tags;
}

Leave a Comment