The discussion revolves around preventing certain WordPress users from logging into Discourse using the WP-Discourse plugin. lkramer wants to restrict users with “Guest Access” membership from accessing Discourse.
simon provides a solution using the wpdc_sso_provider_before_sso_redirect action hook to bypass SSO for specific users. This involves adding a function to check the user’s membership level and redirecting them to a different page if they don’t meet the requirement.
However, lkramer notes that this solution doesn’t prevent the user from being automatically created on Discourse. simon acknowledges this limitation and updates the plugin to add a wpdc_bypass_sync_sso filter hook to prevent users from being created on Discourse.
lkramer confirms that the updated solution works. Ryan_Collins1 asks additional questions about implementing the solution, and simon provides guidance on adding the code to the theme’s functions.php file, checking the user’s membership level, and redirecting users to a different page.
The solution involves using the following code:
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;
}
}
add_filter( 'wpdc_bypass_sync_sso', 'wpdc_custom_bypass_sync_sso', 10, 3 );
function wpdc_custom_bypass_sync_sso( $bypass_sync, $user_id, $user ) {
if ( /* Some condition that returns true if the user doesn't meet the membership requirement */ ) {
$bypass_sync = true;
}
return $bypass_sync;
}
By implementing this solution, users can prevent specific WordPress users from logging into Discourse and being automatically created on the platform.