Posts tagged: how to Page 2 of 5

Add WordPress Plugins via Symlinks

WordPress doesn’t fully support adding plugins by using symbolic links in the wp-content/plugins folder. This is because plugins_url() which is often used for enqueuing plugin CSS and Javascript files uses plugin_basename() which in turn relies on WP_PLUGIN_DIR constant for extracting the plugin’s basename. However, the path to a symlinked plugin doesn’t include WP_PLUGIN_DIR and therefore it fails at this replacement:

$file = preg_replace('#^' . preg_quote($plugin_dir, '#') . '/|^' . preg_quote($mu_plugin_dir, '#') . '/#','',$file); // get relative path from plugins dir

The solution is to use the following plugins_url filter:

// Allow symlinking this plugin
add_filter( 'plugins_url', 'your_plugin_symlink_fix', 10, 3 );

function your_plugin_symlink_fix( $url, $path, $plugin ) {
	// Do it only for this plugin
	if ( strstr( $plugin, basename(__FILE__) ) )
		return str_replace( dirname(__FILE__), '/' . basename( dirname( $plugin ) ), $url );

	return $url;
}

or replace all instances of plugins_url( '/js/plugin.js', __FILE__ ) with something like:

WP_PLUGIN_URL . '/' . basename( __DIR__ ) . '/js/plugin.js'

Fixing /etc/init.d/php5-fpm Init Script for PHP 5.4 (from Dotdeb) on Debian Squeeze

I recently updated my server to PHP 5.4 and discovered that I was no longer able to restart the PHP-FPM service using the regular:

$ /etc/init.d/php5-fpm restart

or

$ service php5-fpm restart

I went to the official Debian GIT repository for the PHP 5.4 beta package and found the following differences between the init scripts (here is the one from Dotdeb):

Replacing my init script with the one from the official beta package solved the problem. I wonder what export ZEND_DONT_UNLOAD_MODULES=1 does wrong.

Develop and Work with WordPress Multisite Locally Using a Production Database

Update: This is useful only if you can’t edit your local /etc/hosts file (using a tool like Gas Mask makes it fast and super easy) and use the production domain for development.

To my knowledge, there was no way to work on a WordPress Multisite network locally while using a production database, so I spent a few hours and created a simple MU plugin which allows you to do just that.

The way Multisite Local Dev works is it filters all get_option and get_site_option calls for siteurl and home values to correct the site URLs. In addition, we define both $current_site and $current_blog globals already in wp-config.php to stop WordPress from querying database for these variables in wp-includes/ms-settings.php, which is the key to this solution.

Currently this works only with sites in sub-folders, but it should be relatively easy to modify it for either subdomains or separate domains.

Page 2 of 5