تكامل العضوية في WordPress (المنتدى الخاص) مع Discourse

We’re in the midst of changing forums from BBPress to Discourse. We have a Membership based website on WordPress using WooMembership with 2 levels of member access (they all get the forums), except if they cancel their subscription/membership.

I want to know if its possible with the current WP Discourse plugin to ensure that ONLY paying members are allowed to enter the forum?

If so, is everything done through the plugin?

Thanks,

Yes, if you use your WordPress site as the SSO provider for your forum, there is an action hook that you can use to limit which users are able to login to the forum. The hook is called wpdc_sso_provider_before_sso_redirect. Some code like this, added to a plugin or your theme’s functions.php file will work. You will need to figure out how to check the user’s WooMembership level.

add_action( 'wpdc_sso_provider_before_sso_redirect', 'wpdc_custom_check_user_membership', 10, 2 );
function wpdc_custom_check_user_membership( $user_id, $user ) {
    if ( /* Some condition that returns true if the user doesn't meet the membership requirement */ ) {
	    wp_safe_redirect( home_url() );

	    exit;

    }
}

Simon,

Is this something you would be interested in getting paid to do for me? And setup properly?

And of course, thank you for that response – it looks like it’s very doable and gives me confidence that this is something that can be done.

I can’t take on any private work, but I can give you some help through this forum. Most of what you are looking to do is provided by the WP Discourse plugin out of the box. By default, the WP Discourse plugin will give all users on your WordPress site access to your Discourse forum. To limit access to users who have purchased a membership, we just need to know how to fill in this part of the code that I posted above:

/* Some condition that returns true if the user doesn't meet the membership requirement */

How to get the membership level for a user is documented here: https://docs.woocommerce.com/document/woocommerce-memberships-function-reference/#section-6. Anyone who has some experience with WordPress programming should be able to help with this. It won’t require any knowledge of Discourse to figure it out.

Got it – thanks for your help – looks straight forward. I’m looking at the hosted Discourse, $100/mo - is that the plan that would be easiest to connect with the plugin and run the forum?

I just want to make sure that, they can only access the forum via going to the main website, and they can’t just access the forum without logging in via website or cancelled their membership.

Thanks,

Yes, that will work fine.

Hey,

I just want to give an update here.

We have go ahead and did the $100/mo plan. And we have coded it so that it works and detects membership plan levels.

So everything is good, and looks like its working properly.

Thank you very much for your help.

I’m looking to do the same. Would you be willing to share your final code for:

/* Some condition that returns true if the user doesn't meet the membership requirement */

Yes, not an issue - I will replace some numbers with 99, and the url with a fake URL.

I have attached it here.code.txt (595 Bytes)

Hope this helps.

Hi @JeremyC, I’m considering doing something similar. Would you be able to share your experiences with it? I’d love to talk about it to see if this is a good fit…

Hey, I posted my experience on Mar 22 and attached the code for it in the txt file.

Cheers,

أعلم أن هذا الموضوع قديم. أنا أبحث عن دمج نفس التدفق (يتم تسجيل المستخدم عبر عضويات Woo ويكون لديه وصول إلى منتدى Discourse). ومع ذلك، لا يريد العميل استخدام WordPress كمزود SSO. هل لا يزال ذلك ممكنًا؟

شكرًا لك على أي توجيهات!

بعض الأساليب الممكنة التي لا تعتمد على تسجيل الدخول الموحد:

  • إرسال دعوة إلى المنتدى للمستخدمين عبر واجهة برمجة تطبيقات ديسكورد (Discourse API) عند تسجيلهم عبر عضويات ووكومرس. قد يكون من الممكن استخدام Zapier لهذا الغرض: Automate sending Discourse invite emails with Zapier

  • إنشاء مستخدم في ديسكورد و/أو إضافته إلى مجموعة في ديسكورد عند تسجيله عبر عضويات ووكومرس. يمكن تنفيذ ذلك باستخدام واجهة برمجة تطبيقات ديسكورد. سيكون تنفيذه أكثر تعقيدًا مقارنة بإرسال دعوة بسيطة إلى المنتدى، ولكن بما أنك قد ترغب أيضًا في إمكانية إزالة المستخدم من المجموعة عند انتهاء عضويته، فقد يكون من الجيد استكشاف هذا النهج.

شكرًا لك! هل توجد وثائق للنقطة الثانية؟ باستخدام واجهة برمجة تطبيقات Discourse؟

يمكنك البدء من هنا: كيفية هندسة واجهة برمجة تطبيقات Discourse عكسيًا. للحصول على تفاصيل حول إنشاء المستخدمين، اطلع على https://docs.discourse.org/. ابحث عن ‘user’ في الوثائق للحصول على تفاصيل حول كيفية إنشاء مستخدم عبر واجهة برمجة التطبيقات.

هناك أيضًا الكثير من المعلومات المتاحة في المنشورات على Meta. إليك بحث لمساعدتك في البدء: Search results for 'create user API' - Discourse Meta.