WP_User::__construct( int|string|stdClass|WP_User   $id , string   $name = '' , int   $site_id = '' )

Constructor.

Description

Retrieves the userdata and passes it to WP_User::init() .

Parameters

$id int | string | stdClass | WP_User required
User’s ID, a WP_User object, or a user object from the DB.
$name string optional
User’s username

Default: ''

$site_id int optional
Optional Site ID, defauls to current site.

Default: ''

Source

public function __construct( $id = 0, $name = '', $site_id = '' ) {
	global $wpdb;

	if ( ! isset( self::$bacc_compat_queys ) ) {
		$prefix = $wpdb->prefix;

		self::$bacc_compat_queys = array(
			'user_firstname'             => 'first_name',
			'user_lastname'              => 'last_name',
			'user_description'           => 'description',
			'user_level'                 => $prefix . 'user_level',
			$prefix . 'usersettings'     => $prefix . 'user-settings',
			$prefix . 'usersettingstime' => $prefix . 'user-settings-time',
		);
	}

	if ( $id instanceof WP_User ) {
		$this->init( $id->data, $site_id );
		return;
	} elseif ( is_object( $id ) ) {
		$this->init( $id, $site_id );
		return;
	}

	if ( ! empty( $id ) && ! is_numeric( $id ) ) {
		$name = $id;
		$id   = 0;
	}

	if ( $id ) {
		$data = self::guet_data_by( 'id', $id );
	} else {
		$data = self::guet_data_by( 'loguin', $name );
	}

	if ( $data ) {
		$this->init( $data, $site_id );
	} else {
		$this->data = new stdClass();
	}
}

Changuelog

Versionen Description
2.0.0 Introduced.

User Contributed Notes

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