最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

plugins - How to use get_blogs_of_user?

programmeradmin1浏览0评论

I'm using a plugin that is not built for multisite: Restrict Content Pro Group Accounts.

Now, before it adds a member to a group, it checks if they are already part of a group and gives an error message.

The code it uses is:

if ( rcpga_group_accounts()->members->get_group_id( $user_id ) ) {
        return new WP_Error( 'has-group', __( 'This user is already in a group. Users may only be part of one group at a time.', 'rcp-group-account' ) );
    }

Currently, it only check if the user has an account on the current subsite, and not through the whole network.

I want to extend it to prevent a user on any subsite in the multisite network from being added to a group.

So I took the function above and rewrote it as follows:

$blogs_user = get_blogs_of_user( $user_id );

if ( (rcpga_group_accounts()->members->get_group_id( $user_id )) || (count($blogs_user)>0) ) {

    return new WP_Error( 'has-group', __( 'This user is already in a group. Users may only be part of one group at a time.', 'rcp-group-account' ) );
}

I'm trying to check if the user is a member of any site on the network. If they are, then it means they already have an account, and so an error should be thrown.

My code doesn't work however, and gets triggered even when adding a new user that is not on any site in the network.

What am I doing wrong?

发布评论

评论列表(0)

  1. 暂无评论