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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. /**
  3. * REST API: WP_REST_Post_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 posts via the REST API.
  11. *
  12. * @since 4.7.0
  13. *
  14. * @see WP_REST_Meta_Fields
  15. */
  16. class WP_REST_Post_Meta_Fields extends WP_REST_Meta_Fields {
  17. /**
  18. * Post type to register fields for.
  19. *
  20. * @since 4.7.0
  21. * @var string
  22. */
  23. protected $post_type;
  24. /**
  25. * Constructor.
  26. *
  27. * @since 4.7.0
  28. *
  29. * @param string $post_type Post type to register fields for.
  30. */
  31. public function __construct( $post_type ) {
  32. $this->post_type = $post_type;
  33. }
  34. /**
  35. * Retrieves the post meta type.
  36. *
  37. * @since 4.7.0
  38. *
  39. * @return string The meta type.
  40. */
  41. protected function get_meta_type() {
  42. return 'post';
  43. }
  44. /**
  45. * Retrieves the post 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->post_type;
  53. }
  54. /**
  55. * Retrieves the type for register_rest_field().
  56. *
  57. * @since 4.7.0
  58. *
  59. * @see register_rest_field()
  60. *
  61. * @return string The REST field type.
  62. */
  63. public function get_rest_field_type() {
  64. return $this->post_type;
  65. }
  66. }