您可以删除read
订阅者提供的功能,使他们能够访问仪表板。这最好通过插件上的激活挂钩来完成——只需完成一次。
<?php
register_activation_hook( __FILE__, \'wpse43054_activation\' );
function wpse43054_activation()
{
$role = get_role( \'subscriber\' );
if( $role ) $role->remove_cap( \'read\' );
}
当然,您可能希望在插件停用时恢复该功能。
<?php
register_deactivation_hook( __FILE__, \'wpse43054_deactivation\' );
function wpse43054_deactivation()
{
$role = get_role( \'subscriber\' );
if( $role ) $role->add_cap( \'read\' );
}
最后,你可以
init
如果用户已登录,请重定向他们,尝试访问管理区域,但不具备读取功能。
<?php
add_action( \'init\', \'wpse43054_maybe_redirect\' );
function wpse43054_maybe_redirect()
{
if( is_admin() && ! current_user_can( \'read\' ) )
{
wp_redirect( home_url(), 302 );
exit();
}
}
您可能还想为具有
read
能力。你可以通过
get_user_metadata
并劫持用户元值的检查
show_admin_bar_front
.
<?php
add_filter( \'get_user_metadata\', \'wpse43054_hijack_admin_bar\', 10, 3 );
function wpse43054_hijack_admin_bar( $null, $user_id, $key )
{
if( \'show_admin_bar_front\' != $key ) return null;
if( ! current_user_can( \'read\' ) ) return 0;
return null;
}
所有这些
as a plugin.