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(-)
@@ -22,6 +22,7 @@
* @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 @@
* @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 @@
* syntax.
*
* @param $callback
*
* @return Closure
*/
protected static function wrap($callback)
@@ -57,6 +57,7 @@
* Validate a user's credentials.
*
* @param array $credentials
*
* @return bool
*/
public function validate(array $credentials = [])
@@ -74,6 +75,7 @@
* @param array $credentials
* @param bool $remember
* @param bool $login
*
* @return bool
*/
public function attempt(array $credentials = [], $remember = false, $login = true)
@@ -99,6 +101,7 @@
* Log a user into the application without sessions or cookies.
*
* @param array $credentials
*
* @return bool
*/
public function once(array $credentials = [])
@@ -117,6 +120,7 @@
*
* @param \Illuminate\Contracts\Auth\Authenticatable $user
* @param bool $remember
*
* @return void
*/
public function login(Authenticatable $user, $remember = false)
@@ -133,6 +137,7 @@
*
* @param mixed $id
* @param bool $remember
*
* @return \Illuminate\Contracts\Auth\Authenticatable|bool
*/
public function loginUsingId($id, $remember = false)
@@ -154,6 +159,7 @@
* 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 @@
* Set the current user.
*
* @param \Illuminate\Contracts\Auth\Authenticatable $user
*
* @return $this
*/
public function setUser(Authenticatable $user)
@@ -1,13 +1,14 @@
<?php
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
@@ -8,6 +8,7 @@
*
* @see \Koselig\Proxy\Query
* @mixin \Koselig\Proxy\Query
*
* @author Jordan Doyle <jordan@doyle.wf>
*/
class Query extends Facade
@@ -8,6 +8,7 @@
*
* @see \Koselig\Hashing\WordpressHasher
* @mixin \Koselig\Hashing\WordpressHasher
*
* @author Jordan Doyle <jordan@doyle.wf>
*/
class WPHash extends Facade
@@ -16,7 +16,9 @@
*
* @param string $value
* @param array $options
*
* @throws \RuntimeException
*
* @return string
*/
public function make($value, array $options = [])
@@ -30,6 +32,7 @@
* @param string $value
* @param string $hashedValue
* @param array $options
*
* @return bool
*/
public function check($value, $hashedValue, array $options = [])
@@ -42,6 +45,7 @@
*
* @param string $hashedValue
* @param array $options
*
* @return bool
*/
public function needsRehash($hashedValue, array $options = [])
@@ -1,4 +1,5 @@
<?php
use Illuminate\Mail\Message;
use Illuminate\Support\Facades\Mail;
use Koselig\Support\Action;
@@ -12,6 +13,7 @@
* @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 = [])
@@ -9,8 +9,8 @@
/**
* 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 @@
* @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 @@
public function parent()
{
return $this->belongsTo(Comment::class, 'comment_parent');
return $this->belongsTo(self::class, 'comment_parent');
}
}
@@ -14,8 +14,6 @@
*/
class Meta extends Model
{
protected $primaryKey = 'meta_id';
protected $table = DB_PREFIX . 'postmeta';
public $timestamps = false;
/**
@@ -24,11 +22,14 @@
* @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 @@
* @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 @@
* 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 @@
$field = static::get($page, '_' . $name);
if (!acf_is_field_key($field)) {
return null;
return;
}
$field = get_field_object($field, $name, false, false);
@@ -11,14 +11,15 @@
*/
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 @@
* Get an option by its name.
*
* @param $name
*
* @return mixed
*/
public static function findByName($name)
@@ -46,6 +48,7 @@
* Get the option's value.
*
* @param $value
*
* @return mixed
*/
public function getOptionValueAttribute($value)
@@ -19,16 +19,17 @@
*/
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 = [])
@@ -40,20 +41,6 @@
$this->prefix = DB_PREFIX . Wordpress::getSiteId() . '_';
$this->setTable($this->prefix . 'posts');
}
}
/**
* 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');
});
}
/**
@@ -61,6 +48,7 @@
*
* @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 @@
* Get a post by its slug.
*
* @param $slug
*
* @return static
*/
public static function findBySlug($slug)
@@ -103,6 +92,7 @@
* Get meta values for this Post.
*
* @param array|string|null $key
*
* @return mixed
*/
public function getMeta($key = null)
@@ -127,6 +117,7 @@
*
* @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 @@
$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 @@
$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 @@
* Get the permalink for this post.
*
* @see get_permalink
*
* @return false|string
*/
public function getLinkAttribute()
@@ -246,9 +237,10 @@
}
/**
* 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 @@
}
/**
* 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 @@
* Get the classes that should be applied to this post.
*
* @see get_post_class
*
* @return string
*/
public function getClassesAttribute()
@@ -303,10 +298,25 @@
* 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');
});
}
}
@@ -12,14 +12,15 @@
*/
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 = [])
@@ -11,14 +11,15 @@
*/
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 = [])
@@ -15,16 +15,17 @@
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 = [])
@@ -1,9 +1,8 @@
<?php
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 @@
*/
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 @@
* @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)
@@ -16,7 +16,7 @@
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'),
]);
}
}
@@ -30,6 +30,7 @@
$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);
});
}
@@ -1,10 +1,9 @@
<?php
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 @@
}
/**
* 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,10 +113,40 @@
$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);
}
}
/**
@@ -147,78 +219,7 @@
define('PATH_CURRENT_SITE', $this->app->make('config')->get('wordpress.path_current_site'));
define('SITE_ID_CURRENT_SITE', $this->app->make('config')->get('wordpress.site_id_current_site'));
define('BLOG_ID_CURRENT_SITE', $this->app->make('config')->get('wordpress.blog_id_current_site'));
}
}
}
/**
* 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;
}
}
@@ -65,6 +65,7 @@
* @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 @@
*/
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 @@
}
/**
* 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)
@@ -126,5 +122,13 @@
}
return $this->query->{$name}(...$arguments);
}
public static function instance(WP_Query $query)
{
$instance = new static;
$instance->query = $query;
return $instance;
}
}
@@ -26,6 +26,7 @@
* @param array|string $methods
* @param array $postTypes
* @param \Closure|array $action
*
* @return void
*/
public function __construct($methods, $postTypes, $action)
@@ -41,6 +42,7 @@
*
* @param \Illuminate\Http\Request $request
* @param bool $includingMethod
*
* @return bool
*/
public function matches(Request $request, $includingMethod = true)
@@ -29,6 +29,7 @@
* @param array|string $methods
* @param array $users
* @param \Closure|array $action
*
* @return void
*/
public function __construct($methods, $users, $action)
@@ -37,6 +38,23 @@
$this->users = $this->uri;
$this->uri = 'author/' . (implode('/', $this->users) ?: 'all');
}
/**
* 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);
}
/**
@@ -61,21 +79,5 @@
}
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);
}
}
@@ -21,12 +21,37 @@
* @param array|string $methods
* @param array $users
* @param \Closure|array $action
*
* @return void
*/
public function __construct($methods, $users, $action)
{
parent::__construct($methods, $users, $action);
$this->uri = 'page/' . $this->uri();
}
/**
* 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;
}
/**
@@ -51,28 +76,5 @@
}
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;
}
}
@@ -11,6 +11,7 @@
*
* @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 @@
*
* @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 @@
*
* @param callable|string|array $postTypes
* @param callable|array|string|null $action
*
* @return \Illuminate\Routing\Route
*/
public function archive($postTypes = [], $action = [])
@@ -82,6 +85,7 @@
*
* @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 @@
*
* @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 @@
* 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 @@
* route.
*
* @param $route
*
* @return mixed
*/
protected function applyStack($route)
@@ -28,6 +28,7 @@
* @param array|string $methods
* @param array $types
* @param \Closure|array $action
*
* @return void
*/
public function __construct($methods, $types, $action)
@@ -36,6 +37,28 @@
$this->types = $this->uri;
$this->uri = 'singular/' . implode('/', $this->types);
}
/**
* 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);
}
/**
@@ -60,26 +83,5 @@
}
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);
}
}
@@ -21,6 +21,7 @@
* @param array|string $methods
* @param array $types
* @param \Closure|array $action
*
* @return void
*/
public function __construct($methods, $types, $action)
@@ -28,30 +29,6 @@
parent::__construct($methods, $types, $action);
$this->uri = 'template/' . parent::uri();
}
/**
* 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();
}
/**
@@ -59,6 +36,7 @@
*
* @param Request $request
* @param bool $includingMethod
*
* @return bool
*/
public function matches(Request $request, $includingMethod = true)
@@ -77,5 +55,29 @@
}
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();
}
}
@@ -29,6 +29,7 @@
* @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)
@@ -27,6 +27,7 @@
* 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 @@
* 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 @@
* 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 @@
*
* @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 @@
* 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()