TinyMCE WordPress Plugin Clickable Image


Sam Kogan|

I'm trying to create a simple WordPress plugin for TinyMCE editor, add a button in the editor bar, when you click the button, it will insert an image in the content, and I want the image to be available to read the image's People click publish and run some javascript when that happens (basically just to open a new window with a certain size).

My problem is that TinyMCE strips the onClick event that I add to the image hyperlink, so it doesn't work. I know one way to fix this is to change the valid_elements section of TinyMCE, but that would involve anyone installing the plugin having to make those changes manually. Is it possible to still run some JS when the reader just clicks the image in my plugin?

Brasofilo

Should be a matter of extending TinyMCE valid elements in your own plugin. Here is an example of adding an image tag with all attributes enabled:

add_filter( 'tiny_mce_before_init', function ( $init ) {
    $img = 'img[*]';
    if ( isset( $init['extended_valid_elements'] ) ) {
        $init['extended_valid_elements'] .= ',' . $img;
    } else {
        $init['extended_valid_elements'] = $img;
    }
    return $init;
});

The following content was used when inserting the following into the post content when creating the TinyMCE button :<img>

ed.addButton( 'test_button', {
    title : 'Insert clickable image',
    image : '../wp-includes/images/smilies/icon_eek.gif',
    onclick : function() {
        ed.selection.setContent( '<img src="http://example.com/test.gif" onclick="alert()" />' );
    }
});

Related


TinyMCE WordPress Plugin Clickable Image

Sam Kogan| I'm trying to create a simple WordPress plugin for the TinyMCE editor, add a button in the editor bar, when you click the button, it will insert an image in the content, and I want the image to be available to read the image's People click publish a

TinyMCE WordPress Plugin Clickable Image

Sam Kogan| I'm trying to create a simple WordPress plugin for TinyMCE editor, add a button in the editor bar, when you click the button, it will insert an image in the content, and I want the image to be available to read the image's People click publish and r

TinyMCE WordPress Plugin Clickable Image

Sam Kogan| I'm trying to create a simple WordPress plugin for TinyMCE editor, add a button in the editor bar, when you click the button, it will insert an image in the content, and I want the image to be available to read the image's People click publish and r

TinyMCE WordPress Plugin Clickable Image

Sam Kogan| I'm trying to create a simple WordPress plugin for TinyMCE editor, add a button in the editor bar, when you click the button, it will insert an image in the content, and I want the image to be available to read the image's People click publish and r

TinyMCE WordPress Plugin Clickable Image

Sam Kogan| I'm trying to create a simple WordPress plugin for TinyMCE editor, add a button in the editor bar, when you click the button, it will insert an image in the content, and I want the image to be available to read the image's People click publish and r

TinyMCE WordPress Plugin Clickable Image

Sam Kogan| I'm trying to create a simple WordPress plugin for TinyMCE editor, add a button in the editor bar, when you click the button, it will insert an image in the content, and I want the image to be available to read the image's People click publish and r

TinyMCE WordPress Plugin Clickable Image

Sam Kogan| I'm trying to create a simple WordPress plugin for TinyMCE editor, add a button in the editor bar, when you click the button, it will insert an image in the content, and I want the image to be available to read the image's People click publish and r

TinyMCE WordPress Plugin Clickable Image

Sam Kogan| I'm trying to create a simple WordPress plugin for the TinyMCE editor, add a button in the editor bar, when you click the button, it will insert an image in the content, and I want the image to be available to read the image's People click publish a

TinyMCE WordPress Plugin Clickable Image

Sam Kogan| I'm trying to create a simple WordPress plugin for the TinyMCE editor, add a button in the editor bar, when you click the button, it will insert an image in the content, and I want the image to be available to read the image's People click publish a

TinyMCE WordPress Plugin Clickable Image

Sam Kogan| I'm trying to create a simple WordPress plugin for the TinyMCE editor, add a button in the editor bar, when you click the button, it will insert an image in the content, and I want the image to be available to read the image's People click publish a

TinyMCE WordPress Plugin Clickable Image

Sam Kogan| I'm trying to create a simple WordPress plugin for the TinyMCE editor, add a button in the editor bar, when you click the button, it will insert an image in the content, and I want the image to be available to read the image's People click publish a

TinyMCE WordPress Plugin Clickable Image

Sam Kogan| I'm trying to create a simple WordPress plugin for the TinyMCE editor, add a button in the editor bar, when you click the button, it will insert an image in the content, and I want the image to be available to read the image's People click publish a

TinyMCE WordPress Plugin Clickable Image

Sam Kogan| I'm trying to create a simple WordPress plugin for the TinyMCE editor, add a button in the editor bar, when you click the button, it will insert an image in the content, and I want the image to be available to read the image's People click publish a

TinyMCE WordPress Plugin Clickable Image

Sam Kogan| I'm trying to create a simple WordPress plugin for the TinyMCE editor, add a button in the editor bar, when you click the button, it will insert an image in the content, and I want the image to be available to read the image's People click publish a

TinyMCE WordPress Plugin Clickable Image

Sam Kogan| I'm trying to create a simple WordPress plugin for the TinyMCE editor, add a button in the editor bar, when you click the button, it will insert an image in the content, and I want the image to be available to read the image's People click publish a

TinyMCE WordPress Plugin Clickable Image

Sam Kogan| I'm trying to create a simple WordPress plugin for the TinyMCE editor, add a button in the editor bar, when you click the button, it will insert an image in the content, and I want the image to be available to read the image's People click publish a

tinyMCE custom plugin for WordPress

mark I'm just getting into plugin development for Wordpress. Now I have a function that I pass as a filter to "tiny_mce_before_init" with specific variables to change buttons, add custom styles and other things like that. I'm building an "options page" and I w

tinyMCE custom plugin for WordPress

mark I'm just getting into plugin development for Wordpress. Now I have a function that I pass as a filter to "tiny_mce_before_init" with specific variables to change buttons, add custom styles and other things like that. I'm building an "options page" and I w

tinyMCE custom plugin for WordPress

mark I'm just getting into plugin development for Wordpress. Now I have a function that I pass as a filter to "tiny_mce_before_init" with specific variables to change buttons, add custom styles and other things like that. I'm building an "options page" and I w

tinyMCE custom plugin for WordPress

mark I'm just getting into plugin development for Wordpress. Now I have a function that I pass as a filter to "tiny_mce_before_init" with specific variables to change buttons, add custom styles and other things like that. I'm building an "options page" and I w

tinyMCE custom plugin for WordPress

mark I'm just getting into plugin development for Wordpress. Now I have a function that I pass as a filter to "tiny_mce_before_init" with specific variables to change buttons, add custom styles and other things like that. I'm building an "options page" and I w

WordPress plugin tinymce conflict

tom I am using Wordpress and have installed two plugins on it. Both use the Tinymce WYSIWYG editor. If I activate both plugins at the same time, I get the following error message when the page plugin B is displayed: jquery.js? ver=1.12.3:2 Uncaught Error: Auto

WordPress plugin tinymce conflict

tom I am using Wordpress and have installed two plugins on it. Both use the Tinymce WYSIWYG editor. If I activate both plugins at the same time, I get the following error message when the page plugin B is displayed: jquery.js? ver=1.12.3:2 Uncaught Error: Auto

tinyMCE custom plugin for WordPress

mark I'm just getting into plugin development for Wordpress. Now I have a function that I pass as a filter to "tiny_mce_before_init" with specific variables to change buttons, add custom styles and other things like that. I'm building an "options page" and I w

tinyMCE custom plugin for WordPress

mark I'm just getting into plugin development for Wordpress. Now I have a function that I pass as a filter to "tiny_mce_before_init" with specific variables to change buttons, add custom styles and other things like that. I'm building an "options page" and I w

tinyMCE custom plugin for WordPress

mark I'm just getting into plugin development for Wordpress. Now I have a function that I pass as a filter to "tiny_mce_before_init" with specific variables to change buttons, add custom styles and other things like that. I'm building an "options page" and I w

WordPress plugin tinymce conflict

tom I am using Wordpress and have installed two plugins on it. Both use the Tinymce WYSIWYG editor. If I activate both plugins at the same time, I get the following error message when the page plugin B is displayed: jquery.js? ver=1.12.3:2 Uncaught Error: Auto

Wordpress 4.1 TinyMce Button Plugin

Rexspi I'm trying to add a button on tinymce editor in wordpress WordPress version: 4.1 I followed this tutorial : http://code.tutsplus.com/tutorials/guide-to-creating-your-own-wordpress-editor-buttons--wp-30182 But it doesn't work. I've at least googled the a

Wordpress 4.1 TinyMce Button Plugin

Rexspi I am trying to add a button to the tinymce editor in wordpress WordPress version: 4.1 I followed this tutorial : http://code.tutsplus.com/tutorials/guide-to-creating-your-own-wordpress-editor-buttons--wp-30182 But it doesn't work. I've at least googled