Symlinks on Windows using Composer

I was reminded today that in order to get symlinks to create on a windows machine that you need to “run as administrator” when starting your console, otherwise you’ll get an error like “Warning: symlink(): Cannot create symlink, error code(1314)” . While we’re on the topic, how about I demo how the autoloader is setup in my composer.json file along with the calling of post install and post update scripts.

    "autoload": {
		"psr-4": {
			"Nick\\": "script/"
    "require": {
        "php": ">=5.4",
        "wordpress/wordpress": "4.0"
    "scripts": {
        "post-install-cmd": [
        "post-update-cmd": [

Then, my post install file lives at /script/Install.php

namespace Nick;
use Composer\Script\Event;
class Install {
    public static function symlinks(Event $event) {
    	$rootDir = dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR;
		$wordpressDir = $rootDir . 'vendor' . DIRECTORY_SEPARATOR . 'wordpress' . DIRECTORY_SEPARATOR . 'wordpress' . DIRECTORY_SEPARATOR;
		//htaccess file
    	if(! file_exists($wordpressDir . '.htaccess')) {
			symlink($rootDir . '.htaccess', $wordpressDir . '.htaccess');
    	//wordpress config file
    	if(! file_exists($wordpressDir . 'wp-config.php')) {
    		symlink($rootDir . 'config' . DIRECTORY_SEPARATOR . 'wp-config.php', $wordpressDir . 'wp-config.php');
    	//wordpress db config file
    	if(! file_exists($wordpressDir . 'db-config.php')) {
    		symlink($rootDir . 'config' . DIRECTORY_SEPARATOR . 'db-config.php', $wordpressDir . 'db-config.php');
    	if(! file_exists($rootDir . 'public' . DIRECTORY_SEPARATOR . 'wp')) {
    		symlink($wordpressDir, $rootDir . 'public' . DIRECTORY_SEPARATOR . 'wp');

Note that I’ve chosen to separate the database connection from the main wordpress config file so it can be ignored separately in version control.

MWI Plugin relative path to Mage.php

The MWI plugin http://www.mwi-plugin.com/ 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

WordPress filter when inserting post breaks my html

I’m programmatically inserting posts into wordpress and all of a sudden the drop down box I’d coded into the content was getting changed sometime between when I’d call wp_insert_post and when it gets saved in the database. The select and option tags would get stripped out and a p tag would get tossed in there randomly. The solution was to disable the filtering wordpress does on the $postarr by doing the following:

wp_insert_post( $postArray );