Wordpress:根据职位数量有条件地更改角色

Wordpress:根据职位数量有条件地更改角色,wordpress,post,conditional,role,Wordpress,Post,Conditional,Role,自从将近4-5个月以来,我一直在努力解决这个问题,即用户角色会随着一定数量的帖子数量自动改变。假设x用户有我认为启动用户角色有错误,因为: if ( ($user_level != 10) && ( $count > 3 && $count <= 5 ) && ( array_key_exists( 'contributor', $current_role[0] ) ) ) { $user_id_role = n

自从将近4-5个月以来,我一直在努力解决这个问题,即用户角色会随着一定数量的帖子数量自动改变。假设x用户有我认为启动用户角色有错误,因为:

if ( ($user_level != 10) && ( $count > 3 && $count <= 5 ) && ( array_key_exists(     'contributor', $current_role[0] ) ) ) {
        $user_id_role = new WP_User( $author->ID );
        $user_id_role->set_role( 'author' );
如果用户级别为10且帖子数量大于3且小于或等于5,则将用户角色设置为作者

但是在第二种情况下

} elseif ( ($user_level != 10) && ( $count > 5 && $count <= 9 ) && ( array_key_exists( 'author', $current_role[0] ) ) ) {

        $user_id_role = new WP_User( $author->ID );
        $user_id_role->set_role( 'editor' );
您再次指出,只有当用户角色为10时,条件标记才会启动。。。因此,例如,如果用户发布了4篇文章,并且它的角色是author,那么条件标记将不起作用

} elseif ( ($user_level != 10) && ( $count > 5 && $count <= 9 ) && ( array_key_exists( 'author', $current_role[0] ) ) ) {

        $user_id_role = new WP_User( $author->ID );
        $user_id_role->set_role( 'editor' );