This article contains PHP code and is intended for developers. We offer this code as a courtesy, but don't provide support for code customizations or 3rd party development.
This hook can be used to filter the data response object.
Usage
add_filter( 'rest_prepare_frm_[action]', 'change_item_name' );
Parameters
- $data (object)
- $item (object)
- $request (array)
Examples
Change item name
This example will change the item name for the data response object
add_filter( 'rest_prepare_frm_entries', 'change_item_name', 10, 3 );
function change_item_name( $response, $item, $request ) {
if ( isset( $response->data['name'] ) ) {
$response->data['name'] = 'place here the new name of the item';
}
return $response;
}
Change field name
This example will change the field name for the data response object
add_filter( 'rest_prepare_frm_fields', 'change_field_name', 10, 3 );
function change_field_name( $response, $field, $request ) {
if ( isset( $response->data['name'] ) ) {
$response->data['name'] = 'place here the new name of the field';
}
return $response;
}
Change form name
This example will change the form name for the data response object
add_filter( 'rest_prepare_frm_forms', 'change_form_name', 10, 3 );
function change_form_name( $response, $form, $request ) {
if ( isset( $response->data['name'] ) ) {
$response->data['name'] = 'place here the new name of the form';
}
return $response;
}
converts a specific meta key to an integer
This example will allow you to convert a specific meta key to an integer.
add_filter( 'rest_prepare_frm_entries', 'my_custom_function' );
function my_custom_function( $response ) {
$meta_key = '5a4m0'; // change this to the meta key that needs to be converted to an integer.
if ( isset( $response->data ) && ! empty( $response->data['meta'] ) && isset( $response->data['meta'][ $meta_key ] ) ) {
$response->data['meta'][ $meta_key ] = (int) $response->data['meta'][ $meta_key ];
}
return $response;
}