su_shortcode_posts_locate_template

The shortcodes-ultimate su shortcode posts locate template function.

Published Date - February 15, 2021

Description

su_shortcode_posts_locate_template( $template );

Parameters

  1. $template


Usage

The following example is for adding a hook callback.

if ( !function_exists( 'su_shortcode_posts_locate_template' ) ) {
    require_once ABSPATH . PLUGINDIR . 'shortcodes-ultimateshortcodes-ultimate/includes/shortcodes/posts.php';
}

// The input(s). 
$template = null;

// NOTICE! Understand what this does before running.
$result = su_shortcode_posts_locate_template( $template );
            

Defined

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

shortcodes-ultimate/includes/shortcodes/posts.php

function su_shortcode_posts_locate_template( $template ) {

	$template = su_set_file_extension( $template, 'php' );
	$template = ltrim( $template, '\\/' );

	$locations = apply_filters(
		'su/shortcode/posts/allowed_template_locations',
		array(
			get_stylesheet_directory(),
			get_template_directory(),
			path_join(
				su_get_plugin_path(),
				'includes/partials/shortcodes/posts'
			),
		)
	);

	foreach ( $locations as $base ) {

		$base = untrailingslashit( $base );
		$base = realpath( $base );

		$path = path_join( $base, $template );
		$path = realpath( $path );

		if ( file_exists( $path ) && strpos( $path, $base ) === 0 ) {
			return $path;
		}

	}

	return false;

}