stats_template_redirect

Stats Template Redirect.

Description

stats_template_redirect(); 

Usage

  1. if ( !function_exists( 'stats_template_redirect' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'jetpack-by-wordpress-com/modules/stats.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = stats_template_redirect(); 
  7.  

Defined (1)

The function is defined in the following location(s).

/modules/stats.php  
  1. function stats_template_redirect() { 
  2. global $wp_the_query, $current_user, $stats_footer; 
  3.  
  4. if ( is_feed() || is_robots() || is_trackback() || is_preview() ) 
  5. return; 
  6.  
  7. // Should we be counting this user's views? 
  8. if ( !empty( $current_user->ID ) ) { 
  9. $count_roles = stats_get_option( 'count_roles' ); 
  10. if ( ! array_intersect( $current_user->roles, $count_roles ) ) 
  11. return; 
  12.  
  13. add_action( 'wp_footer', 'stats_footer', 101 ); 
  14.  
  15. $blog = Jetpack_Options::get_option( 'id' ); 
  16. $tz = get_option( 'gmt_offset' ); 
  17. $v = 'ext'; 
  18. $blog_url = parse_url( site_url() ); 
  19. $srv = $blog_url['host']; 
  20. $j = sprintf( '%s:%s', JETPACK__API_VERSION, JETPACK__VERSION ); 
  21. if ( $wp_the_query->is_single || $wp_the_query->is_page || $wp_the_query->is_posts_page ) { 
  22. // Store and reset the queried_object and queried_object_id 
  23. // Otherwise, redirect_canonical() will redirect to home_url( '/' ) for show_on_front = page sites where home_url() is not all lowercase. 
  24. // Repro: 
  25. // 1. Set home_url = http://ExamPle.com/ 
  26. // 2. Set show_on_front = page 
  27. // 3. Set page_on_front = something 
  28. // 4. Visit http://example.com/ 
  29.  
  30. $queried_object = ( isset( $wp_the_query->queried_object ) ) ? $wp_the_query->queried_object : null; 
  31. $queried_object_id = ( isset( $wp_the_query->queried_object_id ) ) ? $wp_the_query->queried_object_id : null; 
  32. $post = $wp_the_query->get_queried_object_id(); 
  33. $wp_the_query->queried_object = $queried_object; 
  34. $wp_the_query->queried_object_id = $queried_object_id; 
  35. } else { 
  36. $post = '0'; 
  37.  
  38. $script = set_url_scheme( '//stats.wp.com/e-' . gmdate( 'YW' ) . '.js' ); 
  39. $data = stats_array( compact( 'v', 'j', 'blog', 'post', 'tz', 'srv' ) ); 
  40.  
  41. $stats_footer = <<<END 
  42. <script type='text/javascript' src='{$script}' async defer></script> 
  43. <script type='text/javascript'> 
  44. _stq = window._stq || []; 
  45. _stq.push([ 'view', {{$data}} ]); 
  46. _stq.push([ 'clickTrackerInit', '{$blog}', '{$post}' ]); 
  47. </script> 
  48.  
  49. END;