LLMS_Abstract_Generator_Posts::get_author_id( array $raw )

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


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) WP_User ID


Top ↑

Source Source

File: includes/abstracts/llms-abstract-generator-posts.php

			return llms_current_time( 'mysql' );
		}

		return date( 'Y-m-d H:i:s', strtotime( $raw_date ) );

	}

	/**
	 * Accepts raw author data and locates an existing author by email or id or creates one
	 *
	 * @since 3.3.0
	 * @since 4.3.3 Use strict string comparator.
	 * @since 4.7.0 Moved from `LLMS_Generator` and made `protected` instead of `private`.
	 *
	 * @param array $raw 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.
	 * @return int WP_User ID
	 *
	 * @throws Exception When an error is encountered creating a new user.
	 */
	protected 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;
						}
					} 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;
					}


Top ↑

Changelog Changelog

Changelog
Version Description
4.7.0 Moved from LLMS_Generator and made protected instead of private.
4.3.3 Use strict string comparator.
3.3.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

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