AnsPress_Avatar::__construct( integer|string $user )

Description #

Initialize the class.

Parameters #

  • $user
    integer | string (Required) User ID or name if anonymous.

Source #

File: addons/free/avatar.php

	public function __construct( $user ) {

		if ( is_object( $user ) && ! empty( $user->user_id ) ) {
			$this->user_id = (int) $user->user_id;
			$user = get_userdata( $this->user_id );
			$this->name = esc_attr( $user->display_name );
		} elseif ( is_object( $user ) && $user instanceof WP_user ) {
			$this->name = esc_attr( $user->display_name );
			$this->user_id = $user->ID;
		} elseif ( is_object( $user ) && $user instanceof WP_Comment ) {
			$this->name = esc_attr( $user->comment_author );
			$this->user_id = $user->user_id;
		} elseif ( is_numeric( $user ) && ! empty( $user ) ) {
			$user = get_user_by( 'id', $user );
			$this->name = esc_attr( $user->display_name );
			$this->user_id = $user->ID;
		} else {
			$this->name = empty( $user ) ? 'anonymous' : esc_attr( $user );
			$this->user_id = empty( $user ) ? 'anonymous' : $this->name;
		}

		$this->colors();
		$this->filename();
	}

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Add your comment