You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何修改代码在WordPress BuddyPress成员列表中排除多个用户ID

修改BuddyPress成员列表代码支持排除多个用户ID

直接替换为以下代码即可实现多用户ID排除,同时兼容已有排除逻辑:

add_action( 'bp_ajax_querystring', 'user_remove_mem_directory', 20, 2 );
function user_remove_mem_directory( $query, $object ) {
    if ( 'members' != $object ){
        return $query;
    }

    // 定义要排除的多个用户ID数组,替换成实际需要的ID即可
    $excluded_users = array(93, 100, 101); 

    $args = wp_parse_args( $query );

    // 合并已有排除参数,避免重复或冲突
    if ( ! empty( $args['exclude'] ) ) {
        $existing_excluded = array_map('intval', explode(',', $args['exclude']));
        $excluded_users = array_unique(array_merge($excluded_users, $existing_excluded));
    }

    // 转换为BuddyPress查询要求的逗号分隔字符串格式
    $args['exclude'] = implode(',', $excluded_users);

    $query = build_query( $args );

    return $query;
}

关键修改点:

  • 将原单个ID变量改为数组$excluded_users,可一次性添加所有需要隐藏的管理员ID
  • 新增已有排除参数的合并逻辑:如果之前有其他代码添加了排除用户,会自动合并并去重,避免重复排除
  • 用implode()将数组转为BuddyPress成员查询所需的逗号分隔字符串格式

内容的提问来源于stack exchange,提问作者morgyface

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.14 17:52:14