graham73may
6/14/2016 - 12:48 PM

Add to TinyMCE Config

Add to TinyMCE Config

<?php 
/**
 * Customize TinyMCE's configuration
 *
 * @param   array
 *
 * @return  array
 */
function configure_tinymce($in)
{

    $in['plugins'] = 'paste';

    $in['paste_preprocess'] = "function(plugin, args){
        // Strip all HTML tags except those we have whitelisted
        var whitelist = 'p,span,b,strong,i,em,h3,h4,h5,h6,ul,li,ol';
        var stripped = jQuery('<div>' + args.content + '</div>');
        var els = stripped.find('*').not(whitelist);
        
        for (var i = els.length - 1; i >= 0; i--) {
          var e = els[i];
          jQuery(e).replaceWith(e.innerHTML);
        }
        
        // Strip all class and id attributes
        stripped.find('*').removeAttr('id').removeAttr('class').removeAttr('style');
        
        // Return the clean HTML
        args.content = stripped.html();
    }";

    return $in;
}

add_filter('teeny_mce_before_init', 'configure_tinymce');