WC_GZD_REST_Product_Price_Labels_Controller

Class WC_GZD_REST_Product_Price_Labels_Controller.

Defined (1)

The class is defined in the following location(s).

/includes/api/class-wc-gzd-rest-product-price-labels-controller.php  
  1. class WC_GZD_REST_Product_Price_Labels_Controller extends WC_REST_Terms_Controller { 
  2.  
  3. /** 
  4. * Endpoint namespace. 
  5. * @var string 
  6. */ 
  7. protected $namespace = 'wc/v1'; 
  8.  
  9. /** 
  10. * Route base. 
  11. * @var string 
  12. */ 
  13. protected $rest_base = 'products/price_labels'; 
  14.  
  15. /** 
  16. * Taxonomy. 
  17. * @var string 
  18. */ 
  19. protected $taxonomy = 'product_price_label'; 
  20.  
  21. /** 
  22. * Prepare a single delivery Time output for response. 
  23. * @param \WP_Term $item Term object. 
  24. * @param \WP_REST_Request $request 
  25. * @return \WP_REST_Response $response 
  26. */ 
  27. public function prepare_item_for_response( $item, $request ) { 
  28.  
  29. $data = array( 
  30. 'id' => (int) $item->term_id,  
  31. 'name' => $item->name,  
  32. 'slug' => $item->slug,  
  33. 'description' => $item->description,  
  34. 'count' => (int) $item->count,  
  35. ); 
  36.  
  37. $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; 
  38. $data = $this->add_additional_fields_to_object( $data, $request ); 
  39. $data = $this->filter_response_by_context( $data, $context ); 
  40.  
  41. $response = rest_ensure_response( $data ); 
  42.  
  43. $response->add_links( $this->prepare_links( $item, $request ) ); 
  44.  
  45. /** 
  46. * Filter a term item returned from the API. 
  47. * Allows modification of the term data right before it is returned. 
  48. * @param \WP_REST_Response $response The response object. 
  49. * @param object $item The original term object. 
  50. * @param \WP_REST_Request $request Request used to generate the response. 
  51. */ 
  52. return apply_filters( "woocommerce_rest_prepare_{$this->taxonomy}", $response, $item, $request ); 
  53.  
  54. /** 
  55. * Get the Category schema, conforming to JSON Schema. 
  56. * @return array 
  57. */ 
  58. public function get_item_schema() { 
  59. $schema = array( 
  60. '$schema' => 'http://json-schema.org/draft-04/schema#',  
  61. 'title' => $this->taxonomy,  
  62. 'type' => 'object',  
  63. 'properties' => array( 
  64. 'id' => array( 
  65. 'description' => __( 'Unique identifier for the resource.', 'woocommerce-germanized' ),  
  66. 'type' => 'integer',  
  67. 'context' => array( 'view', 'edit' ),  
  68. 'readonly' => true,  
  69. ),  
  70. 'name' => array( 
  71. 'description' => __( 'Resource name.', 'woocommerce-germanized' ),  
  72. 'type' => 'string',  
  73. 'context' => array( 'view', 'edit' ),  
  74. 'arg_options' => array( 
  75. 'sanitize_callback' => 'sanitize_text_field',  
  76. ),  
  77. ),  
  78. 'slug' => array( 
  79. 'description' => __( 'An alphanumeric identifier for the resource unique to its type.', 'woocommerce-germanized' ),  
  80. 'type' => 'string',  
  81. 'context' => array( 'view', 'edit' ),  
  82. 'arg_options' => array( 
  83. 'sanitize_callback' => 'sanitize_title',  
  84. ),  
  85. ),  
  86. 'description' => array( 
  87. 'description' => __( 'HTML description of the resource.', 'woocommerce-germanized' ),  
  88. 'type' => 'string',  
  89. 'context' => array( 'view', 'edit' ),  
  90. 'arg_options' => array( 
  91. 'sanitize_callback' => 'wp_filter_post_kses',  
  92. ),  
  93. ),  
  94. 'count' => array( 
  95. 'description' => __( 'Number of published products for the resource.', 'woocommerce-germanized' ),  
  96. 'type' => 'integer',  
  97. 'context' => array( 'view', 'edit' ),  
  98. 'readonly' => true,  
  99. ),  
  100. ),  
  101. ); 
  102.  
  103. return $this->add_additional_fields_schema( $schema );