ACF\AI\Abilities
AbstractAbilityGroup::execute_rest_request
Execute a REST API request.
Метод класса: AbstractAbilityGroup{}
Хуков нет.
Возвращает
array|WP_Error. Response data or error.
Использование
// protected - в коде основоного (родительского) или дочернего класса $result = $this->execute_rest_request( $method, $rest_base, $input, $item_id );
- $method(строка) (обязательный)
- HTTP method (GET, POST, PUT, DELETE).
- $rest_base(строка) (обязательный)
- REST API base.
- $input(массив)
- Input parameters.
По умолчанию:array() - $item_id(int)
- Optional item ID for single item operations.
По умолчанию:null
Список изменений
| С версии 6.8.0 | Введена. |
Код AbstractAbilityGroup::execute_rest_request() AbstractAbilityGroup::execute rest request ACF 6.8.11
protected function execute_rest_request( string $method, string $rest_base, $input = array(), $item_id = null ) {
$endpoint = '/wp/v2/' . $rest_base;
if ( $item_id ) {
$endpoint .= '/' . intval( $item_id );
}
$request = new WP_REST_Request( $method, $endpoint );
// Set all input parameters.
foreach ( $input as $key => $value ) {
// Skip the ID since it's in the URL for single item operations.
if ( $key === 'id' && $item_id ) {
continue;
}
$request->set_param( $key, $value );
}
$response = rest_do_request( $request );
if ( $response->is_error() ) {
return $response->as_error();
}
return $response->get_data();
}