Skip to content

Instantly share code, notes, and snippets.

@zenril
Last active August 29, 2015 14:23
Show Gist options
  • Save zenril/adcfdb7dd22ce140fd0d to your computer and use it in GitHub Desktop.
Save zenril/adcfdb7dd22ce140fd0d to your computer and use it in GitHub Desktop.
class Router {
public $routes;
function Router( $map ) {
$this->routes = $map;
add_filter( 'parse_request' , array( &$this , 'request_parser' ) );
}
function request_parser($params) {
$url = $params->request;
$pattern = '|^'.$url.'$|';
foreach($this->routes as $from => $to){
$args[$key] = $this->altArgs[$key];
preg_match($pattern, $from, $matches);
if(!empty($matches)){
wp_redirect( $to );
exit;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment