WPCF7_REST_Controller::create_feedback
Метод класса: WPCF7_REST_Controller{}
Хуки из метода
Возвращает
null. Ничего (null).
Использование
$WPCF7_REST_Controller = new WPCF7_REST_Controller(); $WPCF7_REST_Controller->create_feedback( $request );
- $request(WP_REST_Request) (обязательный)
- .
Код WPCF7_REST_Controller::create_feedback() WPCF7 REST Controller::create feedback CF7 6.1.6
public function create_feedback( WP_REST_Request $request ) {
$content_type = $request->get_header( 'Content-Type' ) ?? '';
if ( ! str_starts_with( $content_type, 'multipart/form-data' ) ) {
return new WP_Error( 'wpcf7_unsupported_media_type',
__( 'The request payload format is not supported.', 'contact-form-7' ),
array( 'status' => 415 )
);
}
$url_params = $request->get_url_params();
$item = null;
if ( ! empty( $url_params['id'] ) ) {
$item = wpcf7_contact_form( $url_params['id'] );
}
if ( ! $item ) {
return new WP_Error( 'wpcf7_not_found',
__( 'The requested contact form was not found.', 'contact-form-7' ),
array( 'status' => 404 )
);
}
$unit_tag = wpcf7_sanitize_unit_tag(
$request->get_param( '_wpcf7_unit_tag' )
);
if ( empty( $unit_tag ) ) {
return new WP_Error( 'wpcf7_unit_tag_not_found',
__( 'There is no valid unit tag.', 'contact-form-7' ),
array( 'status' => 400 )
);
}
$result = $item->submit();
$response = array_merge( $result, array(
'into' => sprintf( '#%s', $unit_tag ),
'invalid_fields' => array(),
) );
if ( ! empty( $result['invalid_fields'] ) ) {
$invalid_fields = array();
foreach ( (array) $result['invalid_fields'] as $name => $field ) {
if ( ! wpcf7_is_name( $name ) ) {
continue;
}
$name = strtr( $name, '.', '_' );
$invalid_fields[] = array(
'field' => $name,
'message' => $field['reason'],
'idref' => $field['idref'],
'error_id' => sprintf(
'%1$s-ve-%2$s',
$unit_tag,
$name
),
);
}
$response['invalid_fields'] = $invalid_fields;
}
$response = wpcf7_apply_filters_deprecated(
'wpcf7_ajax_json_echo',
array( $response, $result ),
'5.2',
'wpcf7_feedback_response'
);
$response = apply_filters( 'wpcf7_feedback_response', $response, $result );
return rest_ensure_response( $response );
}