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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. * @access protected
  22. * @var string
  23. */
  24. protected $post_type;
  25. /**
  26. * Constructor.
  27. *
  28. * @since 4.7.0
  29. * @access public
  30. *
  31. * @param string $post_type Post type to register fields for.
  32. */
  33. public function __construct( $post_type ) {
  34. $this->post_type = $post_type;
  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 'post';
  46. }
  47. /**
  48. * Retrieves the type for register_rest_field().
  49. *
  50. * @since 4.7.0
  51. * @access public
  52. *
  53. * @see register_rest_field()
  54. *
  55. * @return string The REST field type.
  56. */
  57. public function get_rest_field_type() {
  58. return $this->post_type;
  59. }
  60. }