ap_get_theme_location( string $file, mixed $plugin = false )

Description #

Get location to a file. First file is being searched in child theme and then active theme and last fall back to AnsPress theme directory.

Parameters #

  • $file
    string (Required) file name.
  • $plugin
    mixed (Optional) Plugin path. File is search inside AnsPress extension. Default value: false

Changelog #

VersionDescription
2.4.7Added filter ap_get_theme_location
0.1Introduced.

Source #

File: includes/functions.php

function ap_get_theme_location( $file, $plugin = false ) {
	$child_path  = get_stylesheet_directory() . '/anspress/' . $file;
	$parent_path = get_template_directory() . '/anspress/' . $file;

	// Checks if the file exists in the theme first,
	// Otherwise serve the file from the plugin.
	if ( file_exists( $child_path ) ) {
		$template_path = $child_path;
	} elseif ( file_exists( $parent_path ) ) {
		$template_path = $parent_path;
	} elseif ( false !== $plugin ) {
		$template_path = $plugin . '/templates/' . $file;
	} else {
		$template_path = ANSPRESS_THEME_DIR . '/' . $file;
	}

	/**
	 * Filter AnsPress template file.
	 *
	 * @param string $template_path Path to template file.
	 * @since 2.4.7
	 */
	return apply_filters( 'ap_get_theme_location', $template_path );
}

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Add your comment