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?
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.
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.And finally, the trick!
Intercept the hidden page load and print some
iframe
content: