WPSEO_Statistics

Class that generates interesting statistics about things.

Defined (1)

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

/inc/class-wpseo-statistics.php  
  1. class WPSEO_Statistics { 
  2.  
  3. /** 
  4. * Returns the post count for a certain SEO rank 
  5. * @todo Merge/DRY this with the logic virtually the same in WPSEO_Metabox::column_sort_orderby() 
  6. * @param WPSEO_Rank $rank The SEO rank to get the post count for. 
  7. * @return int 
  8. */ 
  9. public function get_post_count( $rank ) { 
  10. if ( WPSEO_Rank::NO_FOCUS === $rank->get_rank() ) { 
  11. $posts = array( 
  12. 'meta_query' => array( 
  13. 'relation' => 'OR',  
  14. array( 
  15. 'key' => WPSEO_Meta::$meta_prefix . 'focuskw',  
  16. 'value' => 'needs-a-value-anyway',  
  17. 'compare' => 'NOT EXISTS',  
  18. ),  
  19. ); 
  20. elseif ( WPSEO_Rank::NO_INDEX === $rank->get_rank() ) { 
  21. $posts = array( 
  22. 'meta_key' => WPSEO_Meta::$meta_prefix . 'meta-robots-noindex',  
  23. 'meta_value' => '1',  
  24. 'compare' => '=',  
  25. ); 
  26. else { 
  27. $posts = array( 
  28. 'meta_key' => WPSEO_Meta::$meta_prefix . 'linkdex',  
  29. 'meta_value' => array( $rank->get_starting_score(), $rank->get_end_score() ),  
  30. 'meta_compare' => 'BETWEEN',  
  31. 'meta_type' => 'NUMERIC',  
  32. ); 
  33.  
  34. $posts['fields'] = 'ids'; 
  35. $posts['post_status'] = 'publish'; 
  36.  
  37. if ( current_user_can( 'edit_others_posts' ) === false ) { 
  38. $posts['author'] = get_current_user_id(); 
  39.  
  40. $posts = new WP_Query( $posts ); 
  41.  
  42. return $posts->found_posts; 
  43.  
  44. /********************** DEPRECATED METHODS **********************/ 
  45.  
  46. // @codeCoverageIgnoreStart 
  47. /** 
  48. * Returns the amount of posts that have no focus keyword 
  49. * @deprecated 3.0 
  50. * @return int 
  51. */ 
  52. public function get_no_focus_post_count() { 
  53. _deprecated_function( __METHOD__, 'WPSEO 3.0', 'WPSEO_Statistics::get_post_count' ); 
  54.  
  55. return $this->get_post_count( new WPSEO_Rank( WPSEO_Rank::NO_FOCUS ) ); 
  56.  
  57. /** 
  58. * Returns the amount of posts that have a bad SEO ranking 
  59. * @deprecated 3.0 
  60. * @return int 
  61. */ 
  62. public function get_bad_seo_post_count() { 
  63. _deprecated_function( __METHOD__, 'WPSEO 3.0', 'WPSEO_Statistics::get_post_count' ); 
  64.  
  65. return $this->get_post_count( new WPSEO_Rank( WPSEO_Rank::BAD ) ); 
  66.  
  67. /** 
  68. * Returns the amount of posts that have a poor SEO ranking 
  69. * @deprecated 3.0 
  70. * @return int 
  71. */ 
  72. public function get_poor_seo_post_count() { 
  73. _deprecated_function( __METHOD__, 'WPSEO 3.0', 'WPSEO_Statistics::get_post_count' ); 
  74.  
  75. return $this->get_post_count( new WPSEO_Rank( 'poor' ) ); 
  76.  
  77. /** 
  78. * Returns the amount of posts that have an ok SEO ranking 
  79. * @deprecated 3.0 
  80. * @return int 
  81. */ 
  82. public function get_ok_seo_post_count() { 
  83. _deprecated_function( __METHOD__, 'WPSEO 3.0', 'WPSEO_Statistics::get_post_count' ); 
  84.  
  85. return $this->get_post_count( new WPSEO_Rank( WPSEO_Rank::OK ) ); 
  86.  
  87. /** 
  88. * Returns the amount of posts that have a good SEO ranking 
  89. * @deprecated 3.0 
  90. * @return int 
  91. */ 
  92. public function get_good_seo_post_count() { 
  93. _deprecated_function( __METHOD__, 'WPSEO 3.0', 'WPSEO_Statistics::get_post_count' ); 
  94.  
  95. return $this->get_post_count( new WPSEO_Rank( WPSEO_Rank::GOOD ) ); 
  96.  
  97. /** 
  98. * Returns the amount of posts that have no SEO ranking 
  99. * @deprecated 3.0 
  100. * @return int 
  101. */ 
  102. public function get_no_index_post_count() { 
  103. _deprecated_function( __METHOD__, 'WPSEO 3.0', 'WPSEO_Statistics::get_post_count' ); 
  104.  
  105. return $this->get_post_count( new WPSEO_Rank( WPSEO_Rank::NO_INDEX ) ); 
  106. // @codeCoverageIgnoreEnd