wp_register_plugin_realpath

Register a plugin's real path.

Description

wp_register_plugin_realpath( (string) $file ); 

This is used in plugin_basename() to resolve symlinked paths.

Parameters (1)

0. $file (string)
Known path to the file.

Usage

  1. if ( !function_exists( 'wp_register_plugin_realpath' ) ) { 
  2. require_once ABSPATH . WPINC . '/plugin.php'; 
  3.  
  4. // Known path to the file. 
  5. $file = ''; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = wp_register_plugin_realpath($file); 
  9.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/plugin.php  
  1. function wp_register_plugin_realpath( $file ) { 
  2. global $wp_plugin_paths; 
  3.  
  4. // Normalize, but store as static to avoid recalculation of a constant value 
  5. static $wp_plugin_path = null, $wpmu_plugin_path = null; 
  6. if ( ! isset( $wp_plugin_path ) ) { 
  7. $wp_plugin_path = wp_normalize_path( WP_PLUGIN_DIR ); 
  8. $wpmu_plugin_path = wp_normalize_path( WPMU_PLUGIN_DIR ); 
  9.  
  10. $plugin_path = wp_normalize_path( dirname( $file ) ); 
  11. $plugin_realpath = wp_normalize_path( dirname( realpath( $file ) ) ); 
  12.  
  13. if ( $plugin_path === $wp_plugin_path || $plugin_path === $wpmu_plugin_path ) { 
  14. return false; 
  15.  
  16. if ( $plugin_path !== $plugin_realpath ) { 
  17. $wp_plugin_paths[ $plugin_path ] = $plugin_realpath; 
  18.  
  19. return true;