WordPress.org

Ready to get started?Download WordPress

Forums

Change to allow plugins to inject CDATA brackets in scripts (1 post)

  1. kirkpatrick
    Member
    Posted 4 years ago #

    A plugin may paste javascript into the content rather than queuing it into the head. (For example, acting as a filter on the content, the javascript depending on the specific content found.)
    And it is often desirable to bracket the script with CDATA. This is not possible with the current function the_content(), which for some reason applies the CDATA filter after the content filters:

    function the_content($more_link_text = null, $stripteaser = 0) {
    	$content = get_the_content($more_link_text, $stripteaser);
    	$content = apply_filters('the_content', $content);
    	$content = str_replace(']]>', ']]>', $content);
    	echo $content;
    }

    Since the plugin must hook to the the_content filters, its CDATA will be destroyed by the str_replace.

    The fix is to change the order of those two lines -- str_replace before applying the filters.

    Either way the CDATA gets filtered out of the content retrieved or generated by editor, but (presumably trusted) plugins can insert CDATAs. Seems the right way to do it.

    I hope developers will consider this for upcoming releases. (It's unchanged in 2.9.)

Topic Closed

This topic has been closed to new replies.

About this Topic