Skip to content

Commit

Permalink
Example for rest_endpoints filter in PHP (#33738)
Browse files Browse the repository at this point in the history
Added an example of how to filter rest_endpoints for POST method before v5.5
  • Loading branch information
amir2mi authored Aug 3, 2021
1 parent 0e9c8b1 commit a3445cc
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions packages/server-side-render/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,24 @@ The HTTP request method to use, either 'GET' or 'POST'. It's 'GET' by default. T
- Type: `String`
- Required: No

#### Example:
```php
function add_rest_method( $endpoints ) {
if ( is_wp_version_compatible( '5.5' ) ) {
return $endpoints;
}

foreach ( $endpoints as $route => $handler ) {
if ( isset( $endpoints[ $route ][0] ) ) {
$endpoints[ $route ][0]['methods'] = [ WP_REST_Server::READABLE, WP_REST_Server::CREATABLE ];
}
}

return $endpoints;
}
add_filter( 'rest_endpoints', 'add_rest_method');
```

### urlQueryArgs

Query arguments to apply to the request URL.
Expand Down

0 comments on commit a3445cc

Please sign in to comment.