I am not sure if it is possible or not.

Can i use wp_localize_script with mce_external_plugins filter?

I want to send a variable to the tinymce plugin script. For Example:

add_filter( "mce_external_plugins", array( &$this, 'add_test_plugin' ) );

public function add_test_plugin( $plugin_array ){

    global $pagenow;

    if( is_admin() && $pagenow == "post.php" || $pagenow == "post-new.php" ){
        $plugin_array['mytest'] = plugin_dir_url(__FILE__) . '/js/testing.js';
        return $plugin_array;
    }

}

I have to send a variable to testing.js? How do i achieve this?

Update:

this is the link that help me to resolve my problem Using post ID in custom tinyMCE button

2 Answers
2

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 Reply

Your email address will not be published. Required fields are marked *