有两个选项,修改菜单链接href
属性或重定向主屏幕。
修改菜单更改全局变量$submenu
. 此方法适用于单站点和多站点<问题:子菜单项Installed Plugins
不以粗体显示。
add_action( \'admin_head\', \'b5f_plugins_redirect_to_active\' );
function b5f_plugins_redirect_to_active()
{
global $submenu;
$submenu[\'plugins.php\'][5][2] .= "?plugin_status=active";
return;
}
重定向页面
load-plugins.php
. 需要多站点检测,但没有UI问题。
add_action( \'load-plugins.php\', \'b5f_ms_plugins_redirect_to_active\' );
function b5f_ms_plugins_redirect_to_active()
{
// Trick, plugin_status is only false in WP default screen
// [\'action\'] prevents us interfering with activation/deactivation
if( isset( $_GET[\'plugin_status\'] ) || isset( $_GET[\'action\'] ) )
return;
// Check for MS dashboard, redirect accordingly
if( is_network_admin() )
wp_redirect( network_admin_url( \'plugins.php?plugin_status=active\' ) );
else
wp_redirect( admin_url( \'plugins.php?plugin_status=active\' ) );
exit();
}
还有一些额外的东西:
1) 将主链接重命名为Active
add_action( \'admin_menu\', \'rename_submenu_item\', 99 );
function rename_submenu_item()
{
global $submenu;
foreach( $submenu[\'plugins.php\'] as $key => $value )
{
if( in_array( \'activate_plugins\', $value ) )
$submenu[\'plugins.php\'][$key][0] = __( \'Active\' );
}
}
添加子菜单以访问
All
子菜单链接被入侵,并且打印了一些jQuery来修复子菜单
active
国家:
add_action( \'admin_menu\', \'menu_admin_wpse_44270\' );
add_action( \'admin_head-plugins.php\', \'highlight_menu_item_wpse_44270\' );
function menu_admin_wpse_44270()
{
add_submenu_page(
\'plugins.php\',
\'Drafts\',
\'<span id="my-all-plugins">All</span>\',
\'edit_pages\',
\'plugins.php?plugin_status=all\'
);
}
function highlight_menu_item_wpse_44270()
{
if( isset( $_GET[\'plugin_status\'] ) && \'all\' == $_GET[\'plugin_status\'] )
{
?>
<script type="text/javascript">
jQuery(document).ready( function($)
{
var reference = $(\'#my-all-plugins\').parent().parent();
// add highlighting to our custom submenu
reference.addClass(\'current\');
//remove higlighting from the default menu
reference.parent().find(\'li:nth-child(2)\').removeClass(\'current\');
});
</script>
<?php
}
}