저는 discourse와 pmpro 두 가지 플러그인을 모두 사용했으며, pmpro의 zappier 애드온도 함께 사용하고 있습니다. 현재 사용자의 멤버십 레벨을 discourse로 업데이트하려고 시도하고 있습니다.
wp-admin에서 특정 사용자의 멤버십 레벨을 변경하면, 제 discourse 사이트의 관리자 사용자 섹션에도 자동으로 업데이트되기를 기대하고 있습니다.
이 작업을 수행하려면 무엇을 해야 할까요? 이에 대한 아이디어를 주실 수 있을까요?
pfaffman
(Jay Pfaffman)
2
functions.php에 액션을 추가해야 합니다.
/* http://hookr.io/actions/pmpro_after_change_membership_level/의 예제를 참조하세요 */
do_action( 'pmpro_after_change_membership_level', $level_id, $user_id, $cancel_level );
function action_pmpro_after_change_membership_level( $level_id, $user_id, $cancel_level ) {
. . . . 멤버십 레벨과 그룹을 가져와 그룹에 추가하는 작업
}
갱신된 사용자의 $level_id, $user_id, $cancel_level 및 그룹 이름을 어떻게 가져올 수 있는지 설명해 주시겠어요?
pfaffman
(Jay Pfaffman)
4
문서로 링크를 걸었습니다. 이 값들이 액션 훅을 통해 전달된다고 생각합니다.
제이님, 답변 감사합니다. 제 환경에서는 작동했지만, 이전 값이 여전히 남아 있습니다. 즉, 새 멤버십 레벨과 이전 멤버십 레벨 값이 모두 존재하는 상태입니다. 멤버십 레벨의 이전 값을 제거하는 방법에 대해 조언을 구합니다.
아래와 같은 코드를 사용하고 있습니다.
DiscourseUtilities::remove_user_from_discourse_group( $user_id, $group_name );
제 제거 함수는 다음과 같습니다.
function dcpmp_remove_member_from_group( $level_id, $user_id, $cancel_level ) {
if ( ! empty( $cancel_level ) ) {
$group_name = dcpmp_get_level_for_id( $cancel_level );
if ( is_wp_error( $group_name ) ) {
return null;
}
// Removes the user.
$result = DiscourseUtilities::remove_user_from_discourse_group( $user_id, $group_name );
if ( ! empty( $result->success ) ) {
// Remove the membership level metadata key.
delete_user_meta( $user_id, "dcpmp_group_{$group_name}" );
}
return $result;
}
return null;
}
pfaffman
(Jay Pfaffman)
6
wp-discourse에 그룹에서 삭제하는 기능이 있는 것 같은데, 그걸 호출할 수 있을 것 같습니다.
이것은 Simon Cossar팀이 사용하는 것과 동일한 함수입니다. 이 링크를 참고해 주세요.
Manage group membership in Discourse with WP Discourse SSO
저도 동일한 함수를 사용했는데 도움이 필요합니다. 코드도 함께 게시했으며 위 메시지를 참고해 주세요.
다음은 제 멤버십 레벨 업데이트 코드입니다.
function action_pmpro_after_change_membership_level( $level_id, $user_id, $cancel_level ) {
$group_name = dcpmp_get_level_for_id( $level_id );
if ( is_wp_error( $group_name ) ) {
return null;
}
$groupname = DiscourseUtilities::get_discourse_user( $user_id, false );
// 사용자를 제거합니다.
$result = DiscourseUtilities::remove_user_from_discourse_group( $user_id, $groupname );
if ( ! empty( $result->success ) ) {
// 멤버십 레벨 메타데이터 키를 삭제합니다.
delete_user_meta( $user_id, "dcpmp_group_{$groupname}" );
}
$result1 = DiscourseUtilities::add_user_to_discourse_group( $user_id, $group_name );
if ( ! empty( $result1->success ) ) {
// 사용자가 그룹에 추가된 경우, 나중에 사용할 수 있는 메타데이터 키/값 쌍을 추가합니다.
add_user_meta( $user_id, "dcpmp_group_{$group_name}", 1, true );
}
return $result;
return $result1;
}
add_action( 'pmpro_after_change_membership_level', 'action_pmpro_after_change_membership_level', 10, 3 );
simon
8
코드에서 이 줄이 무엇을 하는지 확실하지 않습니다:
$groupname = DiscourseUtilities::get_discourse_user( $user_id, false );
이 줄은 $groupname을 Discourse 사용자 객체로 설정합니다. 이 줄을 제거하고, 코드 첫 번째 줄에서 설정하는 $group_name 변수를 사용해야 한다고 생각합니다.
전에 사용해 봤는데 작동하지 않았습니다.
해결 방법을 알려주세요.
해결책을 원하시면 비용을 지불하셔야 합니다. https://discourse.org/buy에서 호스팅 플랜에 가입해 주세요.