2

I have a plugin which saves data via AJAX, and realised that it wasn't sending out any request. I opened up the console to look further, and low and behold when trying to look at the object tinyMCE.activeEditor, it's value is null.

This only seems to be the case when the editor is loaded in 'Text' mode - if you switch back to or load it in 'Visual' the tinyMCE.activeEditor object exists as it should.

I'm reckoning this has something to do with cacheing the 'Text' mode state when it shouldn't be, and each page load should really deliver the 'Visual' mode?

If anyone has come across this issue before and knows a fix without editing core, it would be much appreciated. I haven't posted any snippets because I'm not sure how relevant they would be - but if there's anything you'd like me share that might help resolve this it would be much appreciated and I'd be happy to :).

3 Answers 3

3

Use this one-liner:

if(!tinyMCE.activeEditor)jQuery('.wp-editor-wrap .switch-tmce').trigger('click');

//Now you can use "tinyMCE.activeEditor" safely console.log(tinyMCE.activeEditor.settings);

0

There is simple solution for that.

You need to check if editor is active then set value of editor otherwise set value of text-area.See bellow code.


if(tinyMCE.activeEditor==null)
{

 jQuery("#txtArea").html('your html');
}
else{

 tinyMCE.get('txtArea').setContent('Your html');
}

0

How to get content from Wordpress textarea regadless if in Visual or Text mode:

var content;
if (typeof tinyMCE !== 'undefined' && tinyMCE.activeEditor !== null) {
    content = tinyMCE.activeEditor.getContent();
} else {
    content = $('#content').val();
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.