frontend_admin/save_user

frontend_admin/save_user

Description

This action hook fires when a user is saved.

This action allows you to hook in after the form saves data to a new or existing user, making it useful to perform additional functionality when adding or updating your users.

This action can be used on the front end instead of the acf/save_post action hook.

Parameters

do_action( 'frontend_admin/save_user', $form, $user_id );
  • $form (array) The form settings, including $form[‘record’][‘user’] which contains all of the submitted user fields’ data.
  • $user_id (int|string) The ID of the user that is being edited.

Examples

Send email after user is saved.

This example demonstrates how to send an email after the user has been saved. Place this in your functions.php or a dedicated code snippets plugin.

functions.php

add_action('frontend_admin/save_user', 'my_frontend_save_user', 10, 2);
function my_frontend_save_user( $form, $user_id ) {
    $user = get_user_by('ID',$user_id);
    //get important fields
    $user_email = $user->user_email;
    $username = $user->user_login;
    $address = get_field('postal_address', 'user_' .$user_id);
    if( $address ) {
        $email_sent = wp_mail( $user_email, 'Welcome '.$user_title, 'Please confirm your address: '.$user_content );
    }
}

acf/save_post comparison

This hook is a bit different from acf/save_post so be aware of these differences:

  • $user_id is the second of two parameters, so make sure to include both parameters and to set the fourth argument of add_action to “2”.
  • In acf/save_post, you receive the user ID as a string, for example: “user_1”. In this hook you will receive the user id as an integer, for example: “1”.
  • This hook is always fired after the fields have been saved so none of the fields will be in the $_POST global but rather within the $form[‘record’][‘fields’][‘user’] array.

frontend_admin/save_user

Still stuck? 
Contact our support team here.