class-wp-rest-term-meta-fields.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. /**
  3. * REST API: WP_REST_Term_Meta_Fields class
  4. *
  5. * @package WordPress
  6. * @subpackage REST_API
  7. * @since 4.7.0
  8. */
  9. /**
  10. * Core class used to manage meta values for terms via the REST API.
  11. *
  12. * @since 4.7.0
  13. *
  14. * @see WP_REST_Meta_Fields
  15. */
  16. class WP_REST_Term_Meta_Fields extends WP_REST_Meta_Fields {
  17. /**
  18. * Taxonomy to register fields for.
  19. *
  20. * @since 4.7.0
  21. * @var string
  22. */
  23. protected $taxonomy;
  24. /**
  25. * Constructor.
  26. *
  27. * @since 4.7.0
  28. *
  29. * @param string $taxonomy Taxonomy to register fields for.
  30. */
  31. public function __construct( $taxonomy ) {
  32. $this->taxonomy = $taxonomy;
  33. }
  34. /**
  35. * Retrieves the term meta type.
  36. *
  37. * @since 4.7.0
  38. *
  39. * @return string The meta type.
  40. */
  41. protected function get_meta_type() {
  42. return 'term';
  43. }
  44. /**
  45. * Retrieves the term meta subtype.
  46. *
  47. * @since 4.9.8
  48. *
  49. * @return string Subtype for the meta type, or empty string if no specific subtype.
  50. */
  51. protected function get_meta_subtype() {
  52. return $this->taxonomy;
  53. }
  54. /**
  55. * Retrieves the type for register_rest_field().
  56. *
  57. * @since 4.7.0
  58. *
  59. * @return string The REST field type.
  60. */
  61. public function get_rest_field_type() {
  62. return 'post_tag' === $this->taxonomy ? 'tag' : $this->taxonomy;
  63. }
  64. }