コード例 #1
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.
 *
 * Taken from bbPress
 *
 * @since v1.5
 *
 * @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 rcp_locate_template($template_names, $load = false, $require_once = true)
{
    // No file found yet
    $located = false;
    $template_stack = array();
    // check child theme first
    $template_stack[] = trailingslashit(get_stylesheet_directory()) . 'rcp/';
    // check parent theme next
    $template_stack[] = trailingslashit(get_template_directory()) . 'rcp/';
    // check custom directories
    $template_stack = apply_filters('rcp_template_stack', $template_stack, $template_names);
    // check theme compatibility last
    $template_stack[] = trailingslashit(rcp_get_templates_dir());
    // 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, '/');
        // Loop through template stack.
        foreach ((array) $template_stack as $template_location) {
            // Continue if $template_location is empty.
            if (empty($template_location)) {
                continue;
            }
            // Check child theme first.
            if (file_exists(trailingslashit($template_location) . $template_name)) {
                $located = trailingslashit($template_location) . $template_name;
                break 2;
            }
        }
    }
    if (true == $load && !empty($located)) {
        load_template($located, $require_once);
    }
    return $located;
}
コード例 #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.
 *
 * Taken from bbPress
 *
 * @since v1.5
 *
 * @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 rcp_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, '/');
        // Check child theme first
        if (file_exists(trailingslashit(get_stylesheet_directory()) . 'rcp/' . $template_name)) {
            $located = trailingslashit(get_stylesheet_directory()) . 'rcp/' . $template_name;
            break;
            // Check parent theme next
        } elseif (file_exists(trailingslashit(get_template_directory()) . 'rcp/' . $template_name)) {
            $located = trailingslashit(get_template_directory()) . 'rcp/' . $template_name;
            break;
            // Check theme compatibility last
        } elseif (file_exists(trailingslashit(rcp_get_templates_dir()) . $template_name)) {
            $located = trailingslashit(rcp_get_templates_dir()) . $template_name;
            break;
        }
    }
    if (true == $load && !empty($located)) {
        load_template($located, $require_once);
    }
    return $located;
}