tinymce modal and I18n strings methods

While I can’t see any major fault in doing the way I proposed initially especially in relation to translation and localization, what I realised while researching this issue was that I was asking an ajax question. Basically what’s the most efficient method to initialize the I18n components of wordpress. Short of making a custom ajax hook like I had above, I can leverage the ajax plugin api which has a number of benefits:

  1. Possibly faster as it may be loading less of WP core then directly bootstrapping WP
  2. Security as wp_ajax provides a structure helps keep me from doing something stupid
  3. We’re not chasing the location of core files in the case of custom builds
  4. We also have the js global ajaxurl while in the admin

An implementation would look something like the following:

First we set up a function to output the processed file:

function dynaminc_modal() {
   ob_start();
   header('Content-Type: text/html; charset=utf-8');
   include plugin_dir_url( __FILE__ ) . '/path/to/dynamic_modal.php';
   $string = ob_get_clean();
   exit($string);
}

And add the ajax action*:

add_action('wp_ajax_dynamic_modal', 'dynamic_modal');

We will be able to call the file like so (truncated from above):

    ed.windowManager.open({
        file : url + ajaxurl + "?action=dynaminc_modal", // ajaxurl is a global var in WP admin
        width : ... ,
        height : ...,
        inline : 1
        }, ....

wp_ajax in this context will load a streamlined version of wp core.