Patch Wordpress' __ function using composer-patches instead of at runtime
Diff
composer.json | 8 +++++++-
src/Providers/WordpressServiceProvider.php | 26 --------------------------
2 files changed, 7 insertions(+), 27 deletions(-)
@@ -12,7 +12,8 @@
"illuminate/support": "^5.6",
"illuminate/database": "^5.6",
"illuminate/routing": "^5.6",
"watson/rememberable": "^2.0"
"watson/rememberable": "^2.0",
"cweagans/composer-patches": "^1.6"
},
"autoload": {
"psr-4": {
@@ -33,6 +34,11 @@
"Query": "Koselig\\Facades\\Query",
"Loop": "Koselig\\Facades\\Loop"
}
},
"patches": {
"johnpbloch/wordpress-core": {
"Patch __ method in l10n to stop conflicting with Laravel": "https://github.com/koselig/wordpress-core/commit/0881e719711b68812934608a01e986f420658674.diff"
}
}
}
}
@@ -47,10 +47,6 @@ 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.
@@ -131,28 +127,6 @@ 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.
*