ACF\AI\Abilities
Abilities::parse_abilities_json_input
Parse JSON input from query parameters for Abilities API
WordPress 6.9's Abilities API REST controller doesn't parse JSON strings from query parameters in GET requests. This filter fixes that by detecting JSON strings in the 'input' parameter and parsing them into objects/arrays.
Метод класса: Abilities{}
Хуков нет.
Возвращает
mixed.
Использование
$Abilities = new Abilities(); $Abilities->parse_abilities_json_input( $response, $handler, $request );
- $response(разное) (обязательный)
- Response object.
- $handler(массив) (обязательный)
- Route handler info.
- $request(WP_REST_Request) (обязательный)
- Request object.
Список изменений
| С версии 6.8.0 | Введена. |
Код Abilities::parse_abilities_json_input() Abilities::parse abilities json input ACF 6.8.11
public function parse_abilities_json_input( $response, $handler, $request ) {
// Only process ACF abilities.
$route = $request->get_route();
if ( strpos( $route, '/wp-abilities/v1/abilities/acf/' ) !== 0 ) {
return $response;
}
// Only process GET and DELETE requests (POST uses JSON body which is already parsed).
if ( ! in_array( $request->get_method(), array( 'GET', 'DELETE' ), true ) ) {
return $response;
}
// Get the input query parameter.
$input = $request->get_param( 'input' );
// If input is a string that looks like JSON, try to parse it.
if ( is_string( $input ) && ! empty( $input ) ) {
$first_char = substr( trim( $input ), 0, 1 );
// Check if it starts with { or [ (JSON object or array).
if ( in_array( $first_char, array( '{', '[' ), true ) ) {
$parsed = json_decode( $input, true );
if ( json_last_error() === JSON_ERROR_NONE ) {
// Successfully parsed JSON - update the request parameter.
$request->set_param( 'input', $parsed );
}
}
}
return $response;
}