我想检查当前用户是否已经提交了自定义帖子类型的帖子,如果已经提交了,并且他们具有作者角色,然后将内联样式添加到标题以隐藏某些内容。。
这就是我正在尝试的,但它不起作用,我似乎不明白为什么?
function chelsea_user_has_posts($user_id) {
$result = new WP_Query(array(
\'author\'=>$user_id,
\'post_type\'=>\'ait-dir-item\',
\'post_status\'=>\'publish\',
\'posts_per_page\'=>1,
));
return (count($result->posts)!=0);
}
function cross_check_user_items() {
$user = wp_get_current_user();
$chelseaRole = get_the_author_meta(\'user_level\');
if ($user->ID)
if (chelsea_user_has_posts($user->ID) && $chelseaRole == 1) {
echo \'<style type="text/css">
#adminmenuwrap ul#adminmenu li#menu-posts-ait-dir-item.wp-has-submenu ul.wp-submenu li:nth-child(2), body.post-type-ait-dir-item div.wrap h2 a.add-new-h2, #woocommerce-product-data.postbox div.inside div.panel-wrap ul.product_data_tabs li:nth-child(8) {display:none !important;}
</style>\';
} else {
//show them the goods
}
}
add_action(\'admin_head\', \'cross_check_user_items\');
所有这些当然都是我的职责。php文件
感谢您的关注:-)
SO网友:Derek
而不是使用$chelseaRole ==1
应该换成这样的东西!current_user_can(\'manage_categories\')
由于作者角色无法管理此处所示的类别:https://codex.wordpress.org/Roles_and_Capabilities
抛光后的外观如下:
function chelsea_user_has_posts($user_id) {
$result = new WP_Query(array(
\'author\'=>$user_id,
\'post_type\'=>\'ait-dir-item\',
\'post_status\'=>\'publish\',
\'posts_per_page\'=>1,
));
return (count($result->posts)!=0);
}
function cross_check_user_items() {
$user = wp_get_current_user();
if (chelsea_user_has_posts($user->ID) && !current_user_can(\'manage_categories\')) {
echo \'<style type="text/css">
#adminmenuwrap ul#adminmenu li#menu-posts-ait-dir-item.wp-has-submenu ul.wp-submenu li:nth-child(3), body.post-type-ait-dir-item div.wrap h2 a.add-new-h2, #woocommerce-product-data.postbox div.inside div.panel-wrap ul.product_data_tabs li:nth-child(8) {display:none !important;}
</style>\';
} else {
//show them the goods
}
}
add_action(\'admin_head\', \'cross_check_user_items\');