# code-snippets/3.10.1/php/Utils/requests.php

Code Snippets, version 3.10.1. 29 lines.

- Page: https://pluginprobe.com/plugins/code-snippets/3.10.1/code/php/Utils/requests.php
- Raw: https://pluginprobe.com/plugins/code-snippets/3.10.1/raw/php/Utils/requests.php
- Modified: 2026-08-04T13:35:40+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/code-snippets/3.10.1/code/php/Utils/requests.php#L10-L20`.

```php
<?php
/**
 * A collection of utilities for handling REST requests and responses.
 *
 * @package Code_Snippets
 */

namespace Code_Snippets\Utils;

use WP_Error;

/**
 * Unpack JSON data from a request response.
 *
 * @param array|WP_Error $response Response from wp_request_*.
 *
 * @return array<string, mixed>|null Associative array of JSON data on success, null on failure.
 */
function unpack_response_body( $response ): ?array {
	$body = wp_remote_retrieve_body( $response );

	if ( $body ) {
		$json = json_decode( $body, true );
		return is_array( $json ) ? $json : null;
	}

	return null;
}

```
