Commit 6c10b67e authored by Andrew Nacin's avatar Andrew Nacin
Browse files

Detect and handle symlinking of plugins in plugin_basename().

props rmccue, MikeSchinkel, jdgrimes.
see #16953.

Built from https://develop.svn.wordpress.org/trunk@27158


git-svn-id: https://core.svn.wordpress.org/trunk@27024 1a063a9b-81f0-0310-95a4-ce76da25c4cd
parent 0892e43a
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -537,6 +537,7 @@ function activate_plugin( $plugin, $redirect = '', $network_wide = false, $silen
		if ( !empty($redirect) )
			wp_redirect(add_query_arg('_error_nonce', wp_create_nonce('plugin-activation-error_' . $plugin), $redirect)); // we'll override this later if the plugin can be included without fatal error
		ob_start();
		wp_register_plugin_realpath( WP_PLUGIN_DIR . '/' . $plugin );
		include_once( WP_PLUGIN_DIR . '/' . $plugin );

		if ( ! $silent ) {
@@ -921,6 +922,7 @@ function uninstall_plugin($plugin) {
		unset($uninstallable_plugins);

		define('WP_UNINSTALL_PLUGIN', $file);
		wp_register_plugin_realpath( WP_PLUGIN_DIR . '/' . dirname( $file ) );
		include WP_PLUGIN_DIR . '/' . dirname($file) . '/uninstall.php';

		return true;
@@ -932,6 +934,7 @@ function uninstall_plugin($plugin) {
		update_option('uninstall_plugins', $uninstallable_plugins);
		unset($uninstallable_plugins);

		wp_register_plugin_realpath( WP_PLUGIN_DIR . '/' . $file );
		include WP_PLUGIN_DIR . '/' . $file;

		add_action( 'uninstall_' . $file, $callable );
+1 −0
Original line number Diff line number Diff line
@@ -143,6 +143,7 @@ if ( $action ) {
			@ini_set('display_errors', true); //Ensure that Fatal errors are displayed.
			// Go back to "sandbox" scope so we get the same errors as before
			function plugin_sandbox_scrape( $plugin ) {
				wp_register_plugin_realpath( WP_PLUGIN_DIR . '/' . $plugin );
				include( WP_PLUGIN_DIR . '/' . $plugin );
			}
			plugin_sandbox_scrape( $plugin );
+2 −1
Original line number Diff line number Diff line
@@ -84,6 +84,7 @@ if ( isset($_GET['action']) ) {

			error_reporting( E_CORE_ERROR | E_CORE_WARNING | E_COMPILE_ERROR | E_ERROR | E_WARNING | E_PARSE | E_USER_ERROR | E_USER_WARNING | E_RECOVERABLE_ERROR );
			@ini_set('display_errors', true); //Ensure that Fatal errors are displayed.
			wp_register_plugin_realpath( WP_PLUGIN_DIR . '/' . $plugin );
			include( WP_PLUGIN_DIR . '/' . $plugin );
		}
		iframe_footer();
+17 −0
Original line number Diff line number Diff line
@@ -1433,6 +1433,23 @@ function path_join( $base, $path ) {
	return rtrim($base, '/') . '/' . ltrim($path, '/');
}

/**
 * Normalize a filesystem path.
 *
 * Replaces backslashes with forward slashes for Windows systems,
 * and ensures no duplicate slashes exist.
 *
 * @since 3.9.0
 *
 * @param string $path Path to normalize.
 * @return string Normalized path.
 */
function wp_normalize_path( $path ) {
	$path = str_replace( '\\', '/', $path );
	$path = preg_replace( '|/+|','/', $path );
	return $path;
}

/**
 * Determines a writable directory for temporary files.
 * Function's preference is the return value of <code>sys_get_temp_dir()</code>,
+31 −7
Original line number Diff line number Diff line
@@ -593,17 +593,41 @@ function remove_all_actions($tag, $priority = false) {
 * @uses WP_PLUGIN_DIR
 */
function plugin_basename( $file ) {
	$file = str_replace('\\','/',$file); // sanitize for Win32 installs
	$file = preg_replace('|/+|','/', $file); // remove any duplicate slash
	$plugin_dir = str_replace('\\','/',WP_PLUGIN_DIR); // sanitize for Win32 installs
	$plugin_dir = preg_replace('|/+|','/', $plugin_dir); // remove any duplicate slash
	$mu_plugin_dir = str_replace('\\','/',WPMU_PLUGIN_DIR); // sanitize for Win32 installs
	$mu_plugin_dir = preg_replace('|/+|','/', $mu_plugin_dir); // remove any duplicate slash
	global $wp_plugin_paths;

	foreach ( $wp_plugin_paths as $dir => $realdir ) {
		if ( strpos( $file, $realdir ) === 0 ) {
			$file = $dir . substr( $file, strlen( $realdir ) );
		}
	}

	$file = wp_normalize_path( $file );
	$plugin_dir = wp_normalize_path( WP_PLUGIN_DIR );
	$mu_plugin_dir = wp_normalize_path( WPMU_PLUGIN_DIR );

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

/**
 * Register a plugin's real path.
 *
 * This is used in {@see plugin_basename()} to resolve symlinked paths.
 *
 * @param string $file Known path to the file.
 */
function wp_register_plugin_realpath( $file ) {
	global $wp_plugin_paths;

	$plugin_path = wp_normalize_path( dirname( $file ) );
	$plugin_realpath = wp_normalize_path( dirname( realpath( $file ) ) );

	if ( $plugin_path !== $plugin_realpath ) {
		$wp_plugin_paths[ $plugin_path ] = $plugin_realpath;
	}
}

/**
 * Gets the filesystem directory path (with trailing slash) for the plugin __FILE__ passed in
 * @package WordPress
Loading