0

I'm developing a plugin, which extends the "add media"-Button in the Post-Editor.

I found an example (I think it was nextGen Galley maybe) where wp_iframe is used in the add media dialog. For some reasons it was quite comfortable to build my stuff the same way.

This is how id I did it:

// add entry to "add media" menu
add_filter('media_upload_tabs', function($tabs) {
    return array_merge($tabs, array('jt' => "jt's plugin"));
});

// my own "add media" page
add_action('media_upload_jt', function() {

    // use plugin stylesheet
    add_action('admin_print_styles-media-upload-popup', function() {
        $cssUrl = plugins_url() .'/jt.css';
        wp_enqueue_style('jt_mediamenu', $cssUrl);
    });
    return wp_iframe('media_jt_dialogue'); 
});


function media_jt_dialogue() {

        /* do some interactive stuff using the iframe 
         * and forms like a boss (not using ajax and pretending it's still 2005)
         */

        /* yeah... and now? */
}

But I don't know what to do next and can't figure it out. I want to return the result of the dialog with the user in the iframe to tinyMCE editor now (in form of a shortcode maybe). But how? I think I've to trigger some Javascript, but I'm sure Wordpress holds a clean default solution for that. Any suggestions? Thank you in advance!

0

I found out myself. I had to call

media_upload_header();

in the Iframe and trigger the following javascript:

var html = 'stuff I want to return to editor';
var win = window.dialogArguments || opener || parent || top;
win.send_to_editor(html);

I have no Idea how, but this works.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.