WPSEO_Recalculate_Terms

This class handles the calculation of the SEO score for all terms.

Defined (1)

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

/admin/recalculate/class-recalculate-terms.php  
  1. class WPSEO_Recalculate_Terms extends WPSEO_Recalculate { 
  2.  
  3. /** 
  4. * Save the scores. 
  5. * @param array $scores The scores to save. 
  6. */ 
  7. public function save_scores( array $scores ) { 
  8.  
  9. $tax_meta = get_option( 'wpseo_taxonomy_meta' ); 
  10.  
  11. foreach ( $scores as $score ) { 
  12. $tax_meta[ $score['taxonomy'] ][ $score['item_id'] ]['wpseo_linkdex'] = $score['score']; 
  13.  
  14. update_option( 'wpseo_taxonomy_meta', $tax_meta ); 
  15.  
  16. /** 
  17. * Save the score. 
  18. * @param array $score The score to save. 
  19. */ 
  20. protected function save_score( array $score ) { 
  21. WPSEO_Meta::set_value( 'linkdex', $score['score'], $score['item_id'] ); 
  22.  
  23. /** 
  24. * Get the terms from the database by doing a WP_Query. 
  25. * @param integer $paged The page. 
  26. * @return array 
  27. */ 
  28. protected function get_items( $paged ) { 
  29. $items_per_page = max( 1, $this->items_per_page ); 
  30.  
  31. return get_terms( 
  32. get_taxonomies(),  
  33. array( 
  34. 'hide_empty' => false,  
  35. 'number' => $items_per_page,  
  36. 'offset' => $items_per_page * abs( $paged - 1 ),  
  37. ); 
  38.  
  39. /** 
  40. * Convert the given term into a analyzable object. 
  41. * @param mixed $item The term for which to build the analyzer data. 
  42. * @return array 
  43. */ 
  44. protected function item_to_response( $item ) { 
  45. $focus_keyword = $this->get_focus_keyword( $item ); 
  46. $title = str_replace( ' %%page%% ', ' ', $this->get_title( $item ) ); 
  47. $meta = $this->get_meta_description( $item ); 
  48.  
  49. $description = $item->description; 
  50.  
  51. /** 
  52. * Filter the term description for recalculation. 
  53. * @param string $description Content of the term. Modify to reflect front-end content. 
  54. * @oaram WP_Term $item The term the description comes from. 
  55. */ 
  56. $description = apply_filters( 'wpseo_term_description_for_recalculation', $description, $item ); 
  57.  
  58. return array( 
  59. 'term_id' => $item->term_id,  
  60. 'taxonomy' => $item->taxonomy,  
  61. 'text' => $description,  
  62. 'keyword' => $focus_keyword,  
  63. 'url' => urldecode( $item->slug ),  
  64. 'pageTitle' => apply_filters( 'wpseo_title', wpseo_replace_vars( $title, $item, array( 'page' ) ) ),  
  65. 'meta' => apply_filters( 'wpseo_metadesc', wpseo_replace_vars( $meta, $item ) ),  
  66. 'keyword_usage' => array( 
  67. $focus_keyword => WPSEO_Taxonomy_Meta::get_keyword_usage( $focus_keyword, $item->term_id, $item->taxonomy ),  
  68. ),  
  69. ); 
  70.  
  71. /** 
  72. * Gets the focus keyword for the term 
  73. * @param stdClass|WP_Term $term Term to determine the keyword for. 
  74. * @return bool|string 
  75. */ 
  76. private function get_focus_keyword( $term ) { 
  77. $focus_keyword = WPSEO_Taxonomy_Meta::get_term_meta( 'focuskw', $term->term_id, $term->taxonomy ); 
  78. if ( ! empty( $focus_keyword ) ) { 
  79. return $focus_keyword; 
  80.  
  81. return $term->name; 
  82.  
  83. /** 
  84. * Get the title for given term 
  85. * @param stdClass|WP_Term $term The term object. 
  86. * @return mixed|string 
  87. */ 
  88. private function get_title( $term ) { 
  89. $title = WPSEO_Taxonomy_Meta::get_term_meta( $term->term_id, $term->taxonomy, 'title' ); 
  90. if ( '' !== $title ) { 
  91. return $title; 
  92.  
  93. $default_from_options = $this->default_from_options( 'title-tax', $term->taxonomy ); 
  94. if ( false !== $default_from_options ) { 
  95. return $default_from_options; 
  96.  
  97. return '%%title%%'; 
  98.  
  99. /** 
  100. * Get the meta description for given post 
  101. * @param stdClass|WP_Term $term The term object. 
  102. * @return bool|string 
  103. */ 
  104. private function get_meta_description( $term ) { 
  105. $meta_description = WPSEO_Taxonomy_Meta::get_term_meta( $term->term_id, $term->taxonomy, 'desc' ); 
  106. if ( '' !== $meta_description ) { 
  107. return $meta_description; 
  108.  
  109. $default_from_options = $this->default_from_options( 'metadesc-tax', $term->taxonomy ); 
  110. if ( false !== $default_from_options ) { 
  111. return $default_from_options; 
  112.  
  113. return '';