Localize variables with TinyMCE script

I am writing a plugin that has variables that I would like to localize for use within TinyMCE. The logical choice seemed to me to localise them with the enqueued TinyMCE script itself like so:

public function localize_variables() {
    wp_localize_script( 'tinymce', 'varName', 'value' );
}
add_action( 'admin_enqueue_scripts', 'localize_variables' );

However I can’t find where TinyMCE is being enqueued!

Read More

I put this little function at the bottom of my functions page and ran it on my Admin edit posts page:

function my_inspect_scripts() {
    global $wp_scripts;
    print_r($wp_scripts);
}
add_action( 'wp_print_scripts', 'my_inspect_scripts' );

After going through the data dump I noticed that TinyMCE was not in the list of scripts being enqueued! However the script its self was being loaded as a resource within the browser.

I feel like I am missing something here.

Related posts

1 comment

  1. Looks as though Tiny MCE is not enqueued. Looks like it is loaded through the _WP_Editors class in class-wp-editor.php.

    There is a action hook in there called before_wp_tiny_mce where you can output a script with some localised variables… This is what I am going to do.

Comments are closed.