class-taxonomy-settings-fields.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?php
  2. /**
  3. * WPSEO plugin file.
  4. *
  5. * @package WPSEO\Admin
  6. */
  7. /**
  8. * This class parses all the values for the general tab in the Yoast SEO settings metabox
  9. */
  10. class WPSEO_Taxonomy_Settings_Fields extends WPSEO_Taxonomy_Fields {
  11. /**
  12. * @var array Options array for the no-index options, including translated labels
  13. */
  14. private $no_index_options = array();
  15. /**
  16. * @param stdClass $term The currenct taxonomy.
  17. */
  18. public function __construct( $term ) {
  19. parent::__construct( $term );
  20. $this->translate_meta_options();
  21. }
  22. /**
  23. * Returns array with the fields for the General tab.
  24. *
  25. * @return array Fields to be used on the General tab.
  26. */
  27. public function get() {
  28. $labels = $this->get_taxonomy_labels();
  29. $fields = array(
  30. 'noindex' => $this->get_field_config(
  31. /* translators: %s = taxonomy name. */
  32. esc_html( sprintf( __( 'Allow search engines to show this %s in search results?', 'wordpress-seo' ), $labels->singular_name ) ),
  33. '',
  34. 'select',
  35. $this->get_noindex_options()
  36. ),
  37. 'bctitle' => $this->get_field_config(
  38. __( 'Breadcrumbs Title', 'wordpress-seo' ),
  39. esc_html__( 'The Breadcrumbs Title is used in the breadcrumbs where this taxonomy appears.', 'wordpress-seo' ),
  40. 'text',
  41. '',
  42. ( WPSEO_Options::get( 'breadcrumbs-enable' ) !== true )
  43. ),
  44. 'canonical' => $this->get_field_config(
  45. __( 'Canonical URL', 'wordpress-seo' ),
  46. esc_html__( 'The canonical link is shown on the archive page for this term.', 'wordpress-seo' )
  47. ),
  48. );
  49. return $this->filter_hidden_fields( $fields );
  50. }
  51. /**
  52. * Translate options text strings for use in the select fields
  53. *
  54. * {@internal IMPORTANT: if you want to add a new string (option) somewhere, make sure you add
  55. * that array key to the main options definition array in the class WPSEO_Taxonomy_Meta() as well!!!!}}
  56. */
  57. private function translate_meta_options() {
  58. $this->no_index_options = WPSEO_Taxonomy_Meta::$no_index_options;
  59. /* translators: %1$s expands to the taxonomy name %2$s expands to the current taxonomy index value */
  60. $this->no_index_options['default'] = __( '%2$s (current default for %1$s)', 'wordpress-seo' );
  61. $this->no_index_options['index'] = __( 'Yes', 'wordpress-seo' );
  62. $this->no_index_options['noindex'] = __( 'No', 'wordpress-seo' );
  63. }
  64. /**
  65. * Getting the data for the noindex fields
  66. *
  67. * @return array Array containing the no_index options.
  68. */
  69. private function get_noindex_options() {
  70. $labels = $this->get_taxonomy_labels();
  71. $noindex_options['options'] = $this->no_index_options;
  72. $noindex_options['options']['default'] = sprintf( $noindex_options['options']['default'], $labels->name, $this->get_robot_index() );
  73. return $noindex_options;
  74. }
  75. /**
  76. * Retrieve the taxonomies plural for use in sentences.
  77. *
  78. * @return object Object containing the taxonomy's labels.
  79. */
  80. private function get_taxonomy_labels() {
  81. $taxonomy = get_taxonomy( $this->term->taxonomy );
  82. return $taxonomy->labels;
  83. }
  84. /**
  85. * Returns the current robot index value for the taxonomy
  86. *
  87. * @return string
  88. */
  89. private function get_robot_index() {
  90. $robot_index = $this->no_index_options['index'];
  91. $index_option = 'noindex-tax-' . $this->term->taxonomy;
  92. if ( WPSEO_Options::get( $index_option, false ) ) {
  93. $robot_index = $this->no_index_options['noindex'];
  94. }
  95. return $robot_index;
  96. }
  97. }