Created
June 22, 2012 10:15
-
-
Save tomjn/2971872 to your computer and use it in GitHub Desktop.
WP Junction fix
This file contains hidden or 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 | |
/* | |
Plugin Name: Junction fixes for plugins | |
Plugin URI: http://interconnectit.com/ | |
Description: Junctioning files into the WordPess plug-ins folder causes problems with php 5.3 for plugin_url, this tries to fix it. Place in the wp-content/mu-plugins folder so it loads before all other plugins. | |
Author: James R Whitehead | |
Version: 0.0.0.0.0.0.2 | |
Author URI: http://interconnectit.com | |
*/ | |
class fix_junctions { | |
var $paths = array( ); | |
function fix_junctions() { | |
if ( defined( 'WP_PLUGIN_DIR' ) && defined( 'WP_PLUGIN_URL' ) ) { | |
add_filter( 'plugins_url', array( &$this, 'plugins_url' ), 10, 3 ); | |
$this->real_paths( WP_PLUGIN_DIR ); | |
} | |
} | |
function real_paths( $plugins_dir = '' ) { | |
$plugins_dir = $this->clean_win32_path( $plugins_dir ); | |
if ( $dir = opendir( $plugins_dir ) ) { | |
while( $file = readdir( $dir ) ) { | |
if ( ! is_dir( $plugins_dir . '/' . $file ) || $file == '' || $file == '..' || $file == '.' ) | |
continue; | |
$p1 = $plugins_dir . '/' . $file; | |
$p2 = $this->clean_win32_path( realpath( $plugins_dir . '/' . $file ) ); | |
if ( $p1 != $p2 ) // We've found a junction, store the localised name. | |
$this->paths[ $p2 ] = $p1; | |
} | |
} | |
} | |
function plugins_url( $url = '', $path = '', $plugin = '') { | |
$wp_plugin_dir = $this->clean_win32_path( WP_PLUGIN_DIR ); | |
// Something isn't quite right, guessing it's a junction | |
if ( stristr( $plugin, $wp_plugin_dir ) === false && isset( $this->paths[ dirname( $plugin ) ] ) ) | |
$url = plugins_url( $path, $this->paths[ dirname( $plugin ) ] . '/' . basename( $plugin ) ); | |
return $url; | |
} | |
function clean_win32_path( $path = '' ) { | |
$path = str_replace( '\\', '/', $path ); // sanitize for Win32 installs | |
$path = preg_replace( '|/+|', '/', $path ); | |
return $path; | |
} | |
} | |
new fix_junctions(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment