Multisite support in models
Diff
src/Models/Meta.php | 16 ++++++++++++++++
src/Models/Option.php | 17 +++++++++++++++++
src/Models/Post.php | 17 +++++++++++++++++
src/Models/User.php | 1 +
4 files changed, 51 insertions(+)
@@ -26,6 +26,22 @@ class Meta extends Model
public static $cache = [];
/**
* Create a new Eloquent model instance.
*
* @param array $attributes
* @return void
*/
public function __construct(array $attributes = [])
{
parent::__construct($attributes);
// Set the current table to the site's own table if we're in a multisite
if (Wordpress::multisite() && (Wordpress::getSiteId() !== 0 && Wordpress::getSiteId() !== 1)) {
$this->setTable(DB_PREFIX . Wordpress::getSiteId() . '_postmeta');
}
}
/**
* Get metadata for a page (or the current page).
*
* <code>Meta::get('my_meta_key');</code>
@@ -2,6 +2,7 @@
namespace Koselig\Models;
use Illuminate\Database\Eloquent\Model;
use Koselig\Support\Wordpress;
/**
* Table containing all Wordpress options.
@@ -15,6 +16,22 @@ class Option extends Model
public $timestamps = false;
/**
* Create a new Eloquent model instance.
*
* @param array $attributes
* @return void
*/
public function __construct(array $attributes = [])
{
parent::__construct($attributes);
// Set the current table to the site's own table if we're in a multisite
if (Wordpress::multisite() && (Wordpress::getSiteId() !== 0 && Wordpress::getSiteId() !== 1)) {
$this->setTable(DB_PREFIX . Wordpress::getSiteId() . '_options');
}
}
/**
* Get an option by its name.
*
* @param $name
@@ -7,6 +7,7 @@ use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Koselig\Exceptions\UnsatisfiedDependencyException;
use Koselig\Support\Action;
use Koselig\Support\Wordpress;
use WP_Post;
/**
@@ -22,6 +23,22 @@ class Post extends Model
public $timestamps = false;
/**
* Create a new Eloquent model instance.
*
* @param array $attributes
* @return void
*/
public function __construct(array $attributes = [])
{
parent::__construct($attributes);
// Set the current table to the site's own table if we're in a multisite
if (Wordpress::multisite() && (Wordpress::getSiteId() !== 0 && Wordpress::getSiteId() !== 1)) {
$this->setTable(DB_PREFIX . Wordpress::getSiteId() . '_posts');
}
}
/**
* The "booting" method of the model.
*
* @return void
@@ -5,6 +5,7 @@ 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;
/**
* Table containing all the users within the CMS.