Я хочу установить пользовательское ответное сообщение для CF7. После отправки через CF7 я получу вывод ответа от метода wp_remote_post, но не смог отобразить сообщение об ошибке ответа в форме CF7. У меня есть следующий код. Пожалуйста, объясните мне, как я могу установить сообщение об ошибке пользовательского ответа.
add_filter( 'wpcf7_before_send_mail', 'create_tocken' );
function create_tocken( $contact_form ) {
global $wpdb;
if ( ! isset( $contact_form->posted_data ) && class_exists( 'WPCF7_Submission' ) ) {
$submission = WPCF7_Submission::get_instance();
if ( $submission ) {
$form_data = $submission->get_posted_data();
}
} else {
return $contact_form;
}
$body = array(
'username' => 'xxxxx',
'password' => 'xxxxxx',
'type' => 'xxxxx',
'name' => 'xxxxxx',
'phone' => 'xxxxxx',
'email' => 'xxxxxx',
'town' => 'xxxxxx',
);
$url = 'https://example.com/';
$params = array(
'headers' => array(
'Content-Type' => 'application/x-www-form-urlencoded'
),
'body' => $body
);
$response = wp_remote_post( $url, $params );
if ( is_wp_error( $response ) ) {
$error_message = $response->get_error_message();
}
}
Здесь я хотел установить $ error_message в качестве сообщения пользовательского ответа.