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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. * @access protected
  22. * @var string
  23. */
  24. protected $taxonomy;
  25. /**
  26. * Constructor.
  27. *
  28. * @since 4.7.0
  29. * @access public
  30. *
  31. * @param string $taxonomy Taxonomy to register fields for.
  32. */
  33. public function __construct( $taxonomy ) {
  34. $this->taxonomy = $taxonomy;
  35. }
  36. /**
  37. * Retrieves the object meta type.
  38. *
  39. * @since 4.7.0
  40. * @access protected
  41. *
  42. * @return string The meta type.
  43. */
  44. protected function get_meta_type() {
  45. return 'term';
  46. }
  47. /**
  48. * Retrieves the type for register_rest_field().
  49. *
  50. * @since 4.7.0
  51. * @access public
  52. *
  53. * @return string The REST field type.
  54. */
  55. public function get_rest_field_type() {
  56. return 'post_tag' === $this->taxonomy ? 'tag' : $this->taxonomy;
  57. }
  58. }