How to open target blank in a custom admin sub men

2019-02-11 02:23发布

Here is my external link menu function for admin area:

##CACHE MENU
add_action('admin_menu', 'mariCacheDel');
function mariCacheDel() {
    global $submenu;
    $url = get_bloginfo('wpurl').'/cache/?do=deleteAll';
    $submenu['themes.php'][] = array('MARIA CACHE', 'manage_options', $url);
}

How can we open a _blank browser window with this link?

标签: wordpress
1条回答
smile是对你的礼貌
2楼-- · 2019-02-11 03:12

It has to be with jQuery and using a small trick in the admin_menu to insert a target div with an ID:

add_action('admin_menu', 'mariCacheDel');
function mariCacheDel() {
    global $submenu;
    $submenu['themes.php'][] = array(
            '<div id="maricache">MARIA CACHE</div>', // <-- trick
            'manage_options', 
            site_url( '/cache/?do=deleteAll' )
    );
}

add_action( 'admin_footer', 'make_maricache_blank' );    
function make_maricache_blank()
{
    ?>
    <script type="text/javascript">
    jQuery(document).ready(function($) {
        $('#maricache').parent().attr('target','_blank');
    });
    </script>
    <?php
}
查看更多
登录 后发表回答