🏡 index : ~doyle/koselig.git

author Jordan Johnson-Doyle <jordanjd@amazon.com> 2018-08-19 11:09:34.0 +00:00:00
committer Jordan Johnson-Doyle <jordanjd@amazon.com> 2018-08-19 11:12:45.0 +00:00:00
commit
70932c3a42895020b7da28731280d939eb65f065 [patch]
tree
25ecc0b8a4f882a380984bf52bf907120cd02e87
parent
cb2f57042179550e4c830cb2a5cef5d496f39911
download
70932c3a42895020b7da28731280d939eb65f065.tar.gz

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(-)

diff --git a/composer.json b/composer.json
index 5a272e6..ddd549d 100644
--- a/composer.json
+++ b/composer.json
@@ -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"
            }
        }
    }
}
diff --git a/src/Providers/WordpressServiceProvider.php b/src/Providers/WordpressServiceProvider.php
index cb52df3..adefb13 100644
--- a/src/Providers/WordpressServiceProvider.php
+++ b/src/Providers/WordpressServiceProvider.php
@@ -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.
     *