Error with Custom Admin Screen in iframe Thickbox

Interesting question.
Investigating it, I’ve found a [wp-hackers] thread by the same Dion Hulse which gives a bit more of information.

First, a testing page with a simple link which will open another admin page in a thickbox.

add_action('admin_menu', 'wpse_71437_admin_submenu');

function wpse_71437_admin_submenu() 
{
    add_menu_page(
        'TB', 
        '<span style="color:#e57300;">Thickbox</span>', 
        'edit_pages', 
        'open_hidden_page_in_thickbox', 
        'wpse_71437_submenu_page',
        '', // no icon
        1 // create before Dashboard menu item
    );
}

function wpse_71437_submenu_page() 
{
    wp_enqueue_style('thickbox');
    wp_enqueue_script('thickbox');
    ?>
    <div id="icon-upload" class="icon32"></div><h2>Thickbox</h2>
    <br><br>
    <a href="#" id="open-tb">Click Here</a>

    <script type="text/javascript">
    jQuery(document).ready(function() {   
        jQuery("#open-tb").click(function() {                 
            tb_show("", "index.php?page=video_page_hidden&TB_iframe=true");
            return false;
        });
    });             
    </script>
    <?php
}

Now, the page that will be opened in the thickbox. It’s parent is defined as null, so it doesn’t show up in the menu. And the callback is an empty function, if accessed directly nothing appears.

/**
 * Add a hidden and empty submenu page
 */
add_action('admin_menu', 'wpse_71437_admin_menu');

function wpse_71437_admin_menu() 
{
    add_submenu_page(
        null, // doesn't show up in the menu, attached to "index.php" (not sure why)
        'Video', 
        'Video', 
        'edit_pages', 
        'video_page_hidden', 
        'wpse_71437_menu_options'
    );
}

function wpse_71437_menu_options() { /* Print nothing */ }

And finally, the trick!
Intercept the hidden page load and print some iframe content:

/**
 * Intercept our hidden/empty page and print the Thickbox content
 */
add_action( 'load-dashboard_page_video_page_hidden', 'wpse_71437_intercept_thickbox' ); 

function wpse_71437_intercept_thickbox() 
{ 
    iframe_header(); 
    echo '<iframe width="100%" height="380px" src="http://www.youtube.com/embed/cL6qe0b-_BA" frameborder="0" allowfullscreen></iframe>';
    iframe_footer(); 
    exit; //Die to prevent the page continueing loading and adding the admin menu's etc. 
}

Leave a Comment