Created
April 8, 2013 07:50
-
-
Save justinstern/5334998 to your computer and use it in GitHub Desktop.
Allow symlinked plugins to function with WooCommerce plugin_url() call: issue #2859: https://github.com/woothemes/woocommerce/issues/2859
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_filter( 'plugins_url', 'allow_symlink_plugins_url', 10, 3 ); | |
/** | |
* Allow symlinked plugins to function. This was made necessary by a change in | |
* the standard WooCommerce plugin_url() method from: | |
* | |
* plugins_url( basename( plugin_dir_path( __FILE__ ) ), basename( __FILE__ ) ); | |
* | |
* which worked with symlinks, to: | |
* | |
* untrailingslashit( plugins_url( '/', __FILE__ ) ) | |
* | |
* which does not. | |
* | |
* Note: we use '/' as the path to detect when to "fix" the url because that | |
* seems to be the new convention. There is some possibility of this breaking | |
* a 3rd party plugin that does not follow the same convention. We'll just have | |
* to try and do our best to remember this function exists | |
* | |
* @param string $url the url generated by plugins_url() | |
* @param string $path the path passed to plugins_url() | |
* @param string $plugin the plugin passed to plugins_url() | |
*/ | |
function allow_symlink_plugins_url( $url, $path, $plugin ) { | |
if ( '/' === $path && $plugin ) { | |
remove_filter( 'plugins_url', 'allow_symlink_plugins_url', 10, 3 ); | |
$url = plugins_url( basename( plugin_dir_path( $plugin ) ), basename( $plugin ) ); | |
add_filter( 'plugins_url', 'allow_symlink_plugins_url', 10, 3 ); | |
} | |
return $url; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment