<?php
// CUSTOM 404 PAGE TITLE
function theme_slug_filter_wp_title($title)
{
	if (is_404()) {
		$title = __("Page not found - Homegrade", "homegrade-theme__texte-fonctionnel");
	}

	if ($title) {
		return $title;
	}
}
add_filter('wp_title', 'theme_slug_filter_wp_title');


add_action('template_redirect', 'redirect_to_demo_components_page');
function redirect_to_demo_components_page()
{
	// if ($_SERVER['REQUEST_URI'] == '/demo-components' && is_user_logged_in()) {
	if ($_SERVER['REQUEST_URI'] == '/tutorial') {
		global $wp_query;
		$wp_query->is_404 = false;
		status_header(200);
		include(dirname(__DIR__, 1) . '/demo-components.php');
		exit();
	}
	if ($_SERVER['REQUEST_URI'] == '/demo-components') {
		wp_redirect('/tutorial');
		exit();
	}
	if ($_SERVER['REQUEST_URI'] == '/sitemap-progress') {
		global $wp_query;
		$wp_query->is_404 = false;
		status_header(200);
		include(dirname(__DIR__, 1) . '/sitemap-progress.php');
		exit();
	}
	if ($_SERVER['REQUEST_URI'] == '/brochures-map') {
		global $wp_query;
		$wp_query->is_404 = false;
		status_header(200);
		include(dirname(__DIR__, 1) . '/brochures-map.php');
		exit();
	}
	if ($_SERVER['REQUEST_URI'] == '/nl/brochures-map') {
		global $wp_query;
		$wp_query->is_404 = false;
		status_header(200);
		include(dirname(__DIR__, 1) . '/brochures-map.php');
		exit();
	}
}


// function wpa_course_post_link($post_link, $id = 0)
// {
// 	$post = get_post($id);
// 	if (is_object($post) && ICL_LANGUAGE_CODE == 'fr') {
// 		$terms = wp_get_object_terms($post->ID, 'thematiques');
// 		if ($terms) {
// 			return str_replace('%thematiques%', $terms[0]->slug, $post_link);
// 		}
// 	}


// 	return $post_link;
// }
// add_filter('post_type_link', 'wpa_course_post_link', 1, 3);
