默认情况下,我相信wordpress背后有一个访问控制或访问管理器,有没有办法全部删除?由于我添加了不同的角色,并且我希望能够控制每个用户级别的每个角色。
问问题
384 次
2 回答
2
看看这个:用户角色编辑器。
它允许您根据权限级别自定义 wordpress 中的每个管理部分/操作
于 2013-05-29T17:29:29.967 回答
1
检查我的代码,以供参考:
它有 3 个不同之处:管理员(和用户 ID = 1)、管理员(选项更少)和没有管理员,选项更少;)
<?php
add_action('wp_before_admin_bar_render', 'customize_admin_bar');
function customize_admin_bar() {
global $wp_admin_bar;
if (is_user_logged_in()) {
if ( (!current_user_can('administrator') or wp_get_current_user()->ID>1)) {
$wp_admin_bar->remove_menu('edit-profile');
//$wp_admin_bar->remove_menu('user-info');
$wp_admin_bar->remove_menu('wp-logo');
$wp_admin_bar->remove_menu('comments');
$wp_admin_bar->remove_menu('new-media');
$wp_admin_bar->remove_menu('new-tvr_booking');
$wp_admin_bar->remove_menu('new-vp_orbitslides');
$wp_admin_bar->remove_menu('orbitslider_settings');
$wp_admin_bar->remove_menu('orbitslider_settings');
//$wp_admin_bar->remove_menu('site-name');
//$wp_admin_bar->remove_menu('dashboard');
/*$wp_admin_bar->add_menu( array(
'id' => 'custom-account',
'parent' => 'my-account',
'title' => __( 'Mi cuenta'),
'href' => '/pedidos/products-page/your-account/'
) );*/
}
}
}
/* TONIWEB BEGINS*/
function wpc_dashboard_widgets() {
global $wp_meta_boxes;
// Today widget
//unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_right_now']);
// Last comments
if (is_user_logged_in() && (!current_user_can('administrator') or wp_get_current_user()->ID>1)) {
unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_recent_comments']);
// Incoming links
unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_incoming_links']);
// Plugins
unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_plugins']);
unset($wp_meta_boxes['dashboard']['normal']['core']['ts_dashboard']);
unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_quick_press']);
unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_primary']);
unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_secondary']);
unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_right_now']);
}
}
function remove_menus () {
global $menu;
if (is_user_logged_in() && (!current_user_can('administrator') or wp_get_current_user()->ID>1)) {
$restricted = array(__('Dashboard'), __('Links'), __('Media'), __('Appearance'), __('Tools'), __('Settings'), __('Comments'), __('Plugins'),__('Slides'),__('Posts'),__('Profile'),__('Pages'),__('Users'));
end ($menu);
while (prev($menu)){
$value = explode(' ',$menu[key($menu)][0]);
if(in_array($value[0] != NULL?$value[0]:"" , $restricted)){unset($menu[key($menu)]);}
}
}
}
function remove_add_new(){
if (is_user_logged_in() && (!current_user_can('administrator'))) {
if('tvr_booking' == get_post_type()){
echo '<style type="text/css">
.add-new-h2{display:none;}
#menu-posts-tvr_booking .wp-submenu-wrap {
display: none;
}
.subsubsub .all, .subsubsub .publish, .subsubsub .trash {
display: none;
}
</style>';
}
if('tvr_apartment' == get_post_type()){
echo '<style type="text/css">
.subsubsub .all, .subsubsub .publish, .subsubsub .trash {
display: none;
}
</style>';
}
echo '<style>#normal-sortables .versions,#normal-sortables .table_discussion {
visibility: hidden;
}</style>';
}
}
add_action('admin_head','remove_add_new');
add_action('wp_dashboard_setup', 'wpc_dashboard_widgets');
add_action('admin_menu', 'remove_menus');
add_action('admin_head', 'remove_menus');
?>
于 2013-05-29T17:33:59.770 回答