I have a plugin that adds a new admin screen in an iframe. I created a PHP file in my plugin, and I put a link with a class of Thickbox to that. Everything works just fine, but it produces a PHP error when WP_DEBUG is set to true. Looking at the WordPress source code, there's no way around the error if I put a PHP from outside /wp-admin/ directly in an iframe.

Notice: Undefined offset: 1 in .../wp-includes/vars.php on line 28

It happens because WordPress is running regex on the web address to extract the file name to set the $pagenow variable, but it assumes the file will be in /wp-admin/. Since it's not, there are no matches.

Here is the plugin. The file is children.php.

Is there a better way to create a custom admin screen that can be included in an iframe Thickbox that runs through a /wp-admin/ file?

  • Dion Hulse pointed me in the right direction on Twitter. I'll post a full write-up soon. [wp-admin/admin-post.php + add_action + iframe_header() + echo body + iframe_footer()]
    – Randy Hoyt
    Nov 3, 2012 at 16:36
  • Did you ever figure this out? I've tried interpreting Dion Hulse's directions a few different ways, but can't get this to work. It's one of those things that it seems the WordPress team never intended to be extended. Dec 3, 2012 at 6:19
  • 1
    @MattVanAndel, working sample bellow ;)
    – brasofilo
    Dec 22, 2012 at 2:16

1 Answer 1


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() 
        '<span style="color:#e57300;">Thickbox</span>', 
        '', // no icon
        1 // create before Dashboard menu item

function wpse_71437_submenu_page() 
    <div id="icon-upload" class="icon32"></div><h2>Thickbox</h2>
    <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;

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() 
        null, // doesn't show up in the menu, attached to "index.php" (not sure why)

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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