register_rest_field update_callback don’t work for $_FILES


I try to insert a post with REST API who contain text and image in one api call.

My image is an acf field.

I register my field like that:

register_rest_field( 'project', 'logo', array(
    'get_callback'       => 'get_field_logo',
    'update_callback'    => 'update_field_logo',
register_rest_field( 'project', 'headline', array(
    'get_callback'       => 'get_field_headline',
    'update_callback'    => 'update_field_headline',

I send my request via Postman

update_field_headline is correctly call, but update_field_logo is never call.

I try to debug wp-includes/rest-api/endpoints/class-wp-rest-controller.php

on line 421 is see:

// Don't run the update callbacks if the data wasn't passed in the request.
if ( ! isset( $request[ $field_name ] ) ) {

I think update_field_logo is never call because “logo” is not set inside $_POST variable but inside $_FILES variable. So in line 421 the field is skipped.

If I modifiy the core file on line 421 like below everythings work well

if ( ! isset( $request[ $field_name ] ) && ! isset($_FILES[ $field_name ] ) {

But modify WordPress Core file is not a solution…

Any idea how can I allow files to be trigger on update_callback ?

Read more here:: register_rest_field update_callback don’t work for $_FILES

Leave a Reply

Your email address will not be published. Required fields are marked *