The discussion is about integrating WordPress Single Sign-On (SSO) with Restrict Content Pro to manage user levels and groups in Discourse.
tomobrien wants to know how to set up levels during signup, which would carry over to Discourse, while simon is working on a plugin to achieve this functionality.
Later, deere joins the discussion, looking for help with integrating Restrict Content Pro with Discourse to sync paid memberships to a specific group. They share their code, which simon helps debug by suggesting the use of a debug.log file.
After debugging, deere discovers that the issue was with the code wrapped around the action and resolves it by removing the class_exists check. The plugin now works fine for adding and removing members from groups.
simon mentions that an upcoming plugin update will include an option for dealing with comments in private categories.
I have WP discourse working for SSO and Restrict Content Pro for subscription, signup, but I am wondering how to set up levels during signup … That carry over to discourse?
Are you committed to using Restricted Content Pro? There are quite a few different WordPress membership plugins. My plan is to make a general wp-discourse-groups plugin that will work for most of them, but at the moment I’m making a plugin specifically for the WishList Member plugin. When it’s finished, I think it will do everything that you are looking for.
I’ve written code for some WordPress subscription manager that used API calls to manage groups on WordPress. It shouldn’t be hard to set up WordPress groups that whatever group manager you uses could connect to.
안녕하세요, 이 오래된 게시물을 다시 살려보는 이유는 제 질문이 Restrict Content Pro에 해당하기 때문에 원 게시글과 유사하기 때문입니다. 기본적으로 멤버십 시스템이 Restrict Content Pro인 사이트의 작업을 돕고 있는데, 유료 RCP 멤버십에 대해 Discourse 그룹 동기화를 통합하려고 하고 있습니다. 기본적으로 멤버십이 있는 모든 사용자는 Discourse 포럼의 Members 그룹과 동기화되어야 합니다.
Simon의 Managing Discourse group membership with WP Discourse SSO 예제와 비슷한 것을 설정하고 실행하는 데 많은 시간을 보냈습니다. SSO는 잘 작동하지만, 멤버십은 여전히 동기화(멤버십 활성화 시 그룹에 멤버 추가 또는 멤버십 만료 시 그룹에서 멤버 제거)되지 않습니다.
이번 게시물에서는 단순히 새 멤버를 Discourse 그룹에 추가하는 것만 작동하도록 하려고 합니다. 해당 사이트의 Discourse 포럼에는 Members라는 단 하나의 Discourse 그룹만 있습니다. (그룹 제거는 Restrict Content Pro 훅이 동일하기(active 접미사를 expired로 교체하는 것만) 때문에 충분히 쉬울 것입니다.) Restrict Content Pro는 멤버십 상태가 변경될 때마다 트리거되는 rcp_transition_membership_status_active 액션 훅을 목록에 올리고 있습니다. 이 훅에는 $old_status와 $membership_id 매개변수가 있습니다. rcp_get_membership()을 실행하면 RCP_Membership 객체(Wordpress $user_id 참조를 포함하는 등)가 반환됩니다.
제가 생각해 낸 가장 단순화된 버전은 다음과 같습니다:
use WPDiscourse\Utilities\Utilities as DiscourseUtilities;
// Adds a user to the 'members' Discourse group.
function rcpdc_add_member_to_group( $membership_id ) {
$membership = rcp_get_membership( $membership_id );
$user_id = $membership->get_user_id();
DiscourseUtilities::add_user_to_discourse_group( $user_id, 'Members' );
}
// Make sure to check that the Discourse class exists.
if ( class_exists( '\WPDiscourse\Discourse\Discourse' ) ) {
// rcp action suffixed with {active} runs whenever a new membership is added
add_action( 'rcp_transition_membership_status_active', 'rcpdc_add_member_to_group' );
}
이 액션이 올바르게 실행되지 않도록 막는 명백한 실수를 보신다면 도움을 주시면 정말 감사하겠습니다. 감사합니다!
오! Restrict Content Pro 쪽에서 제가 실수를 했네요, 죄송합니다. 제가 사용하고 있는 액션 훅은 두 개의 인수를 요구하는데-
use WPDiscourse\Utilities\Utilities as DiscourseUtilities;
// Adds a user to the 'members' Discourse group.
function rcpdc_add_member_to_group( $old_status, $membership_id ) {
$membership = rcp_get_membership( $membership_id );
$customer = $membership->get_customer();
$user_id = $customer->get_user_id();
DiscourseUtilities::add_user_to_discourse_group( $user_id, 'Members' );
}
// Make sure to check that the Discourse class exists. If not, and you deactivate wp-discourse, this will crash your site.
if ( class_exists( '\WPDiscourse\Discourse\Discourse' ) ) {
add_action( 'rcp_transition_membership_status_active', 'rcpdc_add_member_to_group', 10, 2 );
}
위의 변경 사항 덕분에 add_action은 이제 정상 작동하는 것 같지만, 여전히 add_user_to_discourse_group 함수로는 원하는 결과를 얻지 못하고 있습니다.
새로 활성화된 멤버십이 여전히 Members 그룹에 성공적으로 추가되지 않고 있으니, 혹시 조언을 해줄 수 있는 분이 있다면 정말 감사하겠습니다. 감사합니다.
가능하다면 WordPress 서버에 debug.log 파일을 생성한 후, rcpdc_add_member_to_group 함수에서 해당 파일로 로그를 기록해 보세요. 이를 통해 함수가 실제로 호출되고 있는지, 그리고 생성하는 변수들에 올바른 값이 할당되고 있는지 확인할 수 있습니다.
시몬, 감사합니다! 정말 잘 작동했습니다. 코드를 성공적으로 실행할 수 있었어요. 알고 보니 액션을 감싸고 있던 코드가 add_action가 함수를 실행하는 것을 방해하고 있었습니다. 아래 코드를 제거하고 add_action만 포함시켰더니 플러그인이 정상적으로 작동했습니다.
if ( class_exists( '\WPDiscourse\Discourse\Discourse' ) ) {
이 체크에 대해 크게 걱정하지는 않습니다. 이 사이트는 제가 유일하게 관리하고 있기 때문입니다. 그래서 이제 그룹에 멤버를 추가하고 제거하는 동기화가 완벽하게 작동합니다.