請問有辦法在 buddypress 中隱藏管理員嗎?

正在檢視 9 個帖子:1-9 (共 9 個帖子)
  • 作者
    帖子
  • talklaw
    參與者
    • 文章數量: 189
    @talklaw
    樓主

    在 buddypress 的使用者列表中,會顯示管理員,請問如何隱藏呢?只顯示使用者,不顯示 admin?

    謝謝!

    Geticer
    參與者
    • 文章數量: 63
    @monicfenga

    將以下程式碼放在 (子) 主題的 functions.php 檔案裡即可。

    /**
    * Exclude Users from BuddyPress Members List by WordPress role.
    * 從 BuddyPress 成員列表中排除特定 WordPress 角色的成員。
    *
    * @param array $args 引數
    *
    * @return array
    */
    function buddydev_exclude_users_by_role( $args ) {
        // do not exclude in admin.
        if ( is_admin() && ! defined( 'DOING_AJAX' ) ) {
            return $args;
        }
     
        $excluded = isset( $args['exclude'] ) ? $args['exclude'] : array();
     
        if ( ! is_array( $excluded ) ) {
            $excluded = explode( ',', $excluded );
        }
     
        $role     = 'administrator';// 要排除的使用者許可權 change to the role to be excluded.
        $user_ids = get_users( array( 'role' => $role, 'fields' => 'ID' ) );
     
        $excluded = array_merge( $excluded, $user_ids );
     
        $args['exclude'] = $excluded;
     
        return $args;
    }
     
    add_filter( 'bp_after_has_members_parse_args', 'buddydev_exclude_users_by_role' );
    

    via

    talklaw
    參與者
    • 文章數量: 189
    @talklaw
    樓主

    你好,請問直接把這段程式碼貼上去就可以了嘛?需要做什麼調整嘛?

    我把程式碼加入到 functions.php,但還是在 members 列表中看到管理員

    Geticer
    參與者
    • 文章數量: 63
    @monicfenga

    如果自己是以 「管理員」 賬號登入網站的話,還是能看到其他管理員的 (包括自己),是特意設計的,

    其他使用者是看不到管理員的。

    talklaw
    參與者
    • 文章數量: 189
    @talklaw
    樓主

    謝謝指教,請問在哪裡可以修改使用者是否為管理員呢?我建立了一個使用者,但似乎在 wp 的使用者管理中,沒有 bp 的等級設定,只有 bbpress 的等級 (我把這個等級從管理員改為版主,但對於 bp 的使用者顯示似乎沒有改變)

    Geticer
    參與者
    • 文章數量: 63
    @monicfenga

    BuddyPress 直接使用 WordPress 的使用者等級,也叫 「站點角色」 。

    在編輯使用者介面中,找到 「姓名」 部分的 「角色」 下拉框,選擇 「管理員」,然後儲存。

    talklaw
    參與者
    • 文章數量: 189
    @talklaw
    樓主

    謝謝,在站點角色中,我建立的新使用者的角色是編輯,但這個使用者登入後,在會員列表中看到管理賬號,請問以上的程式碼需要做什麼修改嗎?我是直接複製到 functions.php 中的。

    Geticer
    參與者
    • 文章數量: 63
    @monicfenga

    我在自己的測試站裡做了相同的測試,看不到管理員。

    (測試站的 BuddyPress 設定裡,模板包是 「BuddyPress 舊功能」)

    talklaw
    參與者
    • 文章數量: 189
    @talklaw
    樓主

    奇怪,我這裡總是能看到,會不會和主題的機制有關?

正在檢視 9 個帖子:1-9 (共 9 個帖子)
  • 哎呀,回覆話題必需登入。

話題資訊

  • 當前位於:BuddyPress
  • 8 條回覆
  • 2 個參與人
  • 最後回覆:<a href="https://bbs.weixiaoduo.com/users/talklaw/" title=" 檢視 talklaw 的個人資料" class="bbp-author-link"><span class="bbp-author-name">talklaw</span></a>
  • 上次活動:<a href="https://bbs.weixiaoduo.com/topic/38325/#post-38365" title=" 回覆至:請問有辦法在 buddypress 中隱藏管理員嗎?">4 年、 2 月前</a>