$score['count'] / $total );
}
return $division;
}
/**
* Get all SEO ranks and data associated with them.
*
* @return array An array of SEO scores and associated data.
*/
private function get_seo_scores_with_post_count() {
$ranks = WPSEO_Rank::get_all_ranks();
return array_map( [ $this, 'map_rank_to_widget' ], $ranks );
}
/**
* Converts a rank to data usable in the dashboard widget.
*
* @param WPSEO_Rank $rank The rank to map.
*
* @return array The mapped rank.
*/
private function map_rank_to_widget( WPSEO_Rank $rank ) {
return [
'seo_rank' => $rank->get_rank(),
'label' => $this->get_label_for_rank( $rank ),
'count' => $this->statistics->get_post_count( $rank ),
'link' => $this->get_link_for_rank( $rank ),
];
}
/**
* Returns a dashboard widget label to use for a certain rank.
*
* @param WPSEO_Rank $rank The rank to return a label for.
*
* @return string The label for the rank.
*/
private function get_label_for_rank( WPSEO_Rank $rank ) {
return $this->labels[ $rank->get_rank() ];
}
/**
* Determines the labels for the various scoring ranks that are known within Yoast SEO.
*
* @return array Array containing the translatable labels.
*/
private function labels() {
return [
WPSEO_Rank::NO_FOCUS => sprintf(
/* translators: %1$s expands to an opening strong tag, %2$s expands to a closing strong tag */
__( 'Posts %1$swithout%2$s a focus keyphrase', 'wordpress-seo' ),
'',
''
),
WPSEO_Rank::BAD => sprintf(
/* translators: %s expands to the score */
__( 'Posts with the SEO score: %s', 'wordpress-seo' ),
'' . __( 'Needs improvement', 'wordpress-seo' ) . ''
),
WPSEO_Rank::OK => sprintf(
/* translators: %s expands to the score */
__( 'Posts with the SEO score: %s', 'wordpress-seo' ),
'' . __( 'OK', 'wordpress-seo' ) . ''
),
WPSEO_Rank::GOOD => sprintf(
/* translators: %s expands to the score */
__( 'Posts with the SEO score: %s', 'wordpress-seo' ),
'' . __( 'Good', 'wordpress-seo' ) . ''
),
WPSEO_Rank::NO_INDEX => __( 'Posts that should not show up in search results', 'wordpress-seo' ),
];
}
/**
* Filter items if they have a count of zero.
*
* @param array $item The item to potentially filter out.
*
* @return bool Whether or not the count is zero.
*/
private function filter_items( $item ) {
return $item['count'] !== 0;
}
/**
* Returns a link for the overview of posts of a certain rank.
*
* @param WPSEO_Rank $rank The rank to return a link for.
*
* @return string The link that shows an overview of posts with that rank.
*/
private function get_link_for_rank( WPSEO_Rank $rank ) {
if ( current_user_can( 'edit_others_posts' ) === false ) {
return esc_url( admin_url( 'edit.php?post_status=publish&post_type=post&seo_filter=' . $rank->get_rank() . '&author=' . get_current_user_id() ) );
}
return esc_url( admin_url( 'edit.php?post_status=publish&post_type=post&seo_filter=' . $rank->get_rank() ) );
}
}