Advertisement
Guest User

Untitled

a guest
Jul 24th, 2014
232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.26 KB | None | 0 0
  1. <?php
  2.  
  3. function custom_links() {
  4.     $links = array(
  5.        'stat-1',
  6.        'stat-2',
  7.        'stat-3',
  8.        'stat-4',
  9.        'stat-5',
  10.        'stat-6',
  11.        'stat-7',
  12.        'graph-1',
  13.        'graph-2',
  14.        'graph-3',
  15.        'graph-4',
  16.        'download-stat'
  17.     );
  18.     return $links;
  19. }
  20.  
  21. function create_custom_rewrite_rules() {
  22.     add_rewrite_rule('player/?', 'index.php?player=$matches[1]', 'top');
  23.     $links = custom_links();
  24.     foreach( $links as $link ) {
  25.         add_rewrite_rule( $link . '/?', 'index.php?'.$link.'=$matches[1]', 'top');     
  26.     }
  27. }
  28. add_action('admin_init', 'create_custom_rewrite_rules');
  29. function handle_custom_query_vars($query_vars) {
  30.     $query_vars[] = 'player';
  31.     $links = custom_links();
  32.     foreach( $links as $link ) {
  33.         $query_vars[] = $link; 
  34.     }
  35.     return $query_vars;
  36. }
  37. add_filter('query_vars', 'handle_custom_query_vars');
  38. // redirect
  39. function custom_redirect($template) {
  40.     global $wp_query;
  41.     if (isset($wp_query->query_vars['player'])) {
  42.         return get_template_part('stats/player');
  43.     }
  44.     $links = custom_links();
  45.     if( 1 == 0 ) {
  46.         // like WHERE 1 == 1
  47.     }
  48.     foreach( $links as $link ) {
  49.         if(isset($wp_query->query_vars[$link])) {
  50.             return get_template_part('stats/'.$link);
  51.         }
  52.     }
  53.     return $template;
  54. }
  55. add_filter('template_include', 'custom_redirect', 1, 1);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement