views:

27

answers:

2

Hi, 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?

+1  A: 

Change that to:

if(!function_exists('__')) {
    function __() {}
}
rpSetzer
yeah that makes sense but it didnt solve the actual issue unfortunately
David
A: 

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

Joseph Mastey
Hi thanks for the reply. So would you say just accessing the wordpress database directly would be the best idea. I was kind of hoping for an easier way - not in that it will be difficult, just more time intensive.
David
It will be time intensive if you have to replace functionality like tags and comments, but it will be cleaner (and probably faster in the long run, if you consider upgrades to either Wordpress or Magento).
Joseph Mastey
Otherwise, if it's a possibility, use blog.yourdomain.com or yourdomain.com/blog and skin Wordpress to look like your Magento install.
Joseph Mastey