admin管理员组文章数量:1391975
I need to be able to stop contributors to the website from adding new Tags when they create or edit a Post in WP.
The reason is that I need them to enter an additional field at the same time which I can achieve via ACF in the edit-tags.php page.
However, no matter what I do I can't seem to stop users entering new tags on the tag section on the new post or edit post page(s). They should still be able to select from existing tags when creating/editing a post, but to enter one they should be forced to use the edit-tags.php.
Here's what I've got so far (edited after discussions below):
function disallow_insert_term($term, $taxonomy) {
if( strstr($_SERVER['REQUEST_URI'], 'wp-admin/post-new.php') || strstr($_SERVER['REQUEST_URI'], 'wp-admin/post.php') ) {
return new WP_Error(
'disallow_insert_term',
__('Your role does not have permission to add terms to this taxonomy')
);
} elseif (strstr($_SERVER['REQUEST_URI'], 'wp-admin/edit-tags.php')) {
return $term;
} else {
return $term;
}
}
add_filter('pre_insert_term', 'disallow_insert_term', 10, 2);
The problem is that any new "if" tests I try to do within the function end up being ignored and just the final task runs. So, in the above, the user can enter new tags on any page. If I remove the "elseif" function you can't enter any tags into the site at all.
I've tried using get_current_screen() and $wp->request to get the URL but just run into the same problem.
本文标签: adminForce Contributors to add Tags via edittagsphp
版权声明:本文标题:admin - Force Contributors to add Tags via edit-tags.php 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744664025a2618421.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论