Wordpress插件中没有AdminMenu

时间:2014-06-05 07:45:32

标签: wordpress wordpress-plugin

我正在创建一个插件,我在该插件中有一个显示注册列表的页面。

在该页面上,我想创建一个按钮来打印注册列表。

单击该按钮时,将打开一个带有window.print()的新页面;在身体标签。页面已打印。

但是,在该页面上,Wordpress会将管理菜单设置为页脚,也会打印出来。

我想在没有管理员菜单页脚的情况下打印该页面。所以我的问题是:如何在我自己的插件中创建一个不显示Wordpress菜单的页面,但只是纯文本

2 个答案:

答案 0 :(得分:3)

在搜索brasofilo的解决方案以便开始工作的过程中,我发现使用了GET variable noheader

这很有效。只需将&noheader添加到您的网址,您就没有菜单。

答案 1 :(得分:1)

基于Custom Admin Screen in iframe Thickbox。我们可以在Thickbox中打开一个管理页面,防止WP呈现其元素。

诀窍是在加载WP的其余部分之前,用挂钩load-$our_hidden_page_slugexit拦截子菜单页面。

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;
}