I have a Wordpress installation with a sub directory /shop where I have my Magento 2 installation. I've included wp-load in Magento's index.php (root) so that I can make use of WP functions within the shop such as get_header() etc.
I have an issue where both Wordpress and Magento are trying to declare the function __() for translations. This was solved by adding the following around the function in the functions.php file of Magento (/app/functions.php).
if (!function_exists ('__')){
function __() {
.......
}
}
This solved my immediate error of trying to redeclare the function but I then ran into my next error:-
Recoverable Error: Argument 1 passed to Magento\Framework\Exception\NoSuchEntityException::__construct() must be an instance of Magento\Framework\Phrase, string given, called in....vendor/magento/module-store/Model/StoreRepository.php on line 60
So, I checked what's on this line and it's a call to the __() function
throw new NoSuchEntityException(__('Requested store is not found'));
The return of the __() is giving a string and not an instance of Magento\Framework\Phrase because it's the WP declared version of the function. If I remove __('Requested store is not found') and pass null (ie don't pass a string) then the error is resolved. Obviously this is not what I want to do since those errors will be useful to me.
So, my question is, is there a way around this problem without having to re-name either the WP and Magento 2 functions as this would mean going through the entire code base and changing all calls to the function.
Thank you in advance.