Created
February 9, 2012 20:13
-
-
Save jmdodd/1782766 to your computer and use it in GitHub Desktop.
Locate a template from a BuddyPress plugin template call.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Example usage: ucc_bp_locate_template( 'template/index.php', true, true, __FILE__ ). | |
if ( ! function_exists( 'ucc_bp_locate_template' ) ) { | |
function ucc_bp_locate_template( $template_names, $load = false, $require_once = true, $file = '' ) { | |
$located = ''; | |
foreach ( (array) $template_names as $template_name ) { | |
if ( ! $template_name ) | |
continue; | |
// Child theme. | |
if ( file_exists( STYLESHEETPATH . '/' . $template_name ) ) { | |
$located = STYLESHEETPATH . '/' . $template_name; | |
break; | |
// Parent theme. | |
} elseif ( file_exists( TEMPLATEPATH . '/' . $template_name ) ) { | |
$located = TEMPLATEPATH . '/' . $template_name; | |
break; | |
// Last-ditch attempts at location of calling file. | |
} elseif ( $file != '' ) { | |
$pathinfo = pathinfo( $file, PATHINFO_DIRNAME ); | |
$plugin = plugin_basename( $pathinfo ); | |
// Don't go past the calling plugin's basedir. | |
$levels = count( explode( '/', $plugin ) ) - 1; | |
for ( $level = 0; $level < $levels; $level++ ) { | |
if ( file_exists( $pathinfo . '/' . $template_name ) ) { | |
$located = $pathinfo . '/' . $template_name; | |
break; | |
} | |
$pathinfo = dirname( $pathinfo ); | |
} | |
} | |
} | |
if ( $load && '' != $located ) | |
load_template( $located, $require_once ); | |
return $located; | |
} } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment