<?php
namespace Koselig\Models;
use Illuminate\Auth\Authenticatable;
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Koselig\Support\Wordpress;
use Watson\Rememberable\Rememberable;
class User extends Model implements AuthenticatableContract
{
use Authenticatable, Rememberable;
public $timestamps = false;
protected $table = DB_PREFIX . 'users';
protected $primaryKey = 'ID';
protected $dates = ['user_registered'];
protected $rememberFor;
public function __construct(array $attributes = [])
{
parent::__construct($attributes);
if (Wordpress::multisite() && (Wordpress::getSiteId() !== 0 && Wordpress::getSiteId() !== 1)) {
$this->setTable(DB_PREFIX . Wordpress::getSiteId() . '_users');
}
if (config('wordpress.caching')) {
$this->rememberFor = config('wordpress.caching');
} else {
unset($this->rememberFor);
}
}
public function posts()
{
return $this->hasMany(Post::class, 'post_author');
}
public function getAuthPassword()
{
return $this->user_pass;
}
public function link()
{
return get_author_posts_url($this->ID, $this->display_name);
}
public function comments()
{
return $this->hasMany(Comment::class);
}
}