本文整理汇总了PHP中EEH_Template::_find_common_base_path方法的典型用法代码示例。如果您正苦于以下问题:PHP EEH_Template::_find_common_base_path方法的具体用法?PHP EEH_Template::_find_common_base_path怎么用?PHP EEH_Template::_find_common_base_path使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类EEH_Template
的用法示例。
在下文中一共展示了EEH_Template::_find_common_base_path方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: locate_template
/**
* locate_template
*
* locate a template file by looking in the following places, in the following order:
* <server path up to>/wp-content/themes/<current active WordPress theme>/
* <assumed full absolute server path>
* <server path up to>/wp-content/uploads/espresso/templates/<current EE theme>/
* <server path up to>/wp-content/uploads/espresso/templates/
* <server path up to>/wp-content/plugins/<EE4 folder>/public/<current EE theme>/
* <server path up to>/wp-content/plugins/<EE4 folder>/core/templates/<current EE theme>/
* <server path up to>/wp-content/plugins/<EE4 folder>/
* as soon as the template is found in one of these locations, it will be returned or loaded
*
* Example:
* You are using the WordPress Twenty Sixteen theme,
* and you want to customize the "some-event.template.php" template,
* which is located in the "/relative/path/to/" folder relative to the main EE plugin folder.
* Assuming WP is installed on your server in the "/home/public_html/" folder,
* EEH_Template::locate_template() will look at the following paths in order until the template is found:
*
* /home/public_html/wp-content/themes/twentysixteen/some-event.template.php
* /relative/path/to/some-event.template.php
* /home/public_html/wp-content/uploads/espresso/templates/Espresso_Arabica_2014/relative/path/to/some-event.template.php
* /home/public_html/wp-content/uploads/espresso/templates/relative/path/to/some-event.template.php
* /home/public_html/wp-content/plugins/event-espresso-core-reg/public/Espresso_Arabica_2014/relative/path/to/some-event.template.php
* /home/public_html/wp-content/plugins/event-espresso-core-reg/core/templates/Espresso_Arabica_2014/relative/path/to/some-event.template.php
* /home/public_html/wp-content/plugins/event-espresso-core-reg/relative/path/to/some-event.template.php
*
* Had you passed an absolute path to your template that was in some other location,
* ie: "/absolute/path/to/some-event.template.php"
* then the search would have been :
*
* /home/public_html/wp-content/themes/twentysixteen/some-event.template.php
* /absolute/path/to/some-event.template.php
*
* and stopped there upon finding it in the second location
*
* @param array|string $templates array of template file names including extension (or just a single string)
* @param array $template_args an array of arguments to be extracted for use in the template
* @param boolean $load whether to pass the located template path on to the EEH_Template::display_template() method or simply return it
* @param boolean $return_string whether to send output immediately to screen, or capture and return as a string
* @param boolean $check_if_custom If TRUE, this flags this method to return boolean for whether this will generate a custom template or not.
* Used in places where you don't actually load the template, you just want to know if there's a custom version of it.
* @return mixed
*/
public static function locate_template($templates = array(), $template_args = array(), $load = TRUE, $return_string = TRUE, $check_if_custom = FALSE)
{
// first use WP locate_template to check for template in the current theme folder
$template_path = locate_template($templates);
if ($check_if_custom && !empty($template_path)) {
return TRUE;
}
// not in the theme
if (empty($template_path)) {
// not even a template to look for ?
if (empty($templates)) {
// get post_type
$post_type = EE_Registry::instance()->REQ->get('post_type');
// get array of EE Custom Post Types
$EE_CPTs = EE_Register_CPTs::get_CPTs();
// build template name based on request
if (isset($EE_CPTs[$post_type])) {
$archive_or_single = is_archive() ? 'archive' : '';
$archive_or_single = is_single() ? 'single' : $archive_or_single;
$templates = $archive_or_single . '-' . $post_type . '.php';
}
}
// currently active EE template theme
$current_theme = EE_Config::get_current_theme();
// array of paths to folders that may contain templates
$template_folder_paths = array(EVENT_ESPRESSO_TEMPLATE_DIR . $current_theme, EVENT_ESPRESSO_TEMPLATE_DIR);
//add core plugin folders for checking only if we're not $check_if_custom
if (!$check_if_custom) {
$core_paths = array(EE_PUBLIC . $current_theme, EE_TEMPLATES . $current_theme, EE_PLUGIN_DIR_PATH);
$template_folder_paths = array_merge($template_folder_paths, $core_paths);
}
// now filter that array
$template_folder_paths = apply_filters('FHEE__EEH_Template__locate_template__template_folder_paths', $template_folder_paths);
$templates = is_array($templates) ? $templates : array($templates);
$template_folder_paths = is_array($template_folder_paths) ? $template_folder_paths : array($template_folder_paths);
// array to hold all possible template paths
$full_template_paths = array();
EE_Registry::instance()->load_helper('File');
// loop through $templates
foreach ($templates as $template) {
// normalize directory separators
$template = EEH_File::standardise_directory_separators($template);
$file_name = basename($template);
$template_path_minus_file_name = substr($template, 0, strlen($file_name) * -1);
// while looping through all template folder paths
foreach ($template_folder_paths as $template_folder_path) {
// normalize directory separators
$template_folder_path = EEH_File::standardise_directory_separators($template_folder_path);
// determine if any common base path exists between the two paths
$common_base_path = EEH_Template::_find_common_base_path(array($template_folder_path, $template_path_minus_file_name));
if ($common_base_path !== '') {
// both paths have a common base, so just tack the filename onto our search path
$resolved_path = EEH_File::end_with_directory_separator($template_folder_path) . $file_name;
} else {
// no common base path, so let's just concatenate
//.........这里部分代码省略.........