admin管理员组文章数量:1333493
I run a multi author blog. I want authors not to be able to publish posts under some categories(Suppose ‘selected’, ‘editorial’). So I want to hide them in post editor.
I tried this code:
add_filter('list_terms_exclusions', 'yoursite_list_terms_exclusions', 10, 2);
function yoursite_list_terms_exclusions( $exclusions, $args ) {
global $pagenow;
if (in_array($pagenow,array('post.php','post-new.php')) &&
!current_user_can('manage_options')) {
$exclusions = " {$exclusions} AND t.slug NOT IN ('selected','editorial')";
}
return $exclusions;
}
But it is not working. I used this code too:
function hide_categories_for_specific_user( $exclusions, $args ){
if (!current_user_can('manage_options') ) {
// IDs of terms to be excluded
$exclude_array = array("5","6"); // CHANGE THIS TO IDs OF YOUR TERMS
// Generation of exclusion SQL code
$exterms = wp_parse_id_list( $exclude_array );
foreach ( $exterms as $exterm ) {
if ( empty($exclusions) )
$exclusions = ' AND ( t.term_id <> ' . intval($exterm) . ' ';
else
$exclusions .= ' AND t.term_id <> ' . intval($exterm) . ' ';
}
// Closing bracket
if ( !empty($exclusions) )
$exclusions .= ')';
// Return our SQL statement
return $exclusions;
}
}
// Finally hook up our filter
add_filter( 'list_terms_exclusions', 'hide_categories_for_specific_user', 10, 2 );
It works in the post editor but it breaks category widget in the front-end for non-admin users.
I used several plugins for that. “Restrict Categories, Author category” etc. But no luck. I am currently hiding them using css :nth-of-type. But works for add new post but it breaks when authors edit their post.
Can anyone help me?
本文标签: Hide Some Categories in Post Editor
版权声明:本文标题:Hide Some Categories in Post Editor 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742341301a2456655.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论