# Wp-discourse hook to hijack login

**URL:** https://meta.discourse.org/t/wp-discourse-hook-to-hijack-login/240792
**Category:** Development
**Tags:** wordpress
**Created:** [October 3, 2022, 7:55pm UTC](https://meta.discourse.org/t/wp-discourse-hook-to-hijack-login/240792 "2022-10-03T19:55:23Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [October 3, 2022, 7:55pm UTC](https://meta.discourse.org/t/wp-discourse-hook-to-hijack-login/240792/1 "2022-10-03T19:55:23Z")

</div>

I have a client that’s using s2member and wants users who are not at a specific membership level to be redirected to an info page rather than being logged in to Discourse. (Don’t want to have them log in as a member of a cannot-read-a-thing group, they want them not to be logged in at all.)

Looks like the s2member stuff I need is here: [Package s2Member\API\_Functions ( Functions ) | s2Member Codex](https://www.s2member.com/codex/stable/s2member/api_functions/package-functions/)

I’m sure that there is a hook in wp-discourse that I can call that does this, but I don’t know where to look to figure out what it is.

Presumably I can find the s2member docs to check whether they are paying, but I’d accept hints on that too!

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [October 18, 2022, 4:28pm UTC](https://meta.discourse.org/t/wp-discourse-hook-to-hijack-login/240792/2 "2022-10-18T16:28:46Z")

</div>

Found it.

```plaintext
add_action( 'wpdc_sso_provider_before_sso_redirect', 'wpdc_custom_check_user_membership', 10, 2 );
function wpdc_custom_check_user_membership( $user_id, $user ) {
    $s2member_access_level = get_user_field('s2member_access_level'); # An s2Member Membership Access Level number.
    if ( $s2member_access_level < 1 ) {
   wp_safe_redirect( 'https://myfishingcapecod.com/members-only-content/' );

   exit;

    }
}

```

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [November 17, 2022, 4:29pm UTC](https://meta.discourse.org/t/wp-discourse-hook-to-hijack-login/240792/3 "2022-11-17T16:29:40Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
