From deb2e457c49ec7e31ba1545936d90397e43ff937 Mon Sep 17 00:00:00 2001 From: Jordan Doyle Date: Fri, 7 Oct 2016 12:58:01 +0100 Subject: [PATCH] Nicer WP interfacing & allow CMS to be outside /cms --- src/Providers/WordpressServiceProvider.php | 7 ++++--- src/Support/Wordpress.php | 16 ++++++++++++++-- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/Providers/WordpressServiceProvider.php b/src/Providers/WordpressServiceProvider.php index 88e91ee..8b80600 100644 --- a/src/Providers/WordpressServiceProvider.php +++ b/src/Providers/WordpressServiceProvider.php @@ -7,6 +7,7 @@ use Illuminate\Support\Facades\DB; use Illuminate\Support\ServiceProvider; use Koselig\Guards\WordpressGuard; use Koselig\Support\Action; +use Koselig\Support\Wordpress; /** * Service provider for everything Wordpress, configures @@ -174,13 +175,13 @@ class WordpressServiceProvider extends ServiceProvider // separate directories. Action::hook('network_site_url', function ($url, $path, $scheme) { if ($scheme == 'relative') { - $url = get_current_site()->path; + $url = Wordpress::site()->path; } else { - $url = set_url_scheme('http://' . get_current_site()->domain . get_current_site()->path, $scheme); + $url = set_url_scheme('http://' . Wordpress::site()->domain . Wordpress::site()->path, $scheme); } if ($path && is_string($path)) { - $url .= 'cms/' . ltrim($path, '/'); + $url .= str_replace('public/', '', WP_PATH) . ltrim($path, '/'); } return $url; diff --git a/src/Support/Wordpress.php b/src/Support/Wordpress.php index 8b18435..dec572a 100644 --- a/src/Support/Wordpress.php +++ b/src/Support/Wordpress.php @@ -80,7 +80,7 @@ class Wordpress } } - return $id === null ? is_multisite() : ($id === static::getMultisite()); + return $id === null ? is_multisite() : ($id === static::getSiteId()); } /** @@ -88,16 +88,28 @@ class Wordpress * * @return int */ - public static function getMultisite() + public static function getSiteId() { return get_current_blog_id(); } /** + * Get the current site that the user is currently browsing. + * + * @return \WP_Network + */ + public static function site() + { + return get_current_site(); + } + + /** * Get the current logged in user. Generally, you shouldn't be using this * function and should instead be using Auth::user() from Laravel to get * the current logged in Wordpress user. * + * Use of WP_User is deprecated, however this method will not be removed. + * * @return \WP_User */ public static function currentUser() -- libgit2 1.7.2