Alert: This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only in other core functions. It is listed here for completeness.

LLMS_Generator::get_author_id( array $raw )

Accepts raw author data and locates an existing author by email or id or creates one


Description Description


Parameters Parameters

$raw

(array) (Required) author data if id and email are provided will use id only if it matches the email for user matching that id in the database if no id found, attempts to locate by email if no author found and email provided, creates new user using email falls back to current user id first_name, last_name, and description can be optionally provided when provided will be used only when creating a new user


Top ↑

Return Return

(int|void) WP User ID or void when error encountered


Top ↑

Source Source

File: includes/class.llms.generator.php

	private function get_author_id( $raw ) {

		$author_id = 0;

		// if raw is missing an ID and Email, use current user id
		if ( ! isset( $raw['id'] ) && ! isset( $raw['email'] ) ) {
			$author_id = get_current_user_id();
		} else {

			// if id is set, check if the id matches a user in the DB
			if ( isset( $raw['id'] ) && is_numeric( $raw['id'] ) ) {

				$user = get_user_by( 'ID', $raw['id'] );

				// user exists
				if ( $user ) {

					// we have a raw email
					if ( isset( $raw['email'] ) ) {

						// raw email matches found user's email
						if ( $user->user_email == $raw['email'] ) {
							$author_id = $user->ID;
						}
					} // End if().
					else {
						$author_id = $user->ID;
					}
				}
			}

			if ( ! $author_id ) {

				if ( isset( $raw['email'] ) ) {

					// see if we have a user that matches by email
					$user = get_user_by( 'email', $raw['email'] );

					// user exists, use this user
					if ( $user ) {
						$author_id = $user->ID;
					}
				}
			}

			// no author id, create a new one using the email
			if ( ! $author_id && isset( $raw['email'] ) ) {

				$data = array(
					'role' => 'administrator',
					'user_email' => $raw['email'],
					'user_login' => LLMS_Person_Handler::generate_username( $raw['email'] ),
					'user_pass' => wp_generate_password(),
				);

				if ( isset( $raw['first_name'] ) && isset( $raw['last_name'] ) ) {
					$data['display_name'] = $raw['first_name'] . ' ' . $raw['last_name'];
					$data['first_name'] = $raw['first_name'];
					$data['last_name'] = $raw['last_name'];
				}

				if ( isset( $raw['description'] ) ) {
					$data['description'] = $raw['description'];
				}

				$author_id = wp_insert_user( apply_filters( 'llms_generator_new_author_data', $data ), $raw );

				// increment stats
				if ( ! is_wp_error( $author_id ) ) {
					$this->increment( 'authors' );
				}
			}
		}// End if().

		if ( is_wp_error( $author_id ) ) {
			return $this->error->add( $author_id->get_error_code(), $author_id->get_error_message() );
		}

		return apply_filters( 'llms_generator_get_author_id', $author_id, $raw );

	}

Top ↑

Changelog Changelog

Changelog
Version Description
3.3.0 Introduced.


Top ↑

User Contributed Notes User Contributed Notes

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