Monthly Archives: May 2014

MWI Plugin relative path to Mage.php

The MWI plugin is a great plugin to integrate Magento and WordPress. It allows you to pull in Magento blocks, CSS, JS and other Magento functionality into a wordpress blog. However, one thing that bothered me with this wordpress plugin was it required you to enter the full path to the Mage.php file, starting from the server root. This does not allow for seamless movement of the website’s database between environments.

The below solution will allow you to enter a full path on the server if you’d like, or a relative path from the wordpress root to the Mage.php file. Open up file wp-content/plugins/magento-wordpress-integration/mwi.php and within function mwi_admin_page() just below the $magepath declaration right around line 134, add four lines to check for a relative path as below.

// Mage Path
$magepath = self::getValue('magepath');

//check for relative path from blog root
if(file_exists(ABSPATH . $magepath)) {
	$magepath = ABSPATH . $magepath;
//check for relative path from blog root

// notification/error messages

Magento wysiwyg images don’t work when using a symlink

I recently started deploying a magento project using capistrano, which symlinked the public_html directory to a generated subdirectory of “releases”. After some digging I found Magento uses dirname(__FILE__) and the realpath() function quite a bit, which resolves symlinks, which causes Magento to use file paths that point at the symlinked directory instead of public_html. This mostly works, but there are a few bugs out there including the one I encoutered where when trying to insert an image from the wysiwyg editor the image would not be found. The solution is to extend Mage_Cms_Helper_Wysiwyg_Images with your own custom module and override the getCurrentUrl() method with the below. You only have to change one line.

public function getCurrentUrl()
		if (!$this->_currentUrl) {
			//$path = str_replace(Mage::getConfig()->getOptions()->getMediaDir(), '', $this->getCurrentPath());
			$path = str_replace(realpath(Mage::getConfig()->getOptions()->getMediaDir()), '', $this->getCurrentPath());
			$path = trim($path, DS);
			$this->_currentUrl = Mage::app()->getStore($this->_storeId)->getBaseUrl('media') .
			$this->convertPathToUrl($path) . '/';
		return $this->_currentUrl;