WPCF7_REST_Controller::update_contact_form
Метод класса: WPCF7_REST_Controller{}
Хуков нет.
Возвращает
null. Ничего (null).
Использование
$WPCF7_REST_Controller = new WPCF7_REST_Controller(); $WPCF7_REST_Controller->update_contact_form( $request );
- $request(WP_REST_Request) (обязательный)
- .
Код WPCF7_REST_Controller::update_contact_form() WPCF7 REST Controller::update contact form CF7 6.1.6
public function update_contact_form( WP_REST_Request $request ) {
$id = (int) $request->get_param( 'id' );
$item = wpcf7_contact_form( $id );
if ( ! $item ) {
return new WP_Error( 'wpcf7_not_found',
__( 'The requested contact form was not found.', 'contact-form-7' ),
array( 'status' => 404 )
);
}
$args = $request->get_params();
$context = $request->get_param( 'context' );
$item = wpcf7_save_contact_form( $args, $context );
if ( ! $item ) {
return new WP_Error( 'wpcf7_cannot_save',
__( 'There was an error saving the contact form.', 'contact-form-7' ),
array( 'status' => 500 )
);
}
$response = array(
'id' => $item->id(),
'slug' => $item->name(),
'title' => $item->title(),
'locale' => $item->locale(),
'properties' => $this->get_properties( $item ),
'config_errors' => array(),
);
if ( wpcf7_validate_configuration() ) {
$config_validator = new WPCF7_ConfigValidator( $item );
$config_validator->validate();
$response['config_errors'] = $config_validator->collect_error_messages(
array( 'decodes_html_entities' => true )
);
if ( 'save' === $context ) {
$config_validator->save();
}
}
return rest_ensure_response( $response );
}