Home › Forums › Front-end Issues › acf/save_post hook how to display error message › Reply To: acf/save_post hook how to display error message
Hi John,
Thanks for your quick reply.
For Second problem, regarding data is being saved under wp_options table, now i am using acf/pre_save_post filter instead of acf/save_post filter. Now it’s work properly. Now no more data is being saved in wp_options table.
For First issue, i still have some confusion, where do i write below code, i meant to say in which hook do i write code ?
// Create a new user
if ( 'create_user' === $post_id )
{
$user_name = sanitize_text_field($_POST['acf']['field_5e42850b5b270']);
$user_email = sanitize_email($_POST['acf']['field_5e4282dbd4ddd']);
$user_password = sanitize_text_field($_POST['acf']['field_5e4284f25b26f']);
$new_user_id = wp_insert_user(array(
'first_name' => $user_name,
'user_email' => $user_email,
'user_login' => $user_email,
'user_pass' => $user_password,
'role' => 'subscriber'
));
if( is_wp_error( $new_user_id ) )
{
$error_string = $new_user_id->get_error_message();
echo '<div id="message" class="error"><p>' . $error_string . '</p></div>';
}
else
return true;
Because as you mentioned that to validate field, we need to use acf/validate_value filter for all fields. Because we don’t know at what circumstances wp_insert_user() function will return error.
So my question is that when using acf/pre_save_post filter, if any error occur runtime inside wp_insert_user() function, then how can we show error message ?
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.