class-wpseo-statistics.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. /**
  3. * WPSEO plugin file.
  4. *
  5. * @package WPSEO\Internals
  6. */
  7. /**
  8. * Class that generates interesting statistics about things
  9. */
  10. class WPSEO_Statistics {
  11. /**
  12. * Returns the post count for a certain SEO rank
  13. *
  14. * @todo Merge/DRY this with the logic virtually the same in WPSEO_Metabox::column_sort_orderby()
  15. *
  16. * @param WPSEO_Rank $rank The SEO rank to get the post count for.
  17. *
  18. * @return int
  19. */
  20. public function get_post_count( $rank ) {
  21. if ( WPSEO_Rank::NO_FOCUS === $rank->get_rank() ) {
  22. $posts = array(
  23. 'meta_query' => array(
  24. 'relation' => 'OR',
  25. array(
  26. 'key' => WPSEO_Meta::$meta_prefix . 'focuskw',
  27. 'value' => 'needs-a-value-anyway',
  28. 'compare' => 'NOT EXISTS',
  29. ),
  30. ),
  31. );
  32. }
  33. elseif ( WPSEO_Rank::NO_INDEX === $rank->get_rank() ) {
  34. $posts = array(
  35. 'meta_key' => WPSEO_Meta::$meta_prefix . 'meta-robots-noindex',
  36. 'meta_value' => '1',
  37. 'compare' => '=',
  38. );
  39. }
  40. else {
  41. $posts = array(
  42. 'meta_key' => WPSEO_Meta::$meta_prefix . 'linkdex',
  43. 'meta_value' => array( $rank->get_starting_score(), $rank->get_end_score() ),
  44. 'meta_compare' => 'BETWEEN',
  45. 'meta_type' => 'NUMERIC',
  46. );
  47. }
  48. $posts['fields'] = 'ids';
  49. $posts['post_status'] = 'publish';
  50. if ( current_user_can( 'edit_others_posts' ) === false ) {
  51. $posts['author'] = get_current_user_id();
  52. }
  53. $posts = new WP_Query( $posts );
  54. return $posts->found_posts;
  55. }
  56. }