wp_localize_script with mce_external_plugins in wordpress

If I understand correctly; you just need to make a Javascript variable available to testing.js.

I think it would be just as useful to send the variable with jQuery, as that would be loaded prior to TinyMCE anyway:

add_action('wp_enqueue_scripts', 'YOUR_NAME_scripts'); //back end

function YOUR_NAME_scripts( $hook_suffix ) {

        global $blog_id;
        $params = array(
            'site_url' => site_url(),
            'admin_ajax_url' => site_url() . '/wp-admin/admin-ajax.php',
            'mytest' => $whatever_variable_value


         );

            wp_localize_script( 'jquery', 'YOUR_JAVASCRIPT_VARIABLE_HOLDER', $params );

}

Then you can access the mytest variable in testing.js by simply using YOUR_JAVASCRIPT_VARIABLE_HOLDER.mytest anywhere in the script.

Leave a Comment