Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function custom_links() {
- $links = array(
- 'stat-1',
- 'stat-2',
- 'stat-3',
- 'stat-4',
- 'stat-5',
- 'stat-6',
- 'stat-7',
- 'graph-1',
- 'graph-2',
- 'graph-3',
- 'graph-4',
- 'download-stat'
- );
- return $links;
- }
- function create_custom_rewrite_rules() {
- add_rewrite_rule('player/?', 'index.php?player=$matches[1]', 'top');
- $links = custom_links();
- foreach( $links as $link ) {
- add_rewrite_rule( $link . '/?', 'index.php?'.$link.'=$matches[1]', 'top');
- }
- }
- add_action('admin_init', 'create_custom_rewrite_rules');
- function handle_custom_query_vars($query_vars) {
- $query_vars[] = 'player';
- $links = custom_links();
- foreach( $links as $link ) {
- $query_vars[] = $link;
- }
- return $query_vars;
- }
- add_filter('query_vars', 'handle_custom_query_vars');
- // redirect
- function custom_redirect($template) {
- global $wp_query;
- if (isset($wp_query->query_vars['player'])) {
- return get_template_part('stats/player');
- }
- $links = custom_links();
- if( 1 == 0 ) {
- // like WHERE 1 == 1
- }
- foreach( $links as $link ) {
- if(isset($wp_query->query_vars[$link])) {
- return get_template_part('stats/'.$link);
- }
- }
- return $template;
- }
- add_filter('template_include', 'custom_redirect', 1, 1);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement