<?php
namespace Koselig\Models;
use Illuminate\Database\Eloquent\Model;
use Koselig\Support\Wordpress;
use Watson\Rememberable\Rememberable;
class Option extends Model
{
use Rememberable;
public $timestamps = false;
protected $primaryKey = 'option_id';
protected $table = DB_PREFIX . 'options';
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() . '_options');
}
if (config('wordpress.caching')) {
$this->rememberFor = config('wordpress.caching');
} else {
unset($this->rememberFor);
}
}
public static function findByName($name)
{
return static::where('option_name', $name)->first();
}
public function getOptionValueAttribute($value)
{
return is_serialized($value) ? unserialize($value) : $value;
}
}