package playne

imports "programmer"

beware the trailing slash…

So, we had an interesting issue with wordpress plugins not using the correct path, so we had busted URLs for their resources. for example:

<img src='http://example.com/wp-content/plugins/var/www/example.com/htdocs/wp-content/plugins/myplugin/logo.png' alt='plugin logo'/>

Now, this is obviously ideal since the resource was not being loaded (bad mkay).

The fix is only 1 character believe it or not. Removing the trailing slash from the WP_PLUGIN_DIR config variable fixed the problem!

Why? Well the function that plugins call to get the path they need is called “plugin_basename” and plugin basename assumes that you do not have a trailing slash on your path – here is the code for it – Note the “/|^” and the “/#” to add the trailing slash onto your WP_PLUGIN_DIR and WPMU_PLUGIN_DIR paths.

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

Posted

in

by