Reputation: 1
I am trying to integrate wordpress into a magento install but keep getting the following error when trying to include
Fatal error: Cannot redeclare __()
I assume this is because both magento and wordpress use this.
How can i get around this.
I have tried things like:
if(!function_exists('__()')) {
function __() {}
}
in both magento and wordpress files but it makes no difference - granted i dont fully understand what its doing.
Are there any suggestions on getting around this?
Upvotes: 0
Views: 1713
Reputation: 21
You can modify your WordPress code. It allows you to integrate both WordPress and Magento easily. I used SSH to get into the server and went into the blog directory. I then ran the following commands:
grep -rl '__(' * | xargs sed -i 's/__(/__wp(/g'
This allowed me to change all references to the '_' function to '_wp' instead with no more redefine errors.
There are some issues to be aware of when using this method:
My method of upgrading is:
This has worked well for me.
http://www.technickels.com/2012/12/wordpress-integration-with-magento/
Upvotes: 2
Reputation: 27099
As stated already, the issue occurs because both frameworks define the same function (__()
). In order to solve these problems, you need to remove one of the declarations (or make it conditional as listed). IF they happen to be identical functions in both frameworks this is fine, but if either one of them implements the function differently you will need to move one of the declarations to another function (i.e. __2()
) and refactor the existing code to point to it. This is a bad idea.
This is actually a good example of why Wordpress and Magento are not easily closely tied together. My first suggestion for getting around this would be to keep the two codebases at arm's length and use mod-rewrite to take care of integrating them if at all possible. Failing that, and depending on requirements, use Wordpress installed elsewhere to manage posts and grab the database information with a wrapper.
When the codebases change (e.g. you upgrade), having integrated the two codebases will likely cause you much existential angst.
Hope that helps!
Thanks, Joe
Upvotes: 1
Reputation: 2416
Change that to:
if(!function_exists('__')) {
function __() {}
}
Upvotes: 2