wpsc_render_partial()WPSCache 1.0

Renders a partial/template.

The global $current_user is made available for any rendered template.

No Hooks.

Return

null. Nothing (null).

Usage

wpsc_render_partial( $partial, $page_vars );
$partial(string) (required)
- Filename under ./partials directory, with or without .php (appended if absent).
$page_vars(array)
- Variables made available for the template.
Default: array()

wpsc_render_partial() code WPSCache 1.12.0

function wpsc_render_partial( $partial, array $page_vars = array() ) {
	if ( ! str_ends_with( $partial, '.php' ) ) {
		$partial .= '.php';
	}

	if ( strpos( $partial, 'partials/' ) !== 0 ) {
		$partial = 'partials/' . $partial;
	}

	$path = __DIR__ . '/' . $partial;
	if ( ! file_exists( $path ) ) {
		return;
	}

	foreach ( $page_vars as $key => $val ) {
		$$key = $val;
	}
	global $current_user;
	include $path;
}