Reputation: 3157
I am creating a plugin, I have a page in that plugin that displays a list of registrations.
On that page I want to make a button to print that list of registrations.
When that button is clicked a new page is opened with an window.print(); in the body tag. The page is printed.
However, on that page, Wordpress places the admin menu en footer, which are also printed.
I would like to print that page without the admin menu en footer. So my question is: How can I create a page in my own plugin that does not show the Wordpress menu's but is just plain text
Upvotes: 2
Views: 125
Reputation: 3157
While searching for brasofilo's solution to get working I found the use of the GET variable noheader.
That works great. Just add &noheader
to your URL and you have no menus.
Upvotes: 4
Reputation: 26055
Based on Custom Admin Screen in iframe Thickbox. We can open an admin page inside a Thickbox and prevent WP from rendering its elements.
The trick is to intercept the submenu page with the hook load-$our_hidden_page_slug
and exit
its execution before it loads the rest of WP.
add_action('admin_menu', 'admin_menu_wpse_71437');
add_action( 'load-dashboard_page_my_hidden_page', 'intercept_thickbox_wpse_71437' );
/**
* Add plugin page and a hidden and empty submenu page
*/
function admin_menu_wpse_71437()
{
add_menu_page(
'TB',
'<span style="color:#e57300;">Thickbox</span>',
'edit_pages',
'open_hidden_page_in_thickbox',
'menu_page_wpse_71437',
'', // no icon
1 // create before Dashboard menu item
);
add_submenu_page(
null, // doesn't shows up in the menu, attached to "index.php"
'Hidden',
'Hidden',
'edit_pages',
'my_hidden_page',
'submenu_page_wpse_71437'
);
}
/**
* Main page
*/
function menu_page_wpse_71437()
{
wp_enqueue_style('thickbox');
wp_enqueue_script('thickbox');
?>
<h2>Print without menu and footer</h2>
<a href="#" id="open-tb"><strong>Print table</strong></a>
<?php print_table_so_24054478(); ?>
<script type="text/javascript">
jQuery(document).ready(function($) {
$("#open-tb").click(function() {
tb_show("", "index.php?page=my_hidden_page&TB_iframe=true");
return false;
});
});
</script>
<?php
}
/**
* Submenu page
*/
function submenu_page_wpse_71437() { /* Do nothing */ }
/**
* Intercept our hidden/empty page and print the Thickbox content
*/
function intercept_thickbox_wpse_71437()
{
iframe_header();
echo '<script>window.print();</script>';
print_table_so_24054478();
exit; // Exit to prevent the page continueing loading and adding the admin menu's etc.
}
/**
* Aux function to echo a table
* from https://github.com/bueltge/WordPress-Admin-Style
*/
function print_table_so_24054478()
{
echo <<<HTML
<table class="widefat">
<thead>
<tr>
<th class="row-title">Table header cell #1</th>
<th>Table header cell #2</th>
</tr>
</thead>
<tbody>
<tr>
<td class="row-title"><label for="tablecell">Table Cell #1, with label</label></td>
<td>Table Cell #2</td>
</tr>
<tr class="alternate">
<td class="row-title"><label for="tablecell">Table Cell #3, with label and class <code>alternate</code></label></td>
<td>Table Cell #4</td>
</tr>
<tr>
<td class="row-title">Table Cell #5, without label</td>
<td>Table Cell #6</td>
</tr>
<tr class="alt">
<td class="row-title">Table Cell #7, without label and with class <code>alt</code></td>
<td>Table Cell #8</td>
</tr>
<tr class="form-invalid">
<td class="row-title">Table Cell #9, without label and with class <code>form-invalid</code></td>
<td>Table Cell #10</td>
</tr>
</tbody>
<tfoot>
<tr>
<th class="row-title">Table header cell #1</th>
<th>Table header cell #2</th>
</tr>
</tfoot>
</table>
HTML;
}
Upvotes: 1