Make WordPress Core

Changeset 27158


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.

Location:
trunk/src
Files:
6 edited

Legend:

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

    r27033 r27158  
    538538                        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
    539539                ob_start();
    540                 include_once(WP_PLUGIN_DIR . '/' . $plugin);
     540                wp_register_plugin_realpath( WP_PLUGIN_DIR . '/' . $plugin );
     541                include_once( WP_PLUGIN_DIR . '/' . $plugin );
    541542
    542543                if ( ! $silent ) {
     
    922923
    923924                define('WP_UNINSTALL_PLUGIN', $file);
     925                wp_register_plugin_realpath( WP_PLUGIN_DIR . '/' . dirname( $file ) );
    924926                include WP_PLUGIN_DIR . '/' . dirname($file) . '/uninstall.php';
    925927
     
    933935                unset($uninstallable_plugins);
    934936
     937                wp_register_plugin_realpath( WP_PLUGIN_DIR . '/' . $file );
    935938                include WP_PLUGIN_DIR . '/' . $file;
    936939
  • trunk/src/wp-admin/plugins.php

    r26518 r27158  
    144144                        // Go back to "sandbox" scope so we get the same errors as before
    145145                        function plugin_sandbox_scrape( $plugin ) {
     146                                wp_register_plugin_realpath( WP_PLUGIN_DIR . '/' . $plugin );
    146147                                include( WP_PLUGIN_DIR . '/' . $plugin );
    147148                        }
  • trunk/src/wp-admin/update.php

    r25951 r27158  
    8585                        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 );
    8686                        @ini_set('display_errors', true); //Ensure that Fatal errors are displayed.
    87                         include(WP_PLUGIN_DIR . '/' . $plugin);
     87                        wp_register_plugin_realpath( WP_PLUGIN_DIR . '/' . $plugin );
     88                        include( WP_PLUGIN_DIR . '/' . $plugin );
    8889                }
    8990                iframe_footer();
  • trunk/src/wp-includes/functions.php

    r27154 r27158  
    14321432
    14331433        return rtrim($base, '/') . '/' . ltrim($path, '/');
     1434}
     1435
     1436/**
     1437 * Normalize a filesystem path.
     1438 *
     1439 * Replaces backslashes with forward slashes for Windows systems,
     1440 * and ensures no duplicate slashes exist.
     1441 *
     1442 * @since 3.9.0
     1443 *
     1444 * @param string $path Path to normalize.
     1445 * @return string Normalized path.
     1446 */
     1447function wp_normalize_path( $path ) {
     1448        $path = str_replace( '\\', '/', $path );
     1449        $path = preg_replace( '|/+|','/', $path );
     1450        return $path;
    14341451}
    14351452
  • 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
  • trunk/src/wp-settings.php

    r26997 r27158  
    165165wp_plugin_directory_constants();
    166166
     167$GLOBALS['wp_plugin_paths'] = array();
     168
    167169// Load must-use plugins.
    168170foreach ( wp_get_mu_plugins() as $mu_plugin ) {
     171        wp_register_plugin_realpath( $mu_plugin );
    169172        include_once( $mu_plugin );
    170173}
     
    174177if ( is_multisite() ) {
    175178        foreach( wp_get_active_network_plugins() as $network_plugin ) {
     179                wp_register_plugin_realpath( $network_plugin );
    176180                include_once( $network_plugin );
    177181        }
     
    207211
    208212// Load active plugins.
    209 foreach ( wp_get_active_and_valid_plugins() as $plugin )
     213foreach ( wp_get_active_and_valid_plugins() as $plugin ) {
     214        wp_register_plugin_realpath( $plugin );
    210215        include_once( $plugin );
     216}
    211217unset( $plugin );
    212218
Note: See TracChangeset for help on using the changeset viewer.