fs_find_direct_caller_plugin_file

Find the plugin main file path based on any give file inside the plugin's folder.

Description

(string) fs_find_direct_caller_plugin_file( (string) $file ); 

Returns (string)

Parameters (1)

0. $file (string)
Absolute path to a file inside a plugin's folder.

Usage

  1. if ( !function_exists( 'fs_find_direct_caller_plugin_file' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'nextgen-gallery/freemius/includes/supplements/fs-essential-functions-1.1.7.1.php'; 
  3.  
  4. // Absolute path to a file inside a plugin's folder. 
  5. $file = ''; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = fs_find_direct_caller_plugin_file($file); 
  9.  

Defined (1)

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

/freemius/includes/supplements/fs-essential-functions-1.1.7.1.php  
  1. function fs_find_direct_caller_plugin_file( $file ) { 
  2. /** 
  3. * All the code below will be executed once on activation. 
  4. * If the user changes the main plugin's file name, the file_exists() 
  5. * will catch it. 
  6. */ 
  7. if ( ! function_exists( 'get_plugins' ) ) { 
  8. require_once( ABSPATH . 'wp-admin/includes/plugin.php' ); 
  9.  
  10. $all_plugins = get_plugins(); 
  11.  
  12. $file_real_path = fs_normalize_path( realpath( $file ) ); 
  13.  
  14. // Get active plugin's main files real full names (might be symlinks). 
  15. foreach ( $all_plugins as $relative_path => &$data ) { 
  16. if ( 0 === strpos( $file_real_path, fs_normalize_path( dirname( realpath( WP_PLUGIN_DIR . '/' . $relative_path ) ) ) ) ) { 
  17. if ( '.' !== dirname( trailingslashit( $relative_path ) ) ) { 
  18. return $relative_path; 
  19.  
  20. return null;