I'm trying to enable WordPress' tinyMCE editor for a front-end textarea, from a plugin's pro version.
I temporarily solved the issue in a bogus way:
In free version:
wp_editor(
$details_val, //content
'pre-details', //editor ID
array('tinymce'=>false),
);
Then from the pro version, with a filter hook, made the 'tinymce' value to true
. Ha ha ha...
Need a viable solution
Here's my textarea on front end:
<textarea class="tinymce-enabled" rows="5" cols="40" name="pre_details" id="pre-details"><?php echo $details_val; ?></textarea>
I tried the following function in jQuery:
jQuery(document).ready(function($) {
tinymce.init({
selector :"pre-details",
mode : "specific_textareas",
theme : "simple",
editor_selector :"tinymce-enabled"
});
});
And the files are called in the following fashion:
function pre_scripts() {
if( is_page('xyz') ) {
wp_enqueue_script( 'pre-scripts', Pre()->plugin_url() .'/assets/js/pre-scripts.min.js', array('jquery', 'tiny_mce'), Pre()->version, true );
}
}
add_action( 'wp_enqueue_scripts', 'pre_scripts' );
First of all, if I don't use the 'tiny_mce'
dependency the tinymce.init()
shows an error of not finding such function, but my custom script loads. But if I add the 'tiny_mce'
dependency, my custom script doesn't even load. But the hook is mentioned in dev resources.
I found this WPSE thread, that suggests it's an age-old problem. But the workaround represented there, doesn't solve my problem.
I also tried different versions:
$(function() {
$('textarea.tinymce-enabled').tinymce({
mode : "specific_textareas",
theme : "simple",
});
});
and
tinyMCE.execCommand('mceAddControl', false, 'pre-details');
But no luck. Because that dependency dequeues my script,
or, the alternative methods of loading the tinymce core scripts doesn't comply with my scripts.
How can I load the WordPress' tinyMCE Rich Text editor to a textarea on frontend without using wp_editor()
, but in a pluggable way?
wp_editor()
that you're trying to get rid of? Why do you need to break the tinyMCE out ofwp_editor()
. It sounds like you're doing some kind of premium features. You could usewp_eidtor()
to remove all the buttons and tabs so the user just sees a normal textbox. I'm just speculating on what you need from it though.array('tinymce'=>false)
. To me it's a numb way implementing a pro feature. Anyone with a basic knowledge of WordPress can do a simple filter likereturn true
and they can enable tinymce on awp_editor()
field. I think it's not a smart way. How do you people offer rich text support on pro version, while giving a simple textarea on free version?