Skip to content

Instantly share code, notes, and snippets.

@jasonrhodes
Last active November 15, 2017 14:12
Show Gist options
  • Save jasonrhodes/6168618 to your computer and use it in GitHub Desktop.
Save jasonrhodes/6168618 to your computer and use it in GitHub Desktop.
Once you load WordPress in via Composer (using the GitHub WordPress/WordPress mirror and Composer's "package" repository type), you have to solve a few directory path problems. This Composer script solution helps WordPress find your config file kept in your /config/ directory (You can easily change that path in the bin/wp-config-redirect script)
<?php
/**
* Load WordPress
*
*/
define('WP_USE_THEMES', true);
require 'vendor/wordpress/wordpress/wp-blog-header.php';
{
"repositories": [
{
"type": "package",
"package": {
"name": "wordpress/wordpress",
"version": "3.6",
"source": {
"url": "https://github.com/WordPress/WordPress.git",
"type": "git",
"reference": "3.6"
}
}
}
],
"require": {
"wordpress/wordpress": "3.6"
},
"scripts": {
"post-install-cmd": "bin/wp-config-redirect",
"post-update-cmd": "bin/wp-config-redirect"
}
}
<?php
require dirname(__DIR__) . '/bootstrap.php';
#!/usr/bin/env bash
########################################################################
# Solves a problem with WordPress being kept in the Composer-managed
# vendor directory, where it looks for wp-config.php only one level
# up from the wp directory. After composer install/update, we run this
# command to create a dummy wp-config.php file that includes our real
# config file, managed in the /config directory (duh).
########################################################################
echo "<?php require dirname(dirname(__DIR__)) . '/config/wordpress.php';'" > "vendor/wordpress/wp-config.php"
@jasonrhodes
Copy link
Author

So far, the only other thing we've had to do to make this work is:

$ cd public
$ ln -s ../vendor/wordpress/wordpress/wp-admin wp-admin

@jenwachter
Copy link

Just a small typo:

echo "<?php require dirname(dirname(__DIR__)) . '/config/wordpress.php';'" > "vendor/wordpress/wp-config.php"

should be:

echo "<?php require dirname(dirname(__DIR__)) . '/config/wordpress.php';" > "vendor/wordpress/wp-config.php"

@jenwachter
Copy link

Also:

$ cd public
$ ln -s ../vendor/wordpress/wordpress/wp-login.php wp-login.php
$ ln -s ../vendor/wordpress/wordpress/wp-includes wp-includes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment