# Wordpress SSO - Restrict Content / user levels / groups

**URL:** <https://meta.discourse.org/t/wordpress-sso-restrict-content-user-levels-groups/57776>\
**Category:** WordPress\
**Created:** [2월 22, 2017, 10:53오전 UTC](https://meta.discourse.org/t/wordpress-sso-restrict-content-user-levels-groups/57776 "2017-02-22T10:53:56Z")\
**Posts on this page:** 1\
**Showing post:** 6

<div class="post-metadata">

**Author:** ![deere](https://avatars.discourse-cdn.com/v4/letter/d/9fc29f/32.png) [@deere](https://meta.discourse.org/u/deere)\
**Post date:** [7월 23, 2020, 10:57오전 UTC](https://meta.discourse.org/t/wordpress-sso-restrict-content-user-levels-groups/57776/6 "2020-07-23T10:57:11Z")

</div>

안녕하세요, 이 오래된 게시물을 다시 살려보는 이유는 제 질문이 _Restrict Content Pro_에 해당하기 때문에 원 게시글과 유사하기 때문입니다. 기본적으로 멤버십 시스템이 Restrict Content Pro인 사이트의 작업을 돕고 있는데, 유료 RCP 멤버십에 대해 Discourse 그룹 동기화를 통합하려고 하고 있습니다. 기본적으로 멤버십이 있는 모든 사용자는 Discourse 포럼의 `Members` 그룹과 동기화되어야 합니다.

Simon의 _Managing Discourse group membership with [WP Discourse](https://github.com/discourse/wp-discourse) SSO_ 예제와 비슷한 것을 설정하고 실행하는 데 많은 시간을 보냈습니다. SSO는 잘 작동하지만, 멤버십은 여전히 _동기화_(멤버십 활성화 시 그룹에 멤버 추가 또는 멤버십 만료 시 그룹에서 멤버 제거)되지 않습니다.

이번 게시물에서는 단순히 새 멤버를 Discourse 그룹에 추가하는 것만 작동하도록 하려고 합니다. 해당 사이트의 Discourse 포럼에는 `Members`라는 단 하나의 Discourse 그룹만 있습니다. (그룹 제거는 _Restrict Content Pro_ 훅이 동일하기(`active` 접미사를 `expired`로 교체하는 것만) 때문에 충분히 쉬울 것입니다.) Restrict Content Pro는 멤버십 상태가 변경될 때마다 트리거되는 [rcp\_transition\_membership\_status\_active](https://docs.restrictcontentpro.com/article/2130-rcp-transition-membership-status) 액션 훅을 목록에 올리고 있습니다. 이 훅에는 `$old_status`와 `$membership_id` 매개변수가 있습니다. [rcp\_get\_membership()](https://docs.restrictcontentpro.com/article/2080-rcp-get-membership)을 실행하면 `RCP_Membership` 객체(Wordpress $user\_id 참조를 포함하는 등)가 반환됩니다.

제가 생각해 낸 가장 단순화된 버전은 다음과 같습니다:

```php

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' );
}

```

이 액션이 올바르게 실행되지 않도록 막는 명백한 실수를 보신다면 도움을 주시면 정말 감사하겠습니다. 감사합니다!

---

_[View the full topic](https://meta.discourse.org/t/wordpress-sso-restrict-content-user-levels-groups/57776)._
