• Resolved Alex Moss

    (@alexmoss)


    Hey guys,

    Great plugin, using it more and more now in child theme dev. One question I have – I’ve tried to insert a <script> into the WYSIWYG and when I hit save, not only does it not appear to seems to ignore the rest of the saving of the post itself. Why is this happening and how do I avoid this saving issue happen and enable the script to save in the Meta Box and appear on the frontend?

    Thanks!

    https://ww.wp.xz.cn/plugins/cmb2/

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    I believe this is because of the kses filtering that goes on and possibly unfiltered_html capabilities. Not stuff specific to CMB2, but more WordPress in general.

    Thread Starter Alex Moss

    (@alexmoss)

    Thanks for this. Is there a workaround at all?

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    You should be able to change the sanitization and escape callbacks on the individual fields, which could allow you to specify one that wouldn’t strip the script tags out.

    Another idea would be to just use a shortcode for where the script tags should be inserted, and then run the fields through do_shortcode() when it comes time to display the content, and the script tags could be inserted at that point.

    Thread Starter Alex Moss

    (@alexmoss)

    Thanks, but the issue isn’t displaying on the frontend but more about saving the field within the backend. Clicking save doesn’t apply that change, and also affects sortable group field that the wysiwyg is placed within.

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    I have to wonder if filtering in script to the sanitization functions would help.

    http://www.goldenapplewebdesign.com/wordpress-take-control-of-html-tag-filtering/

    I’m pretty sure this is because of the WP_Editor that’s being used for the WYSIWYG aspect. My hunch also say it’d be fine if it was just a standard textarea, because of filters run on the first one.

    Thread Starter Alex Moss

    (@alexmoss)

    None of this worked. Inserting a script is fine in the post body of a normal post (I don’t use post body in the CPT I’m using the META box for) but not within the WYSIWYG option. I don’t want to use textarea too.

    Thread Starter Alex Moss

    (@alexmoss)

    Ah wait, more fiddling and did it! I added this to my functions.php file should anyone else need it:

    function script_allowed_tags() {
        global $allowedposttags;
        $allowedposttags['script'] = array(
         'type' => array(),
         'src' => array()
     );
    }
    add_action('init', 'script_allowed_tags', 10);
Viewing 7 replies - 1 through 7 (of 7 total)

The topic ‘Scripts inside WYSIWYG’ is closed to new replies.