WPSEO_Term_Metabox_Formatter

This class provides data for the term metabox by return its values for localization.

Defined (1)

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

/admin/formatter/class-term-metabox-formatter.php  
  1. class WPSEO_Term_Metabox_Formatter implements WPSEO_Metabox_Formatter_Interface { 
  2.  
  3. /** 
  4. * @var WP_Term|stdClass 
  5. */ 
  6. private $term; 
  7.  
  8. /** 
  9. * @var stdClass 
  10. */ 
  11. private $taxonomy; 
  12.  
  13. /** 
  14. * @var array Array with the WPSEO_Titles options. 
  15. */ 
  16. protected $options; 
  17.  
  18. /** 
  19. * WPSEO_Taxonomy_Scraper constructor. 
  20. * @param stdClass $taxonomy Taxonomy. 
  21. * @param WP_Term|stdClass $term Term. 
  22. * @param array $options Options with WPSEO_Titles. 
  23. */ 
  24. public function __construct( $taxonomy, $term, array $options ) { 
  25. $this->term = $term; 
  26. $this->taxonomy = $taxonomy; 
  27. $this->options = $options; 
  28.  
  29. /** 
  30. * Returns the translated values. 
  31. * @return array 
  32. */ 
  33. public function get_values() { 
  34. $values = array(); 
  35.  
  36. // Todo: a column needs to be added on the termpages to add a filter for the keyword, so this can be used in the focus kw doubles. 
  37. if ( is_object( $this->term ) && property_exists( $this->term, 'taxonomy' ) ) { 
  38. $values = array( 
  39. 'search_url' => $this->search_url(),  
  40. 'post_edit_url' => $this->edit_url(),  
  41. 'base_url' => $this->base_url_for_js(),  
  42. 'taxonomy' => $this->term->taxonomy,  
  43. 'keyword_usage' => $this->get_focus_keyword_usage(),  
  44. 'title_template' => $this->get_title_template(),  
  45. 'metadesc_template' => $this->get_metadesc_template(),  
  46. ); 
  47.  
  48. return $values; 
  49.  
  50. /** 
  51. * Returns the url to search for keyword for the taxonomy 
  52. * @return string 
  53. */ 
  54. private function search_url() { 
  55. return admin_url( 'edit-tags.php?taxonomy=' . $this->term->taxonomy . '&seo_kw_filter={keyword}' ); 
  56.  
  57. /** 
  58. * Returns the url to edit the taxonomy 
  59. * @return string 
  60. */ 
  61. private function edit_url() { 
  62. global $wp_version; 
  63. $script_filename = version_compare( $wp_version, '4.5', '<' ) ? 'edit-tags' : 'term'; 
  64. return admin_url( $script_filename . '.php?action=edit&taxonomy=' . $this->term->taxonomy . '&tag_ID={id}' ); 
  65.  
  66. /** 
  67. * Returns a base URL for use in the JS, takes permalink structure into account 
  68. * @return string 
  69. */ 
  70. private function base_url_for_js() { 
  71.  
  72. $base_url = home_url( '/', null ); 
  73. $options = WPSEO_Options::get_option( 'wpseo_permalinks' ); 
  74. if ( ! $options['stripcategorybase'] ) { 
  75. $base_url = trailingslashit( $base_url . $this->taxonomy->rewrite['slug'] ); 
  76.  
  77. return $base_url; 
  78.  
  79. /** 
  80. * Counting the number of given keyword used for other term than given term_id 
  81. * @return array 
  82. */ 
  83. private function get_focus_keyword_usage() { 
  84. $focuskw = WPSEO_Taxonomy_Meta::get_term_meta( $this->term, $this->term->taxonomy, 'focuskw' ); 
  85.  
  86. return WPSEO_Taxonomy_Meta::get_keyword_usage( $focuskw, $this->term->term_id, $this->term->taxonomy ); 
  87.  
  88. /** 
  89. * Retrieves the title template. 
  90. * @return string 
  91. */ 
  92. private function get_title_template() { 
  93. return $this->get_template( 'title' ); 
  94.  
  95. /** 
  96. * Retrieves the metadesc template. 
  97. * @return string 
  98. */ 
  99. private function get_metadesc_template() { 
  100. return $this->get_template( 'metadesc' ); 
  101.  
  102. /** 
  103. * Retrieves a template. 
  104. * @param String $template_option_name The name of the option in which the template you want to get is saved. 
  105. * @return string 
  106. */ 
  107. private function get_template( $template_option_name ) { 
  108. $needed_option = $template_option_name . '-tax-' . $this->term->taxonomy; 
  109. if ( isset( $this->options[ $needed_option ] ) && $this->options[ $needed_option ] !== '' ) { 
  110. return $this->options[ $needed_option ]; 
  111.  
  112. return '';