100 * @param WP_REST_Request $request Request object. |
100 * @param WP_REST_Request $request Request object. |
101 * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure. |
101 * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure. |
102 */ |
102 */ |
103 public function prepare_item_for_response( $item, $request ) { |
103 public function prepare_item_for_response( $item, $request ) { |
104 $fields = $this->get_fields_for_response( $request ); |
104 $fields = $this->get_fields_for_response( $request ); |
105 $keys = array( 'name', 'label' ); |
105 $keys = array( 'name', 'label', 'description' ); |
106 $data = array(); |
106 $data = array(); |
107 foreach ( $keys as $key ) { |
107 foreach ( $keys as $key ) { |
108 if ( rest_is_field_included( $key, $fields ) ) { |
108 if ( isset( $item[ $key ] ) && rest_is_field_included( $key, $fields ) ) { |
109 $data[ $key ] = $item[ $key ]; |
109 $data[ $key ] = $item[ $key ]; |
110 } |
110 } |
111 } |
111 } |
112 |
112 |
113 $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; |
113 $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; |
123 * @since 6.0.0 |
123 * @since 6.0.0 |
124 * |
124 * |
125 * @return array Item schema data. |
125 * @return array Item schema data. |
126 */ |
126 */ |
127 public function get_item_schema() { |
127 public function get_item_schema() { |
|
128 if ( $this->schema ) { |
|
129 return $this->add_additional_fields_schema( $this->schema ); |
|
130 } |
|
131 |
128 $schema = array( |
132 $schema = array( |
129 '$schema' => 'http://json-schema.org/draft-04/schema#', |
133 '$schema' => 'http://json-schema.org/draft-04/schema#', |
130 'title' => 'block-pattern-category', |
134 'title' => 'block-pattern-category', |
131 'type' => 'object', |
135 'type' => 'object', |
132 'properties' => array( |
136 'properties' => array( |
133 'name' => array( |
137 'name' => array( |
134 'description' => __( 'The category name.' ), |
138 'description' => __( 'The category name.' ), |
135 'type' => 'string', |
139 'type' => 'string', |
136 'readonly' => true, |
140 'readonly' => true, |
137 'context' => array( 'view', 'edit', 'embed' ), |
141 'context' => array( 'view', 'edit', 'embed' ), |
138 ), |
142 ), |
139 'label' => array( |
143 'label' => array( |
140 'description' => __( 'The category label, in human readable format.' ), |
144 'description' => __( 'The category label, in human readable format.' ), |
|
145 'type' => 'string', |
|
146 'readonly' => true, |
|
147 'context' => array( 'view', 'edit', 'embed' ), |
|
148 ), |
|
149 'description' => array( |
|
150 'description' => __( 'The category description, in human readable format.' ), |
141 'type' => 'string', |
151 'type' => 'string', |
142 'readonly' => true, |
152 'readonly' => true, |
143 'context' => array( 'view', 'edit', 'embed' ), |
153 'context' => array( 'view', 'edit', 'embed' ), |
144 ), |
154 ), |
145 ), |
155 ), |
146 ); |
156 ); |
147 |
157 |
148 return $this->add_additional_fields_schema( $schema ); |
158 $this->schema = $schema; |
|
159 |
|
160 return $this->add_additional_fields_schema( $this->schema ); |
149 } |
161 } |
150 } |
162 } |