Make WordPress Core

Ticket #16953: 16953.9.diff

File 16953.9.diff, 5.2 KB (added by jdgrimes, 11 years ago)

Add network plugin support in multisite

  • src/wp-admin/includes/plugin.php

     
    537537                if ( !empty($redirect) )
    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 ) {
    543544                        /**
     
    921922                unset($uninstallable_plugins);
    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
    926928                return true;
     
    932934                update_option('uninstall_plugins', $uninstallable_plugins);
    933935                unset($uninstallable_plugins);
    934936
     937                wp_register_plugin_realpath( WP_PLUGIN_DIR . '/' . $file );
    935938                include WP_PLUGIN_DIR . '/' . $file;
    936939
    937940                add_action( 'uninstall_' . $file, $callable );
  • src/wp-includes/functions.php

     
    14341434}
    14351435
    14361436/**
     1437 * Normalize a filesystem path.
     1438 *
     1439 * Replaces backslashes with forward slashes for Windows systems,
     1440 * and ensures no duplicate slashes exist.
     1441 *
     1442 * @param string $path Path to normalize.
     1443 * @return string Normalized path.
     1444 */
     1445function wp_normalize_path( $path ) {
     1446        $path = str_replace( '\\', '/', $path );
     1447        $path = preg_replace( '|/+|','/', $path );
     1448        return $path;
     1449}
     1450
     1451/**
    14371452 * Determines a writable directory for temporary files.
    14381453 * Function's preference is the return value of <code>sys_get_temp_dir()</code>,
    14391454 * followed by your PHP temporary upload directory, followed by WP_CONTENT_DIR,
  • src/wp-includes/plugin.php

     
    583583 * @uses WP_PLUGIN_DIR
    584584 */
    585585function plugin_basename($file) {
    586         $file = str_replace('\\','/',$file); // sanitize for Win32 installs
    587         $file = preg_replace('|/+|','/', $file); // remove any duplicate slash
    588         $plugin_dir = str_replace('\\','/',WP_PLUGIN_DIR); // sanitize for Win32 installs
    589         $plugin_dir = preg_replace('|/+|','/', $plugin_dir); // remove any duplicate slash
    590         $mu_plugin_dir = str_replace('\\','/',WPMU_PLUGIN_DIR); // sanitize for Win32 installs
    591         $mu_plugin_dir = preg_replace('|/+|','/', $mu_plugin_dir); // remove any duplicate slash
     586        global $wp_plugin_paths;
     587        $original_file = $file;
     588
     589        foreach ($wp_plugin_paths as $dir => $realdir) {
     590                if (strpos($file, $realdir) === 0) {
     591                        $file = $dir . substr( $file, strlen( $realdir ) );
     592                }
     593        }
     594
     595        $file = wp_normalize_path($file);
     596        $plugin_dir = wp_normalize_path( WP_PLUGIN_DIR );
     597        $mu_plugin_dir = wp_normalize_path( WPMU_PLUGIN_DIR );
     598
    592599        $file = preg_replace('#^' . preg_quote($plugin_dir, '#') . '/|^' . preg_quote($mu_plugin_dir, '#') . '/#','',$file); // get relative path from plugins dir
    593600        $file = trim($file, '/');
    594         return $file;
     601
     602        /**
     603         * Filter the plugin's basename.
     604         *
     605         * @since 3.7.0
     606         *
     607         * @param string $file Resolved basename.
     608         * @param string $original_file Filename passed into the function.
     609         */
     610        return apply_filters( 'plugin_basename', $file, $original_file );
    595611}
    596612
    597613/**
     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        }
     629}
     630
     631/**
    598632 * Gets the filesystem directory path (with trailing slash) for the plugin __FILE__ passed in
    599633 * @package WordPress
    600634 * @subpackage Plugin
  • src/wp-settings.php

     
    164164// Define must-use plugin directory constants, which may be overridden in the sunrise.php drop-in.
    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 ) {
    169171        include_once( $mu_plugin );
     
    173175// Load network activated plugins.
    174176if ( is_multisite() ) {
    175177        foreach( wp_get_active_network_plugins() as $network_plugin ) {
     178                wp_register_plugin_realpath( $network_plugin );
     179
    176180                include_once( $network_plugin );
    177181        }
    178182        unset( $network_plugin );
     
    206210register_theme_directory( get_theme_root() );
    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 );
     215
    210216        include_once( $plugin );
     217}
    211218unset( $plugin );
    212219
    213220// Load pluggable functions.