Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Problem with TinyMCE Buttons Since 3.5 WordPress


I have a plugin which I created and part of the plugin adds a button to the TinyMCE editor which popups up a window and users select a bit text and then it inserts it into the editor.

My problem is since WordPress 3.5 the button has stopped working. I'm not very good at jquery and only familiar enough with TinyMCE to understand how it's suppose to work. The original code I hired someone here to build for the popup window.

Now when a person clicks the TinyMCE button nothing happens at all. Now thinkbox overlay.

Here's the php part of the issue...

// register tinyMCE additional button
function tinyplugin_add_button($buttons) {
global $post;
global $post_type;
if($post && $post->post_type && $post->post_type == 'salesletters') {

array_push($buttons, "|", "tinySampleText");
array_push($buttons, "|", "code");
array_push($buttons, "|", "add_image");
return $buttons;


function tinyplugin_register($plugin_array) {
$plugin_array['tinySampleText'] = WP_PLUGIN_URL.'/wp-sales-letter/tinymcepop/tinyMCE_custom.js';
return $plugin_array;

// register required jquery plugin & css
function jQ_tools() {
wp_enqueue_script('jquerytools', TPATH.'/', array('jquery'), '1.2.5');
wp_register_style('tinyMCE_custom_style', TPATH.'/tinyMCE_custom.css');

function show_tinyMCE_dialog(){

global $contents;
if(!is_array($contents)) return;
<div id="sample_text_box">
<label id="category_sample_label" for="category_sample">Select Category</label>
<select id="category_sample">
<option value="0">none</option>
<?php foreach ($contents as $category => $data){ ?>
<option value="<?php echo str_replace(' ','',$data['category']); ?>"><?php echo $data['category'] ?></option>
<?php } ?>
<?php foreach ($contents as $category => $data){ ?>
<div id="<?php echo str_replace(' ','',$data['category']); ?>" class="category_sample_text" style="display:none">
<?php foreach ($data['text'] as $text){ ?>
<span><?php echo $text; ?></span>
<?php } ?>
<?php } ?>
<div id="preview_tinyMCE">
$content = '';
$id = 'sample_text_editor';
$settings = array( 'textarea_rows' => '3');
wp_editor( $content, $id, $settings); ?>

<button type="button" class="button add-tinyMCE-text">Add Text</button>
<button type="button" class="button cancel-tinyMCE-text">Cancel</button>

Here's the JQuery Part of the issue... I'm not sure which is the problem...


var targetEditor;


var api_overlay = $('#sample_text_box').data("overlay");

function tiny_plugin() {
return "[tiny-plugin]";

(function() {
tinymce.create('tinymce.plugins.tinyplugin', {
init : function(ed, url){
ed.addButton('tinySampleText', {
title : 'Insert Sample Text',
onclick : function() {

targetEditor =;

image: url + "/custom-tinyMCE.png"

tinymce.PluginManager.add('tinySampleText', tinymce.plugins.tinyplugin);


var uniqueID = $(':selected',this).val();
if(uniqueID) $('#'+ uniqueID).show();

$('.category_sample_text span').each(function(){
var content = $(this).html();


var inserted_content = tinyMCE.getInstanceById('sample_text_editor').getContent(),
formatted = inserted_content.replace(/^<p>+|<\/p>+$/g, '')

tinyMCE.execInstanceCommand(targetEditor, 'mceInsertContent', false, formatted);
$('#content').html(function(){ return $(this).html()+formatted});



$('#category_sample option:selected').removeAttr('selected');
$("#category_sample option[value='0']").attr('selected', 'selected');


Answers (2)


Christianto answers:

Please change javascript part to this

Hope this help

Armand Morin comments:

That worked perfectly.!


Arnav Joy answers:

did you checked console for any js error?

Armand Morin comments:

Yes, no js error.