bb_get_common_paths

The BuddyPress bb get common paths function.

Description

bb_get_common_paths( (constant) $path1 = false, (constant) $path2 = false ); 

Parameters (2)

0. $path1 — Optional. (constant) => false
The path1.
1. $path2 — Optional. (constant) => false
The path2.

Usage

  1. if ( !function_exists( 'bb_get_common_paths' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-forums/bbpress/bb-includes/functions.bb-core.php'; 
  3.  
  4. // The path1. 
  5. $path1 = false; 
  6.  
  7. // The path2. 
  8. $path2 = false; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = bb_get_common_paths($path1, $path2); 
  12.  

Defined (1)

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

/bp-forums/bbpress/bb-includes/functions.bb-core.php  
  1. function bb_get_common_paths($path1 = false, $path2 = false) { 
  2. if (!$path1 || !$path2) { 
  3. return false; 
  4.  
  5. $path1 = preg_replace('@^https?://[^/]+(.*)$@i', '$1', $path1); 
  6. $path2 = preg_replace('@^https?://[^/]+(.*)$@i', '$1', $path2); 
  7.  
  8. if ($path1 === $path2) { 
  9. return $path1; 
  10.  
  11. $path1 = trim( $path1, '/' ); 
  12. $path2 = trim( $path2, '/' ); 
  13.  
  14. $common_path = bb_get_common_parts( $path1, $path2, '/' ); 
  15.  
  16. if ($common_path) { 
  17. return '/' . $common_path . '/'; 
  18. } else { 
  19. return '/';