Generator::__construct( integer|string $user )
Description #
Initialize the class.
Parameters #
- $userinteger | string (Required) User ID or name if non-loggedin user.
Source #
File: addons/avatar/class-generator.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(); }
Expand full source code Collapse full source code View on GitHub: addons/avatar/class-generator.php:103
Add your comment