From 32bd5c67a3052fc924d3e020c9541a30204d65fa Mon Sep 17 00:00:00 2001 From: Jordan Doyle Date: Sat, 14 Apr 2018 15:16:00 +0100 Subject: [PATCH] Update Wordpress & Laravel --- src/Http/Request.php | 2 +- src/Mail/Mailer.php | 2 ++ src/Providers/WordpressServiceProvider.php | 30 +++++++++++++++++++++++++++++- src/Proxy/WordpressDatabase.php | 22 ++++++++++++++++++++++ src/Support/RecursiveMenuIterator.php | 2 +- 5 files changed, 55 insertions(+), 3 deletions(-) diff --git a/src/Http/Request.php b/src/Http/Request.php index 8afb57d..33d926a 100644 --- a/src/Http/Request.php +++ b/src/Http/Request.php @@ -22,7 +22,7 @@ class Request extends BaseRequest * * @return Post */ - public function post() + public function page() { return $this->post ?: $this->post = Post::find(Wordpress::id()); } diff --git a/src/Mail/Mailer.php b/src/Mail/Mailer.php index e3b172c..2d0ecef 100644 --- a/src/Mail/Mailer.php +++ b/src/Mail/Mailer.php @@ -37,5 +37,7 @@ if (!function_exists('wp_mail')) { } } }); + + return true; } } diff --git a/src/Providers/WordpressServiceProvider.php b/src/Providers/WordpressServiceProvider.php index 2df3b60..73f292e 100644 --- a/src/Providers/WordpressServiceProvider.php +++ b/src/Providers/WordpressServiceProvider.php @@ -1,6 +1,7 @@ setDatabaseConstants($table_prefix); + // Wordpress attempts to define a method that Laravel should handle (__) + // so we rename WP's to __wp(). + $this->patchWordpressL10n(); + require ABSPATH . 'wp-settings.php'; // Set up the WordPress query. - wp(); + if (!app()->runningInConsole() && !wp_installing()) { + wp(); + } $this->triggerHooks(); @@ -124,6 +131,27 @@ class WordpressServiceProvider extends ServiceProvider } /** + * Wordpress defines their methods without checking if + * the method is defined beforehand like Laravel does. + * + * We had the option to patch the `__` method that Wordpress + * tries to define to give it a unique name or lose Laravel's + * `__`. As Laravel's `__` is quite a bit more useful than + * Wordpress'. + */ + protected function patchWordpressL10n() { + Cache::rememberForever('patch_wp_l10n', function () { + $path = ABSPATH . 'wp-includes' . DIRECTORY_SEPARATOR . 'l10n.php'; + + $original = file_get_contents($path); + $patched = str_replace('function __(', 'function __wp(', $original); + file_put_contents($path, $patched); + + return true; + }); + } + + /** * Set up the configuration values that wp-config.php * does. Use all the values out of .env instead. * diff --git a/src/Proxy/WordpressDatabase.php b/src/Proxy/WordpressDatabase.php index b711024..a008bdc 100644 --- a/src/Proxy/WordpressDatabase.php +++ b/src/Proxy/WordpressDatabase.php @@ -69,6 +69,28 @@ class WordpressDatabase extends wpdb } /** + * Determine if a database supports a particular feature. + * + * @see wpdb::has_cap() + * @param string $capability The feature to check for. Accepts 'collation', + * 'group_concat', 'subqueries', 'set_charset', + * 'utf8mb4', or 'utf8mb4_520'. + * @return int|false Whether the database feature is supported, false otherwise. + */ + public function has_cap($capability) { + $capability = strtolower($capability); + + switch ($capability) { + case 'set_charset': + return false; + case 'utf8mb4': + return strtolower(DB::connection()->getConfig('charset')) === $capability; + default: + return parent::has_cap($capability); + } + } + + /** * Retrieves the MySQL server version. * * @return null|string Null on failure, version number on success. diff --git a/src/Support/RecursiveMenuIterator.php b/src/Support/RecursiveMenuIterator.php index d825328..2f79c63 100644 --- a/src/Support/RecursiveMenuIterator.php +++ b/src/Support/RecursiveMenuIterator.php @@ -33,7 +33,7 @@ class RecursiveMenuIterator implements RecursiveIterator // only have nodes without a parent at the top level of the tree $this->items = collect($itemsArray)->filter(function ($item) { - return $item->menu_item_parent === 0; + return $item->menu_item_parent == 0; })->reverse()->values(); } else { $this->items = $menu; -- libgit2 1.7.2