Update Wordpress & Laravel
Diff
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(-)
@@ -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());
}
@@ -37,5 +37,7 @@ if (!function_exists('wp_mail')) {
}
}
});
return true;
}
}
@@ -1,6 +1,7 @@
<?php
namespace Koselig\Providers;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\ServiceProvider;
use Koselig\Support\Action;
@@ -46,10 +47,16 @@ class WordpressServiceProvider extends ServiceProvider
$table_prefix = 'wp_';
$this->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.
*
@@ -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.
@@ -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;