Skip to content

Instantly share code, notes, and snippets.

@adamsilverstein
Last active August 29, 2015 14:04
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adamsilverstein/7741b38133fe3a593382 to your computer and use it in GitHub Desktop.
Save adamsilverstein/7741b38133fe3a593382 to your computer and use it in GitHub Desktop.
Allow on* JS handlers for IMG elements in WordPress / TinyMCE 4
add_filter( 'tiny_mce_before_init', 'my_mce_init', 20 );
function my_mce_init( $init ) {
if ( current_user_can('unfiltered_html') ) {
if ( ! empty( $init['extended_valid_elements'] ) ) {
$init['extended_valid_elements'] .= ',';
} else {
$init['extended_valid_elements'] = '';
}
$init['extended_valid_elements'] .= 'img[id|accesskey|class|dir|lang|style|tabindex|title|contenteditable|contextmenu|draggable|dropzone|hidden|spellcheck|translate|src|alt=|usemap|ismap|width|height|name|longdesc|align|border|hspace|vspace|crossorigin|onclick|ondblclick|onmousedown|onmouseenter|onmouseleave|onmousemove|onmouseover|onmouseout|onmouseup|onkeydown|onkeypress|onkeyup]';
}
return $init;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment