Make WordPress Core

Ticket #16953: symlinked_plugins-2.diff

File symlinked_plugins-2.diff, 2.3 KB (added by MikeSchinkel, 12 years ago)

2nd attempt at patch to enable plugin_url() to support symlinked plugins.

  • public_html/wp-includes/plugin.php

    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
     
    563563 * @uses WP_PLUGIN_DIR
    564564 */
    565565function plugin_basename($file) {
     566  $symlinked_plugins = get_option( 'symlinked_plugins' );
     567  if ( isset( $symlinked_plugins[$file] ) )
     568    $file = $symlinked_plugins[$file];
    566569        $file = str_replace('\\','/',$file); // sanitize for Win32 installs
    567570        $file = preg_replace('|/+|','/', $file); // remove any duplicate slash
    568571        $plugin_dir = str_replace('\\','/',WP_PLUGIN_DIR); // sanitize for Win32 installs
     
    787790                return $function[0].$function[1];
    788791        }
    789792}
     793
     794/**
     795 * Stores array of symlinked plugins upon update of 'active_plugins' into 'symlinked_plugins' option.
     796 *
     797 * The array stored for 'symlinked_plugins' will be in the following form assuming that $plugin_virtual_path contains
     798 * an array of full virtual plugin paths where each is in the form WP_PLUGIN_DIR . "/{plugin_slug}":
     799 *
     800 *    array(
     801 *      realpath( $plugin_virtual_path[1] ) => $plugin_virtual_path[1],
     802 *      realpath( $plugin_virtual_path[2] ) => $plugin_virtual_path[2],
     803 *      realpath( $plugin_virtual_path[3] ) => $plugin_virtual_path[3],
     804 *    );
     805 *
     806 * @package WordPress
     807 * @subpackage Plugin
     808 * @access private
     809 * @since 3.6
     810 * @link http://core.trac.wordpress.org/ticket/16953
     811 *
     812 * @param mixed $plugin_slugs The newly changed array of 'active_plugins' being saved.
     813 * @return mixed Array of full plugin filepaths where key is realpath( $virtual_path ) and value is $virtual_path.
     814 */
     815function _wp_pre_update_option_active_plugins( $plugin_slugs ) {
     816  $symlinked_plugins = array();
     817  foreach( $plugin_slugs as $plugin_slug ) {
     818    $real_path = realpath( $virtual_path = WP_PLUGIN_DIR . "/{$plugin_slug}" );
     819    if ( $real_path != $virtual_path )
     820      $symlinked_plugins[$real_path] = $virtual_path;
     821  }
     822  if ( count( $symlinked_plugins ) )
     823    update_option( 'symlinked_plugins', $symlinked_plugins );
     824  else
     825    delete_option( 'symlinked_plugins' );
     826  return $plugin_slugs;
     827}
     828add_filter( 'pre_update_option_active_plugins', '_wp_pre_update_option_active_plugins' );