【问题标题】:How to segregate the Buddypress member page on multisite?如何在多站点上隔离 Buddypress 会员页面?
【发布时间】:2021-05-13 19:37:22
【问题描述】:

感谢 LH Buddypress Multi Network 插件,我在多网络 WordPress 安装(WordPress 多站点)中有一个 BuddyPress 社交网络。

如何防止人们从其他博客访问个人资料页面?

例如: teacherSite, teacherUser studentSitestudentUser

我已限制非会员访问网站。 teacherUser 只能连接到 teacherSite。 而且他在目录中看不到其他博客的其他用户。

如果studentUser 知道teacherUser 用户名,或者如果他发现或测试...

他可以去:

studentSite.domain.com/members/teacherUser/

即使teacherUser 没有链接到studentSite,他也可以看到teacherUser 的个人资料。

幸运的是,除了姓名和头像之外,没有其他信息(因为其他所有内容都被很好地隔离了)。

但他仍然可以提出连接请求或给他发私信! teacherUser 不会在 teacherSite 上看到任何通知。但他可能会收到一封电子邮件,该电子邮件会将他重定向到studentSite,但无法连接到它。

如何避免这种情况?

【问题讨论】:

    标签: wordpress buddypress multisite


    【解决方案1】:

    我猜 BuddyPress 的用户管理系统与 WordPress 有点相同。

    我们可以将当前用户角色与查询的用户角色进行比较。如果它们不同,我们会阻止并重定向。

    <?php
    
    /**
     * Compare the queried user role with the current user role.
     * If both don't match restrict profile access and redirect to current user profile.
     * 
     * Case exceptions: 
     * - IF the current user IS the queried user. 
     * - IF the current user IS an Admin or Super-Admin.
     */
    add_action( 'wp', function() {
    
        if ( is_author() && get_queried_object() instanceof \WP_User ) {
    
            if ( reset( get_queried_object()->roles ) === reset( wp_get_current_user()->roles ) || get_current_user_id() === get_queried_object_id() || current_user_can( 'manage_options' ) ) { // ... @see https://wordpress.org/support/article/roles-and-capabilities/#capability-vs-role-table
    
                return;
    
            } else {
    
                header( 'Refresh: 2; ' . esc_url( get_author_posts_url( get_current_user_id() ) ) );
    
                $args = array(
                    'back_link' => true,
                );
    
                wp_die( "Error, Restricted access. You're not allowed to view this profile.", 'Error, Restricted access', $args );
    
            };
    
        };
    
    } );
    

    【讨论】:

    • 感谢您的帮助。但它不起作用。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-19
    • 1970-01-01
    • 2010-12-08
    • 2011-05-09
    • 2021-05-28
    • 1970-01-01
    相关资源
    最近更新 更多