Title: WP_REST_Icons_Controller::prepare_item_for_response
Published: May 20, 2026

---

# WP_REST_Icons_Controller::prepare_item_for_response( array $item, WP_REST_Request $request ): 󠀁[WP_REST_Response](https://developer.wordpress.org/reference/classes/wp_rest_response/)󠁿|󠀁[WP_Error](https://developer.wordpress.org/reference/classes/wp_error/)󠁿

## In this article

 * [Parameters](https://developer.wordpress.org/reference/classes/wp_rest_icons_controller/prepare_item_for_response/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/classes/wp_rest_icons_controller/prepare_item_for_response/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/classes/wp_rest_icons_controller/prepare_item_for_response/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/classes/wp_rest_icons_controller/prepare_item_for_response/?output_format=md#related)

[ Back to top](https://developer.wordpress.org/reference/classes/wp_rest_icons_controller/prepare_item_for_response/?output_format=md#wp--skip-link--target)

Prepare a raw icon before it gets output in a REST API response.

## 󠀁[Parameters](https://developer.wordpress.org/reference/classes/wp_rest_icons_controller/prepare_item_for_response/?output_format=md#parameters)󠁿

 `$item`arrayrequired

Raw icon as registered, before any changes.

`$request`[WP_REST_Request](https://developer.wordpress.org/reference/classes/wp_rest_request/)
required

Request object.

## 󠀁[Return](https://developer.wordpress.org/reference/classes/wp_rest_icons_controller/prepare_item_for_response/?output_format=md#return)󠁿

 [WP_REST_Response](https://developer.wordpress.org/reference/classes/wp_rest_response/)
|[WP_Error](https://developer.wordpress.org/reference/classes/wp_error/) Response
object on success, or [WP_Error](https://developer.wordpress.org/reference/classes/wp_error/)
object on failure.

## 󠀁[Source](https://developer.wordpress.org/reference/classes/wp_rest_icons_controller/prepare_item_for_response/?output_format=md#source)󠁿

    ```php
    public function prepare_item_for_response( $item, $request ) {
    	$fields = $this->get_fields_for_response( $request );
    	$keys   = array(
    		'name'    => 'name',
    		'label'   => 'label',
    		'content' => 'content',
    	);
    	$data   = array();
    	foreach ( $keys as $item_key => $rest_key ) {
    		if ( isset( $item[ $item_key ] ) && rest_is_field_included( $rest_key, $fields ) ) {
    			$data[ $rest_key ] = $item[ $item_key ];
    		}
    	}

    	$context = ! empty( $request['context'] ) ? $request['context'] : 'view';
    	$data    = $this->add_additional_fields_to_object( $data, $request );
    	$data    = $this->filter_response_by_context( $data, $context );
    	return rest_ensure_response( $data );
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-icons-controller.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.0/src/wp-includes/rest-api/endpoints/class-wp-rest-icons-controller.php#L179)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.0/src/wp-includes/rest-api/endpoints/class-wp-rest-icons-controller.php#L179-L197)

## 󠀁[Related](https://developer.wordpress.org/reference/classes/wp_rest_icons_controller/prepare_item_for_response/?output_format=md#related)󠁿

| Uses | Description | 
| [rest_is_field_included()](https://developer.wordpress.org/reference/functions/rest_is_field_included/)`wp-includes/rest-api.php` |

Given an array of fields to include in a response, some of which may be `nested.fields`, determine whether the provided field should be included in the response body.

  | 
| [rest_ensure_response()](https://developer.wordpress.org/reference/functions/rest_ensure_response/)`wp-includes/rest-api.php` |

Ensures a REST response is a response object (for consistency).

  |

| Used by | Description | 
| [WP_REST_Icons_Controller::get_items()](https://developer.wordpress.org/reference/classes/wp_rest_icons_controller/get_items/)`wp-includes/rest-api/endpoints/class-wp-rest-icons-controller.php` |

Retrieves all icons.

  | 
| [WP_REST_Icons_Controller::get_item()](https://developer.wordpress.org/reference/classes/wp_rest_icons_controller/get_item/)`wp-includes/rest-api/endpoints/class-wp-rest-icons-controller.php` |

Retrieves a specific icon.

  |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fclasses%2Fwp_rest_icons_controller%2Fprepare_item_for_response%2F)
before being able to contribute a note or feedback.