ldc-sbv/wp-content/plugins/wordpress-seo/inc/class-wpseo-statistics.php

63 lines
1.4 KiB
PHP
Raw Normal View History

2021-09-21 15:01:08 +02:00
<?php
/**
* WPSEO plugin file.
*
* @package WPSEO\Internals
*/
/**
2021-09-21 15:05:30 +02:00
* Class that generates interesting statistics about things.
2021-09-21 15:01:08 +02:00
*/
class WPSEO_Statistics {
/**
2021-09-21 15:05:30 +02:00
* Returns the post count for a certain SEO rank.
2021-09-21 15:01:08 +02:00
*
2021-09-21 15:05:30 +02:00
* @todo Merge/DRY this with the logic virtually the same in WPSEO_Metabox::column_sort_orderby().
2021-09-21 15:01:08 +02:00
*
* @param WPSEO_Rank $rank The SEO rank to get the post count for.
*
* @return int
*/
public function get_post_count( $rank ) {
2021-09-21 15:05:30 +02:00
if ( $rank->get_rank() === WPSEO_Rank::NO_FOCUS ) {
$posts = [
'meta_query' => [
2021-09-21 15:01:08 +02:00
'relation' => 'OR',
2021-09-21 15:05:30 +02:00
[
2021-09-21 15:01:08 +02:00
'key' => WPSEO_Meta::$meta_prefix . 'focuskw',
'value' => 'needs-a-value-anyway',
'compare' => 'NOT EXISTS',
2021-09-21 15:05:30 +02:00
],
],
];
2021-09-21 15:01:08 +02:00
}
2021-09-21 15:05:30 +02:00
elseif ( $rank->get_rank() === WPSEO_Rank::NO_INDEX ) {
$posts = [
2021-09-21 15:01:08 +02:00
'meta_key' => WPSEO_Meta::$meta_prefix . 'meta-robots-noindex',
'meta_value' => '1',
'compare' => '=',
2021-09-21 15:05:30 +02:00
];
2021-09-21 15:01:08 +02:00
}
else {
2021-09-21 15:05:30 +02:00
$posts = [
2021-09-21 15:01:08 +02:00
'meta_key' => WPSEO_Meta::$meta_prefix . 'linkdex',
2021-09-21 15:05:30 +02:00
'meta_value' => [ $rank->get_starting_score(), $rank->get_end_score() ],
2021-09-21 15:01:08 +02:00
'meta_compare' => 'BETWEEN',
'meta_type' => 'NUMERIC',
2021-09-21 15:05:30 +02:00
];
2021-09-21 15:01:08 +02:00
}
$posts['fields'] = 'ids';
$posts['post_status'] = 'publish';
if ( current_user_can( 'edit_others_posts' ) === false ) {
$posts['author'] = get_current_user_id();
}
$posts = new WP_Query( $posts );
2021-09-21 15:05:30 +02:00
return (int) $posts->found_posts;
2021-09-21 15:01:08 +02:00
}
}