Make WordPress Core

Opened 8 years ago

Closed 8 years ago

#37357 closed defect (bug) (fixed)

PHPDoc for wp_register_plugin_realpath is wrong

Reported by: zuige's profile Zuige Owned by: drewapicture's profile DrewAPicture
Milestone: 4.6 Priority: normal
Severity: normal Version: 3.9
Component: Plugins Keywords:
Focuses: docs Cc:

Description

/**
 * Register a plugin's real path.
 *
 * This is used in plugin_basename() to resolve symlinked paths.
 *
 * @since 3.9.0
 *
 * @see plugin_basename()
 *
 * @global array $wp_plugin_paths
 *
 * @staticvar string $wp_plugin_path
 * @staticvar string $wpmu_plugin_path
 *
 * @param string $file Known path to the file.
 * @return bool Whether the path was able to be registered.
 */

But plugin_basename() doesn't use the method at all

function plugin_basename( $file ) { 
  global $wp_plugin_paths;

  // $wp_plugin_paths contains normalized paths.
  $file = wp_normalize_path( $file );

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

  $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); /
  $file = trim($file, '/');
  return $file;
}

Change History (2)

#1 @DrewAPicture
8 years ago

  • Focuses docs added
  • Milestone changed from Awaiting Review to 4.6

#2 @DrewAPicture
8 years ago

  • Owner set to DrewAPicture
  • Resolution set to fixed
  • Status changed from new to closed

In 38061:

Docs: Update a cross-reference in the DocBlock for wp_register_plugin_realpath() from plugin_basename() to wp_normalize_path().

Props zuige.
Fixes #37357.

Note: See TracTickets for help on using tickets.