3

I have read several post on stackoverflow but didn't help, so i hope somebody can give the good answer.

I am using Laravel with wordpress. Now there is an error. Is it possible to rename or other method to change this?

Error:

Fatal error: Cannot redeclare __() (previously declared in C:app\laravel\vendor\laravel\framework\src\Illuminate\Foundation\helpers.php:821)

2 Answers 2

1

In de file wp-blog-header.php load before wp-load.php the l110n.php

if ( !isset($wp_did_header) ) {

    $wp_did_header = true;

    // Load the WordPress library.
    require_once( dirname(__FILE__).'/wp-includes/l10n.php' );
    require_once( dirname(__FILE__) . '/wp-load.php' );

    // Set up the WordPress query.
    wp();

    // Load the theme template.
    require_once( ABSPATH . WPINC . '/template-loader.php' );

}

And make a own helpers file in your LARAVEL project with this function with ownname:

if (! function_exists('ownname')) {
    /**
     * Translate the given message.
     *
     * @param  string  $key
     * @param  array  $replace
     * @param  string  $locale
     * @return \Illuminate\Contracts\Translation\Translator|string
     */
    function ownname($key = null, $replace = [], $locale = null)
    {
        return app('translator')->getFromJson($key, $replace, $locale);
    }
}
2
  • Hello Bas. I'm having this exact issue. Where did you create the own helpers file? Commented Jun 25, 2019 at 7:33
  • More explanation of what this does and how it works would be helpful
    – Richard
    Commented Sep 8, 2022 at 13:15
1

Laravel 5.4 added a helper function called __() This function has the same name as WordPress's.

Just rename Laravel's __ to ___ and run "composer update".

You can find the file in:

[project folder]\vendor\laravel\framework\src\Illuminate\Foundation\helpers.php

The problematic function is in line 947. Don't forget to pay attention to line 938 as well.

I had this exact same issue. Couldn't do it with Bas's solution, though. Hope this helps someone.

NOTE: You shoud never change files in the Vendor folder, as they would need to be maintained. I do not recommend this solution unless you understand the consequences. Still, it gets the job done.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.