Closed chrisvanpatten closed 5 years ago
This would also theoretically fix #4. It's not a direct function, but with this it wouldn't be hard to make one...
/**
* Check to see if the current route matches the desired route
*
* @param string $route_id
* @param \WP_Query|null $query
* @return bool
*/
function is_route( $route_id, $query = null ) {
// Get the current query if the user doesn't provide one
if ( is_null( $query ) ) {
global $wp_query;
$query = $wp_query;
}
// If the route ID matches the current route, return true
if ( \WP_Router::get_instance()->identify_route( $query ) === $route_id )
return true;
// Otherwise, return false
return false;
}
Making
identify_route
a public function makes it possible to check which route you're currently on, making template re-use a bit easier in instances where there are only minor changes between routes.For instance...
I can't think of any major security issues, but I might be missing something obvious!