是否可以通过操作,挂钩或其他方式自定义Wordpress
我在codex.wordpress.org上找不到任何东西,也没有找到合适的插件。 :-/
谢谢!
答案 0 :(得分:0)
为此,我建议使用诸如User Role Editor之类的插件,但是-这是一个有效的代码示例:):
在类WP_Role
中,您会找到一个名为“ edit_comment”的属性,该属性映射到“ edit_posts”,因此不会作为单独的功能来处理。但是,我们可以通过对要使用map_meta_cap函数限制编辑注释的选定用户角色应用过滤器来修改行为。
示例: 只有用户“管理员”或“编辑者”可以从后端垃圾邮件,垃圾邮件或编辑评论:
<?php
// Restrict editing capability of comments using `map_meta_cap`
function restrict_comment_editing( $caps, $cap, $user_id, $args ) {
if ( 'edit_comment' == $cap ) {
// Allowed roles
$allowed_roles = ['editor', 'administrator'];
// Checks for multiple users roles
$user = wp_get_current_user();
$is_allowed = array_diff($allowed_roles, (array)$user->roles);
// Remove editing capabilities on the back-end if the role isn't allowed
if(count($allowed_roles) == count($is_allowed))
$caps[] = 'moderate_comments';
}
}
return $caps;
}
add_filter( 'map_meta_cap', 'restrict_comment_editing', 10, 4 );
// Hide comment editing options on the back-end*
add_action('init', function() {
// Allowed roles
$allowed_roles = ['editor', 'administrator'];
// Checks for multiple users roles
$user = wp_get_current_user();
$is_allowed = array_diff($allowed_roles, (array)$user->roles);
if(count($allowed_roles) == count($is_allowed)) {
add_filter('bulk_actions-edit-comments', 'remove_bulk_comments_actions');
add_filter('comment_row_actions', 'remove_comment_row_actions');
}
});
function remove_bulk_comments_actions($actions) {
unset($actions['unapprove']);
unset($actions['approve']);
unset($actions['spam']);
unset($actions['trash']);
return $actions;
}
function remove_comment_row_actions($actions) {
unset($actions['approve']);
unset($actions['unapprove']);
unset($actions['quickedit']);
unset($actions['edit']);
unset($actions['spam']);
unset($actions['trash']);
return $actions;
}
?>
代码进入您的 functions.php 文件
答案 1 :(得分:0)
由于@Kradyy,我来到了map_meta_cap和remove_cap。
通过 functions.php 中的以下内容,仪表板的注释部分以及发送给作者的电子邮件(管理员和编辑者除外)中的链接被删除:>
global $wp_roles;
$allowed_roles = ['editor', 'administrator'];
foreach (array_keys($wp_roles->roles) as $role){
if (!in_array($role, $allowed_roles)) {
$wp_roles->remove_cap( $role, 'moderate_comments' );
}
}