dozent_get_avatar( null $user_id = null, string $size = 'thumbnail' )

Generate custom avatar for dozent resources


Parameters

$user_id

(null) (Optional)

Default value: null

$size

(string) (Optional)

Default value: 'thumbnail'


Return

(string|null)


Source

File: includes/user-functions.php

	function dozent_get_avatar( $user_id = null, $size = 'thumbnail' ) {
		global $wpdb;

		if ( ! $user_id ) {
			return null;
		}

		$user = dozent_query_user( $user_id );

		if ( ! $user ){
			return '';
		}

		if ( $user->dozent_profile_photo ) {
			return '<img src="' . wp_get_attachment_image_url( $user->dozent_profile_photo, $size )
			       . '" class="dozent-image-avatar" alt="" /> ';
		}

		$name = $user->display_name;
		$arr  = explode( ' ', trim( $name ) );

		if ( count( $arr ) > 1 ) {
			$first_char  = substr( $arr[0], 0, 1 );
			$second_char = substr( $arr[1], 0, 1 );
		} else {
			$first_char  = substr( $arr[0], 0, 1 );
			$second_char = '';
		}

		$initial_avatar = strtoupper( $first_char . $second_char );

		$bg_color = '#00' . substr( md5( $initial_avatar ), 0, 4 );
		$initial_avatar
		          = "<span class='dozent-text-avatar' style='background-color: {$bg_color}; color: #fff8e5'>{$initial_avatar}</span>";

		return $initial_avatar;
	}


Changelog

Changelog
Version Description
DozentLMS 1.0.0 Introduced.