Created
June 17, 2015 10:41
-
-
Save prionkor/ef2e6b24d8d5561b4ad7 to your computer and use it in GitHub Desktop.
Rewrites.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// rewrites | |
add_action( 'wp_loaded', 'kcs_internal_rewrites' ); | |
function kcs_internal_rewrites(){ | |
$tokens = kcs_get_tokens(); // array('foo', 'bar') etc | |
foreach($tokens as $token){ | |
add_rewrite_rule("$token", "index.php?$token=1", 'top'); | |
add_rewrite_rule("([^/]*)/$token", 'index.php?pagename=$matches[1]&'. $token .'=1', 'top'); | |
add_rewrite_rule("([^/]*)/([^/]*)/$token", 'index.php?pagename=$matches[1]/$matches[2]&'. $token .'=1', 'top'); | |
add_rewrite_rule("([^/]*)/([^/]*)/([^/]*)/$token", 'index.php?pagename=$matches[1]/$matches[2]/$matches[3]&'. $token .'=1', 'top'); | |
} | |
} | |
add_filter( 'query_vars', 'kcs_internal_query_vars' ); | |
function kcs_internal_query_vars( $query_vars ){ | |
$tokens = kcs_get_tokens(); | |
$query_vars = array_merge($query_vars, $tokens); | |
return $query_vars; | |
} | |
add_action( 'parse_request', 'kcs_internal_rewrites_parse_request' ); | |
function kcs_internal_rewrites_parse_request( &$wp ){ | |
$tokens = kcs_get_tokens(); | |
foreach($tokens as $token){ | |
if (!array_key_exists( $token, $wp->query_vars ) ) { | |
continue; | |
} | |
// process | |
return; | |
} | |
// other codes removed | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment