我有一个会员目录网站,需要一些帮助。
我有一个分类,链接到Wordpress中的自定义帖子类型。这允许我将地理区域应用于每个帖子。问题是任何成员如何访问任何给定的帖子也有权更新该区域。我想使区域元变量仅对管理员角色可编辑。这是当前的代码:
function region() {
$labels = array(
'name' => _x( 'Regions', 'Taxonomy General Name', 'text_domain' ),
'singular_name' => _x( 'Region', 'Taxonomy Singular Name', 'text_domain' ),
'menu_name' => __( 'Regions', 'text_domain' ),
'all_items' => __( 'All Items', 'text_domain' ),
'parent_item' => __( 'Parent Item', 'text_domain' ),
'parent_item_colon' => __( 'Parent Item:', 'text_domain' ),
'new_item_name' => __( 'New Item Name', 'text_domain' ),
'add_new_item' => __( 'Add New Item', 'text_domain' ),
'edit_item' => __( 'Edit Item', 'text_domain' ),
'update_item' => __( 'Update Item', 'text_domain' ),
'view_item' => __( 'View Item', 'text_domain' ),
'separate_items_with_commas' => __( 'Separate items with commas', 'text_domain' ),
'add_or_remove_items' => __( 'Add or remove items', 'text_domain' ),
'choose_from_most_used' => __( 'Choose from the most used', 'text_domain' ),
'popular_items' => __( 'Popular Items', 'text_domain' ),
'search_items' => __( 'Search Items', 'text_domain' ),
'not_found' => __( 'Not Found', 'text_domain' ),
);
$args = array(
'labels' => $labels,
'hierarchical' => true,
'public' => true,
'show_ui' => true,
'show_admin_column' => true,
'map_meta_cap' => false,
'show_in_nav_menus' => true,
'show_tagcloud' => true,
);
register_taxonomy( 'region', array( 'installer' ), $args );
} add_action(' init',' region',0);
我尝试过更改' show_ui'为假,但也隐藏它来自管理员。我知道必须有一个简单的解决方案,但我找不到它。
答案 0 :(得分:0)
谢谢Ty,我指的是正确的方向。我添加了一个似乎可以解决问题的if / else语句。见下文:
function region() {
$labels = array(
'name' => _x( 'Regions', 'Taxonomy General Name', 'text_domain' ),
'singular_name' => _x( 'Region', 'Taxonomy Singular Name', 'text_domain' ),
'menu_name' => __( 'Regions', 'text_domain' ),
'all_items' => __( 'All Items', 'text_domain' ),
'parent_item' => __( 'Parent Item', 'text_domain' ),
'parent_item_colon' => __( 'Parent Item:', 'text_domain' ),
'new_item_name' => __( 'New Item Name', 'text_domain' ),
'add_new_item' => __( 'Add New Item', 'text_domain' ),
'edit_item' => __( 'Edit Item', 'text_domain' ),
'update_item' => __( 'Update Item', 'text_domain' ),
'view_item' => __( 'View Item', 'text_domain' ),
'separate_items_with_commas' => __( 'Separate items with commas', 'text_domain' ),
'add_or_remove_items' => __( 'Add or remove items', 'text_domain' ),
'choose_from_most_used' => __( 'Choose from the most used', 'text_domain' ),
'popular_items' => __( 'Popular Items', 'text_domain' ),
'search_items' => __( 'Search Items', 'text_domain' ),
'not_found' => __( 'Not Found', 'text_domain' ),
);
if (current_user_can('administrator') ){
$args = array(
'labels' => $labels,
'hierarchical' => true,
'public' => true,
'show_ui' => true,
'show_admin_column' => true,
'map_meta_cap' => false,
'show_in_nav_menus' => true,
'show_tagcloud' => true,
);
}else{
$args = array(
'labels' => $labels,
'hierarchical' => true,
'public' => true,
'show_ui' => false,
'show_admin_column' => true,
'map_meta_cap' => false,
'show_in_nav_menus' => true,
'show_tagcloud' => true,
);
}
register_taxonomy( 'region', array( 'installer' ), $args );
}
add_action( 'init', 'region', 0 );
然后我根据管理员角色和非管理员角色将show_ui_从true更改为false。如果有人看到更简单的方法,我很乐意看到它。