🏡 index : ~doyle/koselig.git

author Jordan Doyle <jordan@doyle.wf> 2016-10-16 23:25:16.0 +01:00:00
committer Jordan Doyle <jordan@doyle.wf> 2016-10-16 23:25:16.0 +01:00:00
commit
d4e4cba2073f99be617321d0636e790d9dbda668 [patch]
tree
5a72b4e9c13d77916f5b8da19e2a2fd699f3fa8f
parent
a1a6bd3f9a05d89fe1e9d21975a664b59ec1e124
download
d4e4cba2073f99be617321d0636e790d9dbda668.tar.gz

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(+)

diff --git a/src/Models/Meta.php b/src/Models/Meta.php
index bea4fe7..644ff8a 100644
--- a/src/Models/Meta.php
+++ a/src/Models/Meta.php
@@ -26,6 +26,22 @@
    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>
diff --git a/src/Models/Option.php b/src/Models/Option.php
index f85e3c8..976759c 100644
--- a/src/Models/Option.php
+++ a/src/Models/Option.php
@@ -1,7 +1,8 @@
<?php
namespace Koselig\Models;

use Illuminate\Database\Eloquent\Model;
use Koselig\Support\Wordpress;

/**
 * Table containing all Wordpress options.
@@ -13,6 +14,22 @@
    protected $primaryKey = 'option_id';
    protected $table = DB_PREFIX . 'options';
    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.
diff --git a/src/Models/Post.php b/src/Models/Post.php
index 41c60ef..c24e1a5 100644
--- a/src/Models/Post.php
+++ a/src/Models/Post.php
@@ -7,6 +7,7 @@
use Illuminate\Database\Eloquent\Relations\HasMany;
use Koselig\Exceptions\UnsatisfiedDependencyException;
use Koselig\Support\Action;
use Koselig\Support\Wordpress;
use WP_Post;

/**
@@ -20,6 +21,22 @@
    protected $primaryKey = 'ID';
    protected $dates = ['post_date', 'post_date_gmt', 'post_modified', 'post_modified_gmt'];
    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.
diff --git a/src/Models/User.php b/src/Models/User.php
index 9974e88..1ff21ae 100644
--- a/src/Models/User.php
+++ a/src/Models/User.php
@@ -5,6 +5,7 @@
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.