[wp-hackers] How to prevent loading admin components?

Dion Hulse (dd32) wordpress at dd32.id.au
Mon Jan 4 06:41:24 UTC 2010


You'll need to hook into an early hook in the admin section for your page.

Add
add_action('all', create_function('', 'var_dump(current_filter());'));
to your plugin file,it'll print the name of every action hook which is run.

For example, I can see amongst it all, This hook:  
"load-settings_page_revision-control" for the page  
wp-admin/options-general.php?page=revision-control

Yours will be something like "load-tools_name_of_my_plugin", But it'll  
vary, so if you dump and then look for the action hook starting with  
"load-" you'll be right.

Example code to use would be:

add_action('load-settings_page_revision-control', 'rc_page');
function rc_page() {
	iframe_header();
	echo '<h1>Hello World!</h1>';
	iframe_footer();
	exit; //Die to prevent the page continueing loading and adding the admin  
menu's etc.
}

A tricky thing you can do, Is if you know the page may load in thickbox or  
normal, is to hook that action to thesame as the menu name, and then check  
if it was loaded in TB or not:

add_menu_page('......', 'rc_page');
add_action('load-settings_page_revision-control', 'rc_page_maybe_iframe');

function rc_page_maybe_iframe() {
	if ( isset($_GET['TB_iframe']) )
		return; // If the TB Iframe marker is not set, then its been loaded via  
Thickbox, But if it IS set, then Thickbox has not been used.
	iframe_header();
	rc_page();
	iframe_footer();
	exit; //Die to prevent the page continueing loading and adding the admin  
menu's etc.
}
function rc_page() {
	echo '<h1>Hello World!</h1>';
}

Thats good for users without Javascript, and those of us who Middle-click  
to open in a new tab or whatever.. Get the thickbox without the menu's if  
within thickbox, else get the menu's and a easy way of navigating away  
otherwise.

as for iframe_header(), i'd advise you use those, you can check out the  
code for them in wp-admin/includes/template.php i think, else its misc.php.
reason being, is that it prints the scripts/styles as well as the footer  
stuff and all that..


On Mon, 04 Jan 2010 11:13:56 +1100, Guy <wphax at nullamatix.com> wrote:

> Example link:  
> /wp-admin/tools.php?page=name_of_my_plugin&comment_number=50753
>
> The desired information/data is show; however, in addition to the
> desired information, the entire admin interface is loaded. How can I
> prevent the admin header & nav menus/items from loading when clicking
> that link? The link pops up into a lightbox or other type of pop-up
> window, so reloaded and wrapping the admin interface around the data
> isn't desired.
>
> To illustrate my request ... http://i.imgur.com/kO68A.png
>
> Regards,
>
> Guy
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>


-- 
Dion Hulse / dd32

Contact:
  e: contact at dd32.id.au
  msn: msn at d32.id.au
  skype: theonly_dd32
Web: http://dd32.id.au/


More information about the wp-hackers mailing list