• Hi,

    I am developing intranet site on wordpress. The company uses a few domains and some users have 2-3 login on different domains.
    I set up active directory integration which works well, but of’course I have a few users for one person. I am going to set up one main account for each person that will be used for intranet.
    So, if someone log in using one of their domain credentials it will automatically switch to the main account.

    The username for domain is: firstname.lastname@domainname
    I want all people with domain name redirect to their main account which will be: firstname.lastname

    I believe I need to modify wp_signon() function that will change current user using wp_set_current_user()? If someone login as [email protected] it will change the user to user will.smith using his firstname lastname variables?

    I have checked everywhere and couldn’t find similar issue. Appreciate if someone can help with this

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator bcworkz

    (@bcworkz)

    Close, but no. You must not ever modify core functions. They usually have filter or action hooks you can use to modify behavior. In the case of wp_signon(), you could use the action “wp_login” to alter user data. Setting the current user from this action should work, but I think I have a better plan:

    Hook into the “authenticate” filter (with add_filter()) using a large number priority argument to ensure your callback is called last. It’ll either be passed a WP_Error object or a WP_User object. If an error object, just return it, the authentication already failed. If a user object, check to see if it is a “main” user. If so return the same object. Otherwise, get the pertinent data and get the correct “main” WP_User object and return that object. WP will set the auth cookie based on the returned user object regardless of the initial credentials supplied.

    Untested though. Do a quick proof of concept test before spending a lot of time developing such an approach.

    Dion

    (@diondesigns)

    While you shouldn’t modify wp_signon(), the wp_authenticate() function is “pluggable” and can be replaced with your own custom version. The new function must be part of a plugin; the “pluggable” functions (located in wp-includes/pluggable.php) are already loaded by the time themes are loaded.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Switch user once logged in’ is closed to new replies.