我正在创建一个插件,我在该插件中显示了一个注册列表。WordPress插件中没有AdminMenu
在该页面上,我想制作一个按钮来打印注册列表。
点击该按钮后,会打开一个新页面,并显示一个window.print();在身体标签。该页面已打印。
但是,在该页面上,Wordpress放置了管理菜单页脚,它们也被打印。
我想打印没有管理菜单页脚的页面。所以我的问题是:如何在我自己的插件中创建一个不显示Wordpress菜单但仅显示纯文本的页面
我正在创建一个插件,我在该插件中显示了一个注册列表。WordPress插件中没有AdminMenu
在该页面上,我想制作一个按钮来打印注册列表。
点击该按钮后,会打开一个新页面,并显示一个window.print();在身体标签。该页面已打印。
但是,在该页面上,Wordpress放置了管理菜单页脚,它们也被打印。
我想打印没有管理菜单页脚的页面。所以我的问题是:如何在我自己的插件中创建一个不显示Wordpress菜单但仅显示纯文本的页面
在搜索brasofilo的解决方案以获得工作时,我发现使用了GET variable noheader。
这很好。只需将&noheader
添加到您的网址,并且您没有菜单。
太简单了! – brasofilo
基于Custom Admin Screen in iframe Thickbox。我们可以在Thickbox内打开一个管理页面,并阻止WP呈现其元素。
诀窍是在加载WP的其余部分之前拦截其子程序页面,其执行钩子load-$our_hidden_page_slug
和exit
。
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;
}
请解释“在插件中加载页面”。这个按钮在哪里?任何相关的示例代码? – brasofilo
改变了这个问题,所以希望现在有点更清楚 – AgeDeO
是的,目标是明确的,但我希望看到您的当前实现“打开一个新的页面”,该页面是,你如何制作它?它是'add_submenu_page(null,/ * etc * /);'? – brasofilo