【发布时间】:2017-10-02 10:13:32
【问题描述】:
这就是我想要做的。我正在开发一个插件,我想检查每条评论,看看该评论的作者是否具有“管理员”或“编辑”的角色。如果他们这样做,而不是显示他们的用户名和头像,我想显示网站的名称以及公司徽标或其他东西。我对 WordPress 开发还很陌生,并且一直坚持这一点。我不知道是否有一个过滤器,或者我是否需要创建一个自定义 cmets 模板。如果有人甚至可以让我指出正确的方向,那就太好了,因为在这一点上,我什至不确定我应该从哪里开始。谢谢。
我在哪里,我的思考过程:
<?php
function anonymize_author(){
global $post;
//get the id of the comment author
$author_id = $post->post_author;
//get the userdata of comment author
$author_info = get_userdata($author_id);
//get the user roles of comment author
$author_roles = $author_info->roles;
//Array of roles to check against
$roles_to_check = ["editor", "administrator"];
//see if user has a role in my $roles_to_check array
$results = array_intersect($roles_to_check, $author_roles);
if(!empty($results)){
//the user has roles of either "editor" or "administrator"
//load custom comments page?
//I need to display the author name as the site name
//and the avatar as the site logo
}else{
//Just a regular user, load the Wordpress Default comments
}
}
add_filter('some_filter_here', 'anonymize_author');
【问题讨论】: