LLMS_Person_Handler::login( array $data )

Login a user


Description Description


Parameters Parameters

$data

(array) (Required) array of login data.


Top ↑

Return Return

(WP_Error|int) WP_Error on error or the WP_User ID.


Top ↑

Source Source

File: includes/class.llms.person.handler.php

	public static function login( $data ) {

		do_action( 'lifterlms_before_user_login', $data );

		// validate the fields & allow custom validation to occur.
		$valid = self::validate_fields( apply_filters( 'lifterlms_user_login_data', $data ), 'login' );

		// if errors found, return them.
		if ( is_wp_error( $valid ) ) {
			return apply_filters( 'lifterlms_user_login_errors', $valid, $data, false );
		}

		$creds = array();
		$creds['user_login'] = $data['llms_login'];

		$err = new WP_Error( 'login-error', __( 'Could not find an account with the supplied email address and password combination.', 'lifterlms' ) );

		// get the username from the email address
		if ( llms_parse_bool( get_option( 'lifterlms_registration_generate_username' ) ) && apply_filters( 'lifterlms_get_username_from_email', true ) ) {

			$user = get_user_by( 'email', wp_unslash( $data['llms_login'] ) );

			if ( ! isset( $user->user_login ) ) {
				return apply_filters( 'lifterlms_user_login_errors', $err, $data, false );
			}

			$creds['user_login'] = $user->user_login;

		}

		$creds['user_password'] = $data['llms_password'];
		$creds['remember'] = isset( $data['llms_remember'] );

		$signon = wp_signon( apply_filters( 'lifterlms_login_credentials', $creds ), is_ssl() );

		if ( is_wp_error( $signon ) ) {
			return apply_filters( 'lifterlms_user_login_errors', $err, $data, $signon );
		}

		return $signon->ID;

	}

Top ↑

Changelog Changelog

Changelog
Version Description
3.0.0 Introduced.


Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.





Permalink: