• Resolved kikkervis

    (@kikkervis)


    I’ve been using the WP SAML Auth plugin on several of our university WordPress sites and it’s working great. The only thing that is missing for us is that when user data changes at the IdP the change isn’t updated in WordPress.

    Would it be possible to update the user data whenever a user logs in?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Daniel Bachhuber

    (@danielbachhuber)

    Great suggestion!

    You should be able to update the user data when a user logs in with the following code snippet (untested):

    
    /**
     * Update user attributes after a user has logged in via SAML.
     */
    add_action( 'wp_saml_auth_existing_user_authenticated', function( $existing_user, $attributes ) {
    	$user_args = array(
    		'ID' => $existing_user->ID,
    	);
    	foreach ( array( 'display_name', 'first_name', 'last_name' ) as $type ) {
    		$attribute          = \WP_SAML_Auth::get_option( "{$type}_attribute" );
    		$user_args[ $type ] = ! empty( $attributes[ $attribute ][0] ) ? $attributes[ $attribute ][0] : '';
    	}
    	wp_update_user( $user_args );
    }, 10, 2 );
    

    Let me know how that works for you!

    Thread Starter kikkervis

    (@kikkervis)

    I just had a chance to test it and it works great. Thanks!

    Plugin Author Daniel Bachhuber

    (@danielbachhuber)

    Great! I’ve updated the README to include this code snippet: https://github.com/pantheon-systems/wp-saml-auth/pull/130

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Update user data at login’ is closed to new replies.