首页 > 解决方案 > BuddyPress 应用程序无法与 Memberpress 一起使用

问题描述

我们正在使用 BuddyBoss Platform Pro + Theme。最近我们还投资了 BuddBoss App(今年早些时候发布)。

我们一直以来的意图是创建一个会员网站并让我们的订阅者为访问内容付费。BuddyBoss 在其网站上广泛强调了他们与 Memberpress 的集成,具有支持它的集成功能,有关如何设置它的视频教程等。Memberpress 与 BuddyBoss Platform Pro 和 Theme 配合得很好。

但是,我们无法让它保护 BuddyBoss 应用程序(IOS 和 Android)中的内容。我向 BuddyBoss 开了一张票,一周后没有任何有意义的回应 - 他们提供了以下内容:

根据与开发团队的检查,这里是更新:

对于 MemberPress,它不保护 REST API 中的博客文章,并且 > 应用程序正在使用 REST API 以本机方式显示博客文章。因此,如果 > MemberPress 保护博客 REST 端点中的内容,那么博客文章也不会显示在 App 中。

问候,
BuddyBoss 客户支持

我们在 Memberpress 中有一条通用规则来保护所有 Wordpress 帖子。从这个回复来看,BuddyBoss 似乎并不认为他们的应用程序的用户会想要保护内容,即使该功能在他们的平台和主题价值道具上得到了大力推广。

有没有其他人遇到这个问题,有没有人有解决这个问题的建议?我们已经有成千上万的应用程序用户,他们可以免费访问我们的内容,颠覆我们的订阅业务模式。

标签: wordpressbuddypressmemberpress

解决方案


因此,只是为 BuddyPress 的答案提供一些背景信息。简而言之,Memberpress 所做的是限制前端访问,但仍然可以执行任何 REST API 请求,因此任何有一点知识的人都可以访问您的受限内容。

我对这些服务(BuddyPress)中的任何一个都不熟悉,因此以下答案通常是关于 Wordpress REST API 的。

is_user_logged_in您可以通过向过滤器添加一个检查来要求对所有 REST API 请求进行身份验证,该检查rest_authentication_errors将阻止任何外部请求,为登录用户锁定您的内容。这可以很容易地适应特定角色,例如:使用付费会员时。

以下示例将阻止非登录用户和非管理员的任何 REST API 请求。

<?php

if ( ! defined( 'ABSPATH' ) ) {

    exit; 

};

/**
 * Require authentication for all requests. Prevent blank or empty bots request.
 * 
 * Filters REST API authentication errors. 
 * 
 * @link https://developer.wordpress.org/rest-api/frequently-asked-questions/#require-authentication-for-all-requests
 */
add_filter( 'rest_authentication_errors', function( $result ) {

    // If a previous authentication check was applied,
    // pass that result along without modification.
    if ( true === $result || is_wp_error( $result ) ) {

        return $result;

    };

    // No authentication has been performed yet.
    // Return an error if user is not logged in or isn't a Admin, Editor or Author
    if ( ! is_user_logged_in() || ! current_user_can( 'publish_posts' ) ) {

        header( 'Refresh: 1; ' . esc_url( home_url() ) );

        return new WP_Error(
            'rest_not_logged_in',
            __( 'You are not currently logged in OR are not allowed.' ),
            array( 'status' => 401 )
        );

    };

    // Our custom authentication check should have no effect
    // on logged-in requests
    return $result;
    
} );

推荐阅读