traits
3 years ago
dynamic-rest-url-trait.php
3 years ago
rest-api-controller-base.php
3 years ago
rest-api-endpoint-base.php
3 years ago
rest-endpoint.php
3 years ago
rest-response.php
3 years ago
rest-response.php
31 lines
| 1 | <?php |
| 2 | |
| 3 | |
| 4 | namespace Jet_Form_Builder\Rest_Api; |
| 5 | |
| 6 | class Rest_Response extends \WP_REST_Response { |
| 7 | |
| 8 | public function get_custom_header_prefix(): string { |
| 9 | return 'X-JFB-'; |
| 10 | } |
| 11 | |
| 12 | public function set_headers_merge( array $headers ) { |
| 13 | if ( ! is_array( $this->headers ) ) { |
| 14 | $this->set_headers( array() ); |
| 15 | } |
| 16 | |
| 17 | $this->set_headers( array_merge( $this->headers, $headers ) ); |
| 18 | } |
| 19 | |
| 20 | public function set_headers_custom( $headers ) { |
| 21 | $prefix = $this->get_custom_header_prefix(); |
| 22 | $prepared = array(); |
| 23 | |
| 24 | foreach ( $headers as $name => $value ) { |
| 25 | $prepared[ $prefix . $name ] = $value; |
| 26 | } |
| 27 | |
| 28 | $this->set_headers_merge( $prepared ); |
| 29 | } |
| 30 | } |
| 31 |