我尝试使用REST API插入一篇文章,该API在一个API调用中包含文本和图像。
我的图像是一个acf字段。
我这样注册我的字段:
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\',
)
);
我通过邮递员发送我的请求
update_field_headline
正确调用,但update_field_logo
就是从不打电话。
我尝试调试wp-includes/rest-api/endpoints/class-wp-rest-controller.php
第421行见:
// Don\'t run the update callbacks if the data wasn\'t passed in the request.
if ( ! isset( $request[ $field_name ] ) ) {
continue;
}
我想update_field_logo
从不调用,因为“logo”不是在$\\u POST变量内设置的,而是在$\\u FILES变量内设置的。因此,在第421行中,该字段被跳过。如果我修改421行的核心文件,如下面所示,一切都很好
if ( ! isset( $request[ $field_name ] ) && ! isset($_FILES[ $field_name ] ) {
continue;
}
但修改WordPress核心文件并不是一个解决方案。。。知道如何允许在update\\u回调时触发文件吗?