Make WordPress Core


Ignore:
Timestamp:
02/10/2014 10:59:40 PM (13 years ago)
Author:
nacin
Message:

Detect and handle symlinking of plugins in plugin_basename().

props rmccue, MikeSchinkel, jdgrimes.
see #16953.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/plugin.php

    r26868 r27158  
    593593 * @uses WP_PLUGIN_DIR
    594594 */
    595 function plugin_basename($file) {
    596         $file = str_replace('\\','/',$file); // sanitize for Win32 installs
    597         $file = preg_replace('|/+|','/', $file); // remove any duplicate slash
    598         $plugin_dir = str_replace('\\','/',WP_PLUGIN_DIR); // sanitize for Win32 installs
    599         $plugin_dir = preg_replace('|/+|','/', $plugin_dir); // remove any duplicate slash
    600         $mu_plugin_dir = str_replace('\\','/',WPMU_PLUGIN_DIR); // sanitize for Win32 installs
    601         $mu_plugin_dir = preg_replace('|/+|','/', $mu_plugin_dir); // remove any duplicate slash
     595function plugin_basename( $file ) {
     596        global $wp_plugin_paths;
     597
     598        foreach ( $wp_plugin_paths as $dir => $realdir ) {
     599                if ( strpos( $file, $realdir ) === 0 ) {
     600                        $file = $dir . substr( $file, strlen( $realdir ) );
     601                }
     602        }
     603
     604        $file = wp_normalize_path( $file );
     605        $plugin_dir = wp_normalize_path( WP_PLUGIN_DIR );
     606        $mu_plugin_dir = wp_normalize_path( WPMU_PLUGIN_DIR );
     607
    602608        $file = preg_replace('#^' . preg_quote($plugin_dir, '#') . '/|^' . preg_quote($mu_plugin_dir, '#') . '/#','',$file); // get relative path from plugins dir
    603609        $file = trim($file, '/');
    604610        return $file;
     611}
     612
     613/**
     614 * Register a plugin's real path.
     615 *
     616 * This is used in {@see plugin_basename()} to resolve symlinked paths.
     617 *
     618 * @param string $file Known path to the file.
     619 */
     620function wp_register_plugin_realpath( $file ) {
     621        global $wp_plugin_paths;
     622
     623        $plugin_path = wp_normalize_path( dirname( $file ) );
     624        $plugin_realpath = wp_normalize_path( dirname( realpath( $file ) ) );
     625
     626        if ( $plugin_path !== $plugin_realpath ) {
     627                $wp_plugin_paths[ $plugin_path ] = $plugin_realpath;
     628        }
    605629}
    606630
Note: See TracChangeset for help on using the changeset viewer.