From a3445ccd3a2f16d923b1bc2873159d8f0cecde01 Mon Sep 17 00:00:00 2001 From: Amir Mohamadi <64708228+amir2mi@users.noreply.github.com> Date: Tue, 3 Aug 2021 11:10:12 +0430 Subject: [PATCH] Example for rest_endpoints filter in PHP (#33738) Added an example of how to filter rest_endpoints for POST method before v5.5 --- packages/server-side-render/README.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/packages/server-side-render/README.md b/packages/server-side-render/README.md index 8c0a782fed3b16..46e4b30fd549a3 100644 --- a/packages/server-side-render/README.md +++ b/packages/server-side-render/README.md @@ -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.