🏡 index : ~doyle/koselig.git

author Jordan Doyle <jordan@doyle.wf> 2016-10-22 23:13:58.0 +00:00:00
committer Jordan Doyle <jordan@doyle.wf> 2016-10-22 23:13:58.0 +00:00:00
commit
20eeb7dbf0dc4a655ed798d8a615bf97a763cc16 [patch]
tree
bfd3684712ca5e0973ff0da8f0808b3fbe4ee480
parent
a6cf25e2172c415f171a3e70f1612dcd438f318b
parent
fe23fdb0b035ed402ab5a48fe294ce8f12b77716
download
20eeb7dbf0dc4a655ed798d8a615bf97a763cc16.tar.gz

Merge branch 'master' of https://github.com/koselig/library



Diff

 src/Admin/Page.php                         |   3 +-
 src/Auth/WordpressGuard.php                |   7 +-
 src/Facades/Loop.php                       |   3 +-
 src/Facades/Query.php                      |   1 +-
 src/Facades/WPHash.php                     |   1 +-
 src/Hashing/WordpressHasher.php            |   4 +-
 src/Mail/Mailer.php                        |   2 +-
 src/Models/Comment.php                     |  24 ++---
 src/Models/Meta.php                        |  11 +-
 src/Models/Option.php                      |   5 +-
 src/Models/Post.php                        |  50 ++++++----
 src/Models/Term.php                        |   3 +-
 src/Models/TermTaxonomy.php                |   3 +-
 src/Models/User.php                        |   3 +-
 src/Models/UserMeta.php                    |   4 +-
 src/Providers/ConfigServiceProvider.php    |   2 +-
 src/Providers/QueryServiceProvider.php     |   1 +-
 src/Providers/WordpressServiceProvider.php | 147 +++++++++++++++---------------
 src/Proxy/Query.php                        |  22 ++--
 src/Routing/ArchiveRoute.php               |   2 +-
 src/Routing/AuthorRoute.php                |  34 +++----
 src/Routing/PageRoute.php                  |  48 +++++-----
 src/Routing/Routing.php                    |   7 +-
 src/Routing/SingularRoute.php              |  44 ++++-----
 src/Routing/TemplateRoute.php              |  50 +++++-----
 src/Support/Action.php                     |   1 +-
 src/Support/Wordpress.php                  |   5 +-
 27 files changed, 279 insertions(+), 208 deletions(-)

diff --git a/src/Admin/Page.php b/src/Admin/Page.php
index 28c75f5..0eaf2a8 100644
--- a/src/Admin/Page.php
+++ b/src/Admin/Page.php
@@ -22,6 +22,7 @@ class Page
     * @param mixed $action The function to be called to output the content for this page.
     * @param string $iconUrl The URL to the icon to be used for this menu.
     * @param int $position The position in the menu order this one should appear.
     *
     * @return string The resulting page's hook_suffix.
     */
    public static function addPage($pageTitle, $menuTitle, $capability, $slug, $action, $iconUrl = '', $position = null)
@@ -39,6 +40,7 @@ class Page
     * @param string $capabilities The capability required for this menu to be displayed to the user.
     * @param string $slug The slug name to refer to this menu by (should be unique for this menu).
     * @param mixed $action The function to be called to output the content for this page.
     *
     * @return false|string The resulting page's hook_suffix, or false if the user does not have the capability required
     */
    public static function addSubpage($parent, $pageTitle, $menuTitle, $capabilities, $slug, $action)
@@ -51,6 +53,7 @@ class Page
     * syntax.
     *
     * @param $callback
     *
     * @return Closure
     */
    protected static function wrap($callback)
diff --git a/src/Auth/WordpressGuard.php b/src/Auth/WordpressGuard.php
index bcfd6d5..7849a64 100644
--- a/src/Auth/WordpressGuard.php
+++ b/src/Auth/WordpressGuard.php
@@ -57,6 +57,7 @@ class WordpressGuard implements StatefulGuard
     * Validate a user's credentials.
     *
     * @param  array $credentials
     *
     * @return bool
     */
    public function validate(array $credentials = [])
@@ -74,6 +75,7 @@ class WordpressGuard implements StatefulGuard
     * @param  array $credentials
     * @param  bool $remember
     * @param  bool $login
     *
     * @return bool
     */
    public function attempt(array $credentials = [], $remember = false, $login = true)
@@ -99,6 +101,7 @@ class WordpressGuard implements StatefulGuard
     * Log a user into the application without sessions or cookies.
     *
     * @param  array $credentials
     *
     * @return bool
     */
    public function once(array $credentials = [])
@@ -117,6 +120,7 @@ class WordpressGuard implements StatefulGuard
     *
     * @param  \Illuminate\Contracts\Auth\Authenticatable $user
     * @param  bool $remember
     *
     * @return void
     */
    public function login(Authenticatable $user, $remember = false)
@@ -133,6 +137,7 @@ class WordpressGuard implements StatefulGuard
     *
     * @param  mixed $id
     * @param  bool $remember
     *
     * @return \Illuminate\Contracts\Auth\Authenticatable|bool
     */
    public function loginUsingId($id, $remember = false)
@@ -154,6 +159,7 @@ class WordpressGuard implements StatefulGuard
     * Log the given user ID into the application without sessions or cookies.
     *
     * @param  mixed $id
     *
     * @return bool
     */
    public function onceUsingId($id)
@@ -194,6 +200,7 @@ class WordpressGuard implements StatefulGuard
     * Set the current user.
     *
     * @param  \Illuminate\Contracts\Auth\Authenticatable $user
     *
     * @return $this
     */
    public function setUser(Authenticatable $user)
diff --git a/src/Facades/Loop.php b/src/Facades/Loop.php
index 6475051..e655bf5 100644
--- a/src/Facades/Loop.php
+++ b/src/Facades/Loop.php
@@ -4,10 +4,11 @@ namespace Koselig\Facades;
use Illuminate\Support\Facades\Facade;

/**
 * Facade for {@link Koselig\Models\Post}. Provides access to the current post in "The Loop"
 * Facade for {@link Koselig\Models\Post}. Provides access to the current post in "The Loop".
 *
 * @see \Koselig\Models\Post
 * @mixin \Koselig\Models\Post
 *
 * @author Jordan Doyle <jordan@doyle.wf>
 */
class Loop extends Facade
diff --git a/src/Facades/Query.php b/src/Facades/Query.php
index 9a21b8b..fd6e2eb 100644
--- a/src/Facades/Query.php
+++ b/src/Facades/Query.php
@@ -8,6 +8,7 @@ use Illuminate\Support\Facades\Facade;
 *
 * @see \Koselig\Proxy\Query
 * @mixin \Koselig\Proxy\Query
 *
 * @author Jordan Doyle <jordan@doyle.wf>
 */
class Query extends Facade
diff --git a/src/Facades/WPHash.php b/src/Facades/WPHash.php
index d5f8d04..e306748 100644
--- a/src/Facades/WPHash.php
+++ b/src/Facades/WPHash.php
@@ -8,6 +8,7 @@ use Illuminate\Support\Facades\Facade;
 *
 * @see \Koselig\Hashing\WordpressHasher
 * @mixin \Koselig\Hashing\WordpressHasher
 *
 * @author Jordan Doyle <jordan@doyle.wf>
 */
class WPHash extends Facade
diff --git a/src/Hashing/WordpressHasher.php b/src/Hashing/WordpressHasher.php
index e38d904..3bc1253 100644
--- a/src/Hashing/WordpressHasher.php
+++ b/src/Hashing/WordpressHasher.php
@@ -16,7 +16,9 @@ class WordpressHasher implements HasherContract
     *
     * @param  string $value
     * @param  array $options
     *
     * @throws \RuntimeException
     *
     * @return string
     */
    public function make($value, array $options = [])
@@ -30,6 +32,7 @@ class WordpressHasher implements HasherContract
     * @param  string $value
     * @param  string $hashedValue
     * @param  array $options
     *
     * @return bool
     */
    public function check($value, $hashedValue, array $options = [])
@@ -42,6 +45,7 @@ class WordpressHasher implements HasherContract
     *
     * @param  string $hashedValue
     * @param  array $options
     *
     * @return bool
     */
    public function needsRehash($hashedValue, array $options = [])
diff --git a/src/Mail/Mailer.php b/src/Mail/Mailer.php
index c441057..e3b172c 100644
--- a/src/Mail/Mailer.php
+++ b/src/Mail/Mailer.php
@@ -1,4 +1,5 @@
<?php

use Illuminate\Mail\Message;
use Illuminate\Support\Facades\Mail;
use Koselig\Support\Action;
@@ -12,6 +13,7 @@ if (!function_exists('wp_mail')) {
     * @param string $message Message contents
     * @param string|array $headers Optional. Additional headers.
     * @param string|array $attachments Optional. Files to attach.
     *
     * @return bool Whether the email contents were sent successfully.
     */
    function wp_mail($to, $subject, $message, $headers = '', $attachments = [])
diff --git a/src/Models/Comment.php b/src/Models/Comment.php
index 33c1775..dde3450 100644
--- a/src/Models/Comment.php
+++ b/src/Models/Comment.php
@@ -9,8 +9,8 @@ use Koselig\Support\Wordpress;
/**
 * Table containing all the comments belonging to posts.
 *
 * @property integer $comment_ID ID of this comment
 * @property integer $comment_post_ID ID of the post this comment belongs to
 * @property int $comment_ID ID of this comment
 * @property int $comment_post_ID ID of the post this comment belongs to
 * @property string $comment_author Author of this comment
 * @property string $comment_author_email Author of this comment's email
 * @property string $comment_author_url Author of this comment's URL
@@ -18,29 +18,31 @@ use Koselig\Support\Wordpress;
 * @property Carbon $comment_date Date this comment was posted
 * @property Carbon $comment_date_gmt Date this comment was posted
 * @property string $comment_content Content of this comment
 * @property integer $comment_karma Karma of this comment
 * @property int $comment_karma Karma of this comment
 * @property string $content Content of the comment filtered through "comment_text"
 * @property boolean $comment_approved Whether or not this comment has been approved
 * @property bool $comment_approved Whether or not this comment has been approved
 * @property string $comment_agent
 * @property string $comment_type
 * @property integer $comment_parent comment this comment was in reply to
 * @property integer $user_id user this comment belongs to
 * @property-read Post $post post this comment belongs to
 * @property-read User $user user this comment belongs to
 * @property-read Comment $parent comment this comment is in reply to
 * @property int $comment_parent comment this comment was in reply to
 * @property int $user_id user this comment belongs to
 * @property Post $post post this comment belongs to
 * @property User $user user this comment belongs to
 * @property Comment $parent comment this comment is in reply to
 *
 * @author Jordan Doyle <jordan@doyle.wf>
 */
class Comment extends Model
{
    public $timestamps = false;
    protected $table = DB_PREFIX . 'comments';
    protected $primaryKey = 'comment_ID';
    protected $dates = ['comment_date', 'comment_date_gmt'];
    public $timestamps = false;

    /**
     * Create a new Eloquent model instance.
     *
     * @param  array $attributes
     *
     * @return void
     */
    public function __construct(array $attributes = [])
@@ -85,6 +87,6 @@ class Comment extends Model

    public function parent()
    {
        return $this->belongsTo(Comment::class, 'comment_parent');
        return $this->belongsTo(self::class, 'comment_parent');
    }
}
diff --git a/src/Models/Meta.php b/src/Models/Meta.php
index 644ff8a..36dce4e 100644
--- a/src/Models/Meta.php
+++ b/src/Models/Meta.php
@@ -14,8 +14,6 @@ use Koselig\Support\Wordpress;
 */
class Meta extends Model
{
    protected $primaryKey = 'meta_id';
    protected $table = DB_PREFIX . 'postmeta';
    public $timestamps = false;

    /**
@@ -24,11 +22,14 @@ class Meta extends Model
     * @var array
     */
    public static $cache = [];
    protected $primaryKey = 'meta_id';
    protected $table = DB_PREFIX . 'postmeta';

    /**
     * Create a new Eloquent model instance.
     *
     * @param  array $attributes
     *
     * @return void
     */
    public function __construct(array $attributes = [])
@@ -51,6 +52,7 @@ class Meta extends Model
     * @param int|string|null|Post $page page to get meta for (or name of the meta item to get
     *                                   if you want to get the current page's meta)
     * @param string|null $name
     *
     * @return mixed
     */
    public static function get($page = null, $name = null)
@@ -89,11 +91,14 @@ class Meta extends Model
     * Grab an ACF field from the database.
     *
     * @see Meta::get()
     *
     * @param int|string|null|Post $page page to get meta for (or name of the meta item to get
     *                                   if you want to get the current page's meta)
     * @param string|null $name
     * @param bool $format whether to format this field or not
     *
     * @throws UnsatisfiedDependencyException
     *
     * @return mixed
     */
    public static function acf($page = null, $name = null, $format = true)
@@ -124,7 +129,7 @@ class Meta extends Model
        $field = static::get($page, '_' . $name);

        if (!acf_is_field_key($field)) {
            return null;
            return;
        }

        $field = get_field_object($field, $name, false, false);
diff --git a/src/Models/Option.php b/src/Models/Option.php
index 976759c..d891dd3 100644
--- a/src/Models/Option.php
+++ b/src/Models/Option.php
@@ -11,14 +11,15 @@ use Koselig\Support\Wordpress;
 */
class Option extends Model
{
    public $timestamps = false;
    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 = [])
@@ -35,6 +36,7 @@ class Option extends Model
     * Get an option by its name.
     *
     * @param $name
     *
     * @return mixed
     */
    public static function findByName($name)
@@ -46,6 +48,7 @@ class Option extends Model
     * Get the option's value.
     *
     * @param $value
     *
     * @return mixed
     */
    public function getOptionValueAttribute($value)
diff --git a/src/Models/Post.php b/src/Models/Post.php
index db77bc3..ac61d6e 100644
--- a/src/Models/Post.php
+++ b/src/Models/Post.php
@@ -19,16 +19,17 @@ use WP_Post;
 */
class Post extends Model
{
    public $timestamps = false;
    protected $table = DB_PREFIX . 'posts';
    protected $primaryKey = 'ID';
    protected $dates = ['post_date', 'post_date_gmt', 'post_modified', 'post_modified_gmt'];
    protected $prefix = DB_PREFIX;
    public $timestamps = false;

    /**
     * Create a new Eloquent model instance.
     *
     * @param  array $attributes
     *
     * @return void
     */
    public function __construct(array $attributes = [])
@@ -43,24 +44,11 @@ class Post extends Model
    }

    /**
     * The "booting" method of the model.
     *
     * @return void
     */
    protected static function boot()
    {
        parent::boot();

        static::addGlobalScope('published', function (Builder $builder) {
            $builder->where('post_status', 'publish');
        });
    }

    /**
     * Get all the posts within a certain post type.
     *
     * @param Builder $query query to add the scope to
     * @param string $name name of the post type
     *
     * @return Builder
     */
    public function scopePostType($query, $name)
@@ -72,6 +60,7 @@ class Post extends Model
     * Get a post by its slug.
     *
     * @param $slug
     *
     * @return static
     */
    public static function findBySlug($slug)
@@ -103,6 +92,7 @@ class Post extends Model
     * Get meta values for this Post.
     *
     * @param array|string|null $key
     *
     * @return mixed
     */
    public function getMeta($key = null)
@@ -127,6 +117,7 @@ class Post extends Model
     *
     * @param array|string|null $key key (or keys) to get or null for all.
     * @param bool $format whether to format this field or not
     *
     * @return array array of ACF values.
     */
    public function getACF($key = null, $format = true)
@@ -144,8 +135,7 @@ class Post extends Model
            $wantsArray = true;
        }

        foreach ($meta as $k => $value)
        {
        foreach ($meta as $k => $value) {
            $field = $this->getMeta('_' . $k);

            if (!acf_is_field_key($field)) {
@@ -160,7 +150,7 @@ class Post extends Model
            $field = get_field_object($field, $k, false, false);

            // unset subfields if the user didn't ask for it specifically
            if (((is_array($key) && !in_array($k, $key)) && $k !== $key || $key === null) && acf_is_sub_field($field)) {
            if (((is_array($key) && !in_array($k, $key, true)) && $k !== $key || $key === null) && acf_is_sub_field($field)) {
                unset($meta[$k]);
                continue;
            }
@@ -226,6 +216,7 @@ class Post extends Model
     * Get the permalink for this post.
     *
     * @see get_permalink
     *
     * @return false|string
     */
    public function getLinkAttribute()
@@ -246,9 +237,10 @@ class Post extends Model
    }

    /**
     * Get the thumbnail of this post
     * Get the thumbnail of this post.
     *
     * @see get_the_post_thumbnail
     *
     * @return string
     */
    public function getThumbnailAttribute()
@@ -257,10 +249,12 @@ class Post extends Model
    }

    /**
     * Get the thumbnail of this post
     * Get the thumbnail of this post.
     *
     * @see get_the_post_thumbnail
     *
     * @param string $size
     *
     * @return string
     */
    public function thumbnail($size = 'post-thumbnail')
@@ -292,6 +286,7 @@ class Post extends Model
     * Get the classes that should be applied to this post.
     *
     * @see get_post_class
     *
     * @return string
     */
    public function getClassesAttribute()
@@ -303,10 +298,25 @@ class Post extends Model
     * Get the {@link WP_Post} instance for this Post.
     *
     * @deprecated
     *
     * @return WP_Post
     */
    public function toWordpressPost()
    {
        return new WP_Post((object) $this->toArray());
    }

    /**
     * The "booting" method of the model.
     *
     * @return void
     */
    protected static function boot()
    {
        parent::boot();

        static::addGlobalScope('published', function (Builder $builder) {
            $builder->where('post_status', 'publish');
        });
    }
}
diff --git a/src/Models/Term.php b/src/Models/Term.php
index 8a25bf9..b9e9e44 100644
--- a/src/Models/Term.php
+++ b/src/Models/Term.php
@@ -12,14 +12,15 @@ use Koselig\Support\Wordpress;
 */
class Term extends Model
{
    public $timestamps = false;
    protected $primaryKey = 'term_id';
    protected $table = DB_PREFIX . 'terms';
    public $timestamps = false;

    /**
     * Create a new Eloquent model instance.
     *
     * @param  array $attributes
     *
     * @return void
     */
    public function __construct(array $attributes = [])
diff --git a/src/Models/TermTaxonomy.php b/src/Models/TermTaxonomy.php
index 7d581f6..a1542b9 100644
--- a/src/Models/TermTaxonomy.php
+++ b/src/Models/TermTaxonomy.php
@@ -11,14 +11,15 @@ use Koselig\Support\Wordpress;
 */
class TermTaxonomy extends Model
{
    public $timestamps = false;
    protected $primaryKey = 'term_taxonomy_id';
    protected $table = DB_PREFIX . 'term_taxonomy';
    public $timestamps = false;

    /**
     * Create a new Eloquent model instance.
     *
     * @param  array $attributes
     *
     * @return void
     */
    public function __construct(array $attributes = [])
diff --git a/src/Models/User.php b/src/Models/User.php
index d53fb53..2c22a78 100644
--- a/src/Models/User.php
+++ b/src/Models/User.php
@@ -15,16 +15,17 @@ use Koselig\Support\Wordpress;
class User extends Model implements AuthenticatableContract
{
    use Authenticatable;
    public $timestamps = false;

    protected $table = DB_PREFIX . 'users';
    protected $primaryKey = 'ID';
    protected $dates = ['user_registered'];
    public $timestamps = false;

    /**
     * Create a new Eloquent model instance.
     *
     * @param  array $attributes
     *
     * @return void
     */
    public function __construct(array $attributes = [])
diff --git a/src/Models/UserMeta.php b/src/Models/UserMeta.php
index 08a9630..7b1c9f8 100644
--- a/src/Models/UserMeta.php
+++ b/src/Models/UserMeta.php
@@ -3,7 +3,6 @@ namespace Koselig\Models;

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

/**
 * Table containing the metadata about users in the CMS.
@@ -12,9 +11,9 @@ use Koselig\Support\Wordpress;
 */
class UserMeta extends Model
{
    public $timestamps = false;
    protected $table = DB_PREFIX . 'usermeta';
    protected $primaryKey = 'umeta_id';
    public $timestamps = false;

    /**
     * Cache for all meta values.
@@ -29,6 +28,7 @@ class UserMeta extends Model
     * @param int|string|null $user user to get meta for (or name of the meta item to get
     *                              if you want to get the current user's meta)
     * @param string|null $name
     *
     * @return mixed
     */
    public static function get($user = null, $name = null)
diff --git a/src/Providers/ConfigServiceProvider.php b/src/Providers/ConfigServiceProvider.php
index 27fa111..4a28b74 100644
--- a/src/Providers/ConfigServiceProvider.php
+++ b/src/Providers/ConfigServiceProvider.php
@@ -16,7 +16,7 @@ class ConfigServiceProvider extends ServiceProvider
            realpath(__DIR__ . '/../../config/templates.php') => config_path('templates.php'),
            realpath(__DIR__ . '/../../config/wordpress.php') => config_path('wordpress.php'),
            realpath(__DIR__ . '/../../config/posttypes.php') => config_path('posttypes.php'),
            realpath(__DIR__ . '/../../config/supports.php') => config_path('supports.php')
            realpath(__DIR__ . '/../../config/supports.php') => config_path('supports.php'),
        ]);
    }
}
diff --git a/src/Providers/QueryServiceProvider.php b/src/Providers/QueryServiceProvider.php
index 07fea6c..c0721c2 100644
--- a/src/Providers/QueryServiceProvider.php
+++ b/src/Providers/QueryServiceProvider.php
@@ -30,6 +30,7 @@ class QueryServiceProvider extends ServiceProvider
        $this->app->bind('loop', function () {
            // current post in "The Loop"
            $post = $GLOBALS['post']->ID;

            return $this->cached[$post] ?? $this->cached[$post] = Post::find($GLOBALS['post']->ID);
        });
    }
diff --git a/src/Providers/WordpressServiceProvider.php b/src/Providers/WordpressServiceProvider.php
index a377b2f..bc4e9d5 100644
--- a/src/Providers/WordpressServiceProvider.php
+++ b/src/Providers/WordpressServiceProvider.php
@@ -4,7 +4,6 @@ namespace Koselig\Providers;
use Illuminate\Contracts\Routing\UrlGenerator;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\ServiceProvider;
use Koselig\Mail\WordpressMailServiceProvider;
use Koselig\Support\Action;
use Koselig\Support\Wordpress;

@@ -41,11 +40,54 @@ class WordpressServiceProvider extends ServiceProvider
    }

    /**
     * Register all of the site's theme support.
     *
     * @return void
     */
    public function addThemeSupport()
    {
        foreach (config('supports') as $key => $value) {
            if (is_string($key)) {
                add_theme_support($key, $value);
            } else {
                add_theme_support($value);
            }
        }
    }

    /**
     * Hacky fix to get network admin working, Wordpress is basing the network admin path off of
     * the default site's main link, which obviously doesn't work when the site and Wordpress are in
     * separate directories.
     *
     * @param $url
     * @param $path
     * @param $scheme
     *
     * @return string
     */
    public function rewriteNetworkUrl($url, $path, $scheme)
    {
        if ($scheme === 'relative') {
            $url = Wordpress::site()->path;
        } else {
            $url = set_url_scheme('http://' . Wordpress::site()->domain . Wordpress::site()->path, $scheme);
        }

        if ($path && is_string($path)) {
            $url .= str_replace('public/', '', WP_PATH) . ltrim($path, '/');
        }

        return $url;
    }

    /**
     * Set up the configuration values that wp-config.php
     * does. Use all the values out of .env instead.
     *
     * @SuppressWarnings(PHPMD.CamelCaseVariableName)
     * @SuppressWarnings(PHPMD.Superglobals)
     *
     * @return void
     */
    protected function setConfig()
@@ -71,13 +113,43 @@ class WordpressServiceProvider extends ServiceProvider

        $GLOBALS['wp_filter']['after_setup_theme'][10][] = [
            'function' => [$this, 'addThemeSupport'],
            'accepted_args' => 0
            'accepted_args' => 0,
        ];

        require ABSPATH . 'wp-settings.php';
    }

    /**
     * Wordpress core hooks needed for the main functionality of
     * Koselig.
     *
     * @return void
     */
    protected function triggerHooks()
    {
        // register the user's templates
        Action::hook('theme_page_templates', function ($pageTemplates) {
            return array_merge($pageTemplates, config('templates'));
        });

        Action::hook('network_site_url', [$this, 'rewriteNetworkUrl'], 10, 3);

        $this->registerPostTypes();
    }

    /**
     * Register all the site's custom post types with Wordpress.
     *
     * @return void
     */
    protected function registerPostTypes()
    {
        foreach (config('posttypes') as $key => $value) {
            register_post_type($key, $value);
        }
    }

    /**
     * Set all the database constants used by Wordpress.
     *
     * @param string $tablePrefix
@@ -150,75 +222,4 @@ class WordpressServiceProvider extends ServiceProvider
            }
        }
    }

    /**
     * Wordpress core hooks needed for the main functionality of
     * Koselig.
     *
     * @return void
     */
    protected function triggerHooks()
    {
        // register the user's templates
        Action::hook('theme_page_templates', function ($pageTemplates) {
            return array_merge($pageTemplates, config('templates'));
        });

        Action::hook('network_site_url', [$this, 'rewriteNetworkUrl'], 10, 3);

        $this->registerPostTypes();
    }

    /**
     * Register all the site's custom post types with Wordpress.
     *
     * @return void
     */
    protected function registerPostTypes()
    {
        foreach (config('posttypes') as $key => $value) {
            register_post_type($key, $value);
        }
    }

    /**
     * Register all of the site's theme support.
     *
     * @return void
     */
    public function addThemeSupport()
    {
        foreach (config('supports') as $key => $value) {
            if (is_string($key)) {
                add_theme_support($key, $value);
            } else {
                add_theme_support($value);
            }
        }
    }

    /**
     * Hacky fix to get network admin working, Wordpress is basing the network admin path off of
     * the default site's main link, which obviously doesn't work when the site and Wordpress are in
     * separate directories.
     *
     * @param $url
     * @param $path
     * @param $scheme
     * @return string
     */
    public function rewriteNetworkUrl($url, $path, $scheme)
    {
        if ($scheme == 'relative') {
            $url = Wordpress::site()->path;
        } else {
            $url = set_url_scheme('http://' . Wordpress::site()->domain . Wordpress::site()->path, $scheme);
        }

        if ($path && is_string($path)) {
            $url .= str_replace('public/', '', WP_PATH) . ltrim($path, '/');
        }

        return $url;
    }
}
diff --git a/src/Proxy/Query.php b/src/Proxy/Query.php
index 8466bd3..a56650a 100644
--- a/src/Proxy/Query.php
+++ b/src/Proxy/Query.php
@@ -65,6 +65,7 @@ use WP_Query;
 * @method static mixed lazyloadTermMeta(mixed $check, integer $term_id) Lazyload term meta for posts in the loop.
 * @method static mixed lazyloadCommentMeta(mixed $check, integer $comment_id) Lazyload comment meta for comments in
 *                                                                             the loop.
 *
 * @author Jordan Doyle <jordan@doyle.wf>
 */
class Query
@@ -76,17 +77,11 @@ class Query
     */
    private $query;

    public static function instance(WP_Query $query)
    {
        $instance = new static;
        $instance->query = $query;
        return $instance;
    }

    /**
     * Get a property from {@link WP_Query}
     * Get a property from {@link WP_Query}.
     *
     * @param $name
     *
     * @return mixed
     */
    public function __get($name)
@@ -95,10 +90,11 @@ class Query
    }

    /**
     * Pass a call to this function to {@link WP_Query}
     * Pass a call to this function to {@link WP_Query}.
     *
     * @param $name
     * @param $arguments
     *
     * @return mixed
     */
    public function __call($name, $arguments)
@@ -127,4 +123,12 @@ class Query

        return $this->query->{$name}(...$arguments);
    }

    public static function instance(WP_Query $query)
    {
        $instance = new static;
        $instance->query = $query;

        return $instance;
    }
}
diff --git a/src/Routing/ArchiveRoute.php b/src/Routing/ArchiveRoute.php
index bd3f93f..e14e405 100644
--- a/src/Routing/ArchiveRoute.php
+++ b/src/Routing/ArchiveRoute.php
@@ -26,6 +26,7 @@ class ArchiveRoute extends Route
     * @param  array|string $methods
     * @param  array $postTypes
     * @param  \Closure|array $action
     *
     * @return void
     */
    public function __construct($methods, $postTypes, $action)
@@ -41,6 +42,7 @@ class ArchiveRoute extends Route
     *
     * @param  \Illuminate\Http\Request $request
     * @param  bool $includingMethod
     *
     * @return bool
     */
    public function matches(Request $request, $includingMethod = true)
diff --git a/src/Routing/AuthorRoute.php b/src/Routing/AuthorRoute.php
index ef5b26d..641d556 100644
--- a/src/Routing/AuthorRoute.php
+++ b/src/Routing/AuthorRoute.php
@@ -29,6 +29,7 @@ class AuthorRoute extends Route
     * @param  array|string $methods
     * @param  array $users
     * @param  \Closure|array $action
     *
     * @return void
     */
    public function __construct($methods, $users, $action)
@@ -40,6 +41,23 @@ class AuthorRoute extends Route
    }

    /**
     * Determine if the route matches given request.
     *
     * @param  \Illuminate\Http\Request $request
     * @param  bool $includingMethod
     *
     * @return bool
     */
    public function matches(Request $request, $includingMethod = true)
    {
        if (!empty($this->getAction()['domain']) && !Wordpress::multisite($this->getAction()['domain'])) {
            return false;
        }

        return Wordpress::author($this->users);
    }

    /**
     * Run the route action and return the response.
     *
     * @return mixed
@@ -62,20 +80,4 @@ class AuthorRoute extends Route

        return parent::runCallable();
    }

    /**
     * Determine if the route matches given request.
     *
     * @param  \Illuminate\Http\Request $request
     * @param  bool $includingMethod
     * @return bool
     */
    public function matches(Request $request, $includingMethod = true)
    {
        if (!empty($this->getAction()['domain']) && !Wordpress::multisite($this->getAction()['domain'])) {
            return false;
        }

        return Wordpress::author($this->users);
    }
}
diff --git a/src/Routing/PageRoute.php b/src/Routing/PageRoute.php
index a0aa428..82789c5 100644
--- a/src/Routing/PageRoute.php
+++ b/src/Routing/PageRoute.php
@@ -21,6 +21,7 @@ class PageRoute extends Route
     * @param  array|string $methods
     * @param  array $users
     * @param  \Closure|array $action
     *
     * @return void
     */
    public function __construct($methods, $users, $action)
@@ -30,6 +31,30 @@ class PageRoute extends Route
    }

    /**
     * Determine if the route matches given request.
     *
     * @param  \Illuminate\Http\Request $request
     * @param  bool $includingMethod
     *
     * @return bool
     */
    public function matches(Request $request, $includingMethod = true)
    {
        $id = Wordpress::id();

        if (!$id) {
            // we're not on a Wordpress page
            return false;
        }

        if (!empty($this->getAction()['domain']) && !Wordpress::multisite($this->getAction()['domain'])) {
            return false;
        }

        return $this->uri === $id;
    }

    /**
     * Run the route action and return the response.
     *
     * @return mixed
@@ -52,27 +77,4 @@ class PageRoute extends Route

        return parent::runCallable();
    }

    /**
     * Determine if the route matches given request.
     *
     * @param  \Illuminate\Http\Request $request
     * @param  bool $includingMethod
     * @return bool
     */
    public function matches(Request $request, $includingMethod = true)
    {
        $id = Wordpress::id();

        if (!$id) {
            // we're not on a Wordpress page
            return false;
        }

        if (!empty($this->getAction()['domain']) && !Wordpress::multisite($this->getAction()['domain'])) {
            return false;
        }

        return $this->uri === $id;
    }
}
diff --git a/src/Routing/Routing.php b/src/Routing/Routing.php
index 2e40806..8d2752c 100644
--- a/src/Routing/Routing.php
+++ b/src/Routing/Routing.php
@@ -11,6 +11,7 @@ class Routing
     *
     * @param  string $slug slug to match
     * @param  callable|array|string|null $action
     *
     * @return \Illuminate\Routing\Route
     */
    public function template($slug, $action)
@@ -31,6 +32,7 @@ class Routing
     *
     * @param  string $slug slug to match
     * @param  callable|array|string|null $action
     *
     * @return \Illuminate\Routing\Route
     */
    public function page($slug, $action)
@@ -52,6 +54,7 @@ class Routing
     *
     * @param callable|string|array $postTypes
     * @param callable|array|string|null $action
     *
     * @return \Illuminate\Routing\Route
     */
    public function archive($postTypes = [], $action = [])
@@ -82,6 +85,7 @@ class Routing
     *
     * @param array|string $types post types to supply with this route
     * @param callable|string $action
     *
     * @return mixed
     */
    public function singular($types, $action)
@@ -108,6 +112,7 @@ class Routing
     *
     * @param callable|array|int $users authors to handle by this route
     * @param callable|array|string|null $action
     *
     * @return mixed
     */
    public function author($users, $action = [])
@@ -136,6 +141,7 @@ class Routing
     * Format <pre>$action</pre> in a nice way to pass to the {@link \Illuminate\Routing\RouteCollection}.
     *
     * @param $action
     *
     * @return array|string
     */
    protected function formatAction($action)
@@ -172,6 +178,7 @@ class Routing
     * route.
     *
     * @param $route
     *
     * @return mixed
     */
    protected function applyStack($route)
diff --git a/src/Routing/SingularRoute.php b/src/Routing/SingularRoute.php
index 8ba59b4..fbf777c 100644
--- a/src/Routing/SingularRoute.php
+++ b/src/Routing/SingularRoute.php
@@ -28,6 +28,7 @@ class SingularRoute extends Route
     * @param  array|string $methods
     * @param  array $types
     * @param  \Closure|array $action
     *
     * @return void
     */
    public function __construct($methods, $types, $action)
@@ -39,6 +40,28 @@ class SingularRoute extends Route
    }

    /**
     * Determine if the route matches given request.
     *
     * @param  \Illuminate\Http\Request $request
     * @param  bool $includingMethod
     *
     * @return bool
     */
    public function matches(Request $request, $includingMethod = true)
    {
        if (!Wordpress::id()) {
            // this isn't a wordpress-controlled page
            return false;
        }

        if (!empty($this->getAction()['domain']) && !Wordpress::multisite($this->getAction()['domain'])) {
            return false;
        }

        return Wordpress::singular($this->types);
    }

    /**
     * Run the route action and return the response.
     *
     * @return mixed
@@ -61,25 +84,4 @@ class SingularRoute extends Route

        return parent::runCallable();
    }

    /**
     * Determine if the route matches given request.
     *
     * @param  \Illuminate\Http\Request $request
     * @param  bool $includingMethod
     * @return bool
     */
    public function matches(Request $request, $includingMethod = true)
    {
        if (!Wordpress::id()) {
            // this isn't a wordpress-controlled page
            return false;
        }

        if (!empty($this->getAction()['domain']) && !Wordpress::multisite($this->getAction()['domain'])) {
            return false;
        }

        return Wordpress::singular($this->types);
    }
}
diff --git a/src/Routing/TemplateRoute.php b/src/Routing/TemplateRoute.php
index 55ccc3d..9778735 100644
--- a/src/Routing/TemplateRoute.php
+++ b/src/Routing/TemplateRoute.php
@@ -21,6 +21,7 @@ class TemplateRoute extends Route
     * @param  array|string $methods
     * @param  array $types
     * @param  \Closure|array $action
     *
     * @return void
     */
    public function __construct($methods, $types, $action)
@@ -31,34 +32,11 @@ class TemplateRoute extends Route
    }

    /**
     * Run the route action and return the response.
     *
     * @return mixed
     */
    protected function runCallable()
    {
        // bind the current post to the parameters of the function
        $function = new ReflectionFunction($this->action['uses']);
        $params = $function->getParameters();

        foreach ($params as $param) {
            if ($param->getClass()
                && ($param->getClass()->isSubclassOf(Post::class) || $param->getClass()->getName() === Post::class)) {
                $builder = $param->getClass()->getMethod('query')->invoke(null);
                $post = $builder->find(Wordpress::id());

                $this->setParameter($param->getName(), $post);
            }
        }

        return parent::runCallable();
    }

    /**
     * Determine if the route matches given request.
     *
     * @param  Request $request
     * @param  bool $includingMethod
     *
     * @return bool
     */
    public function matches(Request $request, $includingMethod = true)
@@ -78,4 +56,28 @@ class TemplateRoute extends Route

        return $this->uri === $slug;
    }

    /**
     * Run the route action and return the response.
     *
     * @return mixed
     */
    protected function runCallable()
    {
        // bind the current post to the parameters of the function
        $function = new ReflectionFunction($this->action['uses']);
        $params = $function->getParameters();

        foreach ($params as $param) {
            if ($param->getClass()
                && ($param->getClass()->isSubclassOf(Post::class) || $param->getClass()->getName() === Post::class)) {
                $builder = $param->getClass()->getMethod('query')->invoke(null);
                $post = $builder->find(Wordpress::id());

                $this->setParameter($param->getName(), $post);
            }
        }

        return parent::runCallable();
    }
}
diff --git a/src/Support/Action.php b/src/Support/Action.php
index 1af69aa..8d95163 100644
--- a/src/Support/Action.php
+++ b/src/Support/Action.php
@@ -29,6 +29,7 @@ class Action
     * @param string $tag tag to run
     * @param mixed $value value to run filters on
     * @param array ...$params extra params to pass to filters
     *
     * @return mixed|void
     */
    public static function filter($tag, $value, ...$params)
diff --git a/src/Support/Wordpress.php b/src/Support/Wordpress.php
index 24d24b2..230edc8 100644
--- a/src/Support/Wordpress.php
+++ b/src/Support/Wordpress.php
@@ -27,6 +27,7 @@ class Wordpress
     * Check if the current page is a singular item (eg. a news post).
     *
     * @param array|string $types
     *
     * @return bool
     */
    public static function singular($types = '')
@@ -38,6 +39,7 @@ class Wordpress
     * Check if the current page is an archive page.
     *
     * @param string|array|null $types check if the archive page is for this type
     *
     * @return bool
     */
    public static function archive($types = null)
@@ -49,6 +51,7 @@ class Wordpress
     * Check if the current page is an author page.
     *
     * @param int|array|User $users
     *
     * @return bool
     */
    public static function author($users = [])
@@ -71,6 +74,7 @@ class Wordpress
     *
     * @param null|int|array $id id (or ids) to check against the site, or null if you want to just check
     *                           if we are actually on a multisite
     *
     * @return bool
     */
    public static function multisite($id = null)
@@ -114,6 +118,7 @@ class Wordpress
     * Use of WP_User is deprecated, however this method will not be removed.
     *
     * @deprecated use <code>auth()->user()</code> instead.
     *
     * @return \WP_User
     */
    public static function currentUser()