Пример #1
0
 public function test_get_theme_template_paths()
 {
     $paths = give_get_theme_template_paths();
     $this->assertInternalType('array', $paths);
     $this->assertarrayHasKey(1, $paths);
     $this->assertarrayHasKey(10, $paths);
     $this->assertarrayHasKey(100, $paths);
     $this->assertInternalType('string', $paths[1]);
     $this->assertInternalType('string', $paths[10]);
     $this->assertInternalType('string', $paths[100]);
 }
Пример #2
0
/**
 * Retrieve the name of the highest priority template file that exists.
 *
 * Searches in the STYLESHEETPATH before TEMPLATEPATH so that themes which
 * inherit from a parent theme can just overload one file. If the template is
 * not found in either of those, it looks in the theme-compat folder last.
 *
 * Forked from bbPress
 *
 * @since 1.0
 *
 * @param string|array $template_names Template file(s) to search for, in order.
 * @param bool         $load           If true the template file will be loaded if it is found.
 * @param bool         $require_once   Whether to require_once or require. Default true.
 *                                     Has no effect if $load is false.
 *
 * @return string The template filename if one is located.
 */
function give_locate_template($template_names, $load = false, $require_once = true)
{
    // No file found yet
    $located = false;
    // Try to find a template file
    foreach ((array) $template_names as $template_name) {
        // Continue if template is empty
        if (empty($template_name)) {
            continue;
        }
        // Trim off any slashes from the template name
        $template_name = ltrim($template_name, '/');
        // try locating this template file by looping through the template paths
        foreach (give_get_theme_template_paths() as $template_path) {
            if (file_exists($template_path . $template_name)) {
                $located = $template_path . $template_name;
                break;
            }
        }
        if ($located) {
            break;
        }
    }
    if (true == $load && !empty($located)) {
        load_template($located, $require_once);
    }
    return $located;
}