/**
 * Locate a template and return the path for inclusion.
 *
 * This is the load order:
 *
 *		yourtheme		/	$template_path	/	$template_name
 *		yourtheme		/	$template_name
 *		$default_path	/	$template_name
 * 
 * @package Social Deals Engine
 * @since 1.0.0
 * 
 */
function wps_deals_locate_template($template_name, $template_path = '', $default_path = '')
{
    if (!$template_path) {
        $template_path = WPS_DEALS_BASENAME . '/';
    }
    //wps_deals_get_templates_dir();
    if (!$default_path) {
        $default_path = wps_deals_get_templates_dir();
    }
    // Look within passed path within the theme - this is priority
    $template = locate_template(array(trailingslashit($template_path) . $template_name, $template_name));
    // Get default template
    if (!$template) {
        $template = $default_path . $template_name;
    }
    // Return what we found
    return apply_filters('wps_deals_locate_template', $template, $template_name, $template_path);
}
 /**
  * Load Page Template
  * 
  * Handles to load page template for deals pages
  * 
  * @package Social Deals Engine
  * @since 1.0.0
  * 
  */
 public function wps_deals_load_template($template)
 {
     global $wps_deals_options;
     $find = array('deals-engine.php');
     $file = '';
     $is_archive_page = is_post_type_archive(WPS_DEALS_POST_TYPE) || is_tax(WPS_DEALS_POST_TAXONOMY) || is_tax(WPS_DEALS_POST_TAGS);
     //apply filter to check archive page
     $is_archive_page = apply_filters('wps_deals_is_archive_page', $is_archive_page);
     if (is_single() && get_post_type() == WPS_DEALS_POST_TYPE) {
         $file = 'deals-single.php';
         $find[] = $file;
         $find[] = 'deals-engine/' . $file;
     } elseif ($is_archive_page) {
         $file = 'deals-archive.php';
         $find[] = $file;
         $find[] = 'deals-engine/' . $file;
     }
     if ($file) {
         $template = locate_template($find);
         if (!$template) {
             $template = wps_deals_get_templates_dir() . $file;
         }
     }
     return $template;
 }