Click to initialize TinyMCE
The User Action is a template to create, update or log a user on form submission.
Add actions on form submission
(Optional) Target this action using hooks.
The URL to redirect to. See "Cheatsheet" tab for all available template tags.
(Optional) Target this action using hooks.
Fill inputs with values
(Optional) Target this action using hooks.
Fill inputs with values
Setting name | Description |
Action type | Create, update or log a user |
Action name | Alias name allowing to use targeted hook |
Target | The user to update |
Source | The user to retrieve fields from |
Load values | Fill inputs with values |
The user e-mail | |
Username | The username |
Password | The user password |
First name | The user first name |
Last name | The user last name |
Nickname | The user nickname |
Display name | The user display name |
Website | The user website |
Description | The user description |
Role | The user role |
Save ACF fields | Choose which ACF fields should be saved to this user |
Load ACF fields | Choose which ACF fields should have their values loaded |
The Action is bundled with a validation process for the Log User Action type. You can use the acf/validate_value
hook to validate each fields individually.
To validate the whole form, you can use the acfe/form/validation/user
hook and throw errors with the acfe_add_validation_error()
function.
Usage example:
/*
* User Validation
*
* @array $form Form settings
* @string $post_id Post ID (where the form is displayed)
* @string $action Action name
*/
action('acfe/form/validation/user', $form, $post_id, $action);
action('acfe/form/validation/user/form=my-form', $form, $post_id, $action);
action('acfe/form/validation/user/action=my-user', $form, $post_id, $action);
add_action('acfe/form/validation/user/form=my-form', 'my_form_validation', 10, 3);
function my_form_validation($form, $post_id, $action){
// Get field input value
$my_field = get_field('my_field');
if($my_field === 'Company'){
// Add validation error
acfe_add_validation_error('my_field', 'The value Company is not allowed');
}
}
The preparation phase is triggered after the form validation and before its submission. Returning false
will stop the Action and go to the next one. Usage example:
/*
* User Prepare
*
* @bool $prepare True/false
* @array $form Form settings
* @string $post_id Post ID (where the form is displayed)
* @string $action Action name
*/
filter('acfe/form/prepare/user', $prepare, $form, $post_id, $action);
filter('acfe/form/prepare/user/form=my-form', $prepare, $form, $post_id, $action);
filter('acfe/form/prepare/user/action=my-user', $prepare, $form, $post_id, $action);
add_filter('acfe/form/prepare/user/form=my-form', 'my_form_prepare', 10, 4);
function my_form_prepare($prepare, $form, $post_id, $action){
// Do not create/update/log user if user isn't logged in
if(!is_user_logged_in()){
$prepare = false;
}
// return
return $prepare;
}
Alter the user ID where meta values are loaded from. Usage example:
/*
* User Values Source
*
* @int $user_id User ID Source
* @array $form Form settings
* @string $action Action name
*/
filter('acfe/form/load/user_id', $user_id, $form, $action);
filter('acfe/form/load/user_id/form=my-form', $user_id, $form, $action);
filter('acfe/form/load/user_id/action=my-user', $user_id, $form, $action);
add_filter('acfe/form/load/user_id/form=my-form', 'my_form_user_source', 10, 3);
function my_form_user_source($user_id, $form, $action){
// Get field input value
$my_field = get_field('my_field');
if($my_field === 'Company'){
// Force to load values from the user ID 8
$user_id = 8;
}
// return
return $user_id;
}
Alter the user arguments before database insert/update. Those arguments are later passed to wp_insert_user()
or wp_update_user()
(See documentation). Usage example:
/*
* User Arguments
*
* @array $args Generated user arguments
* @string $type Action type: 'insert_user' or 'update_user'
* @array $form Form settings
* @string $action Action name
*/
filter('acfe/form/submit/user_args', $args, $type, $form, $action);
filter('acfe/form/submit/user_args/form=my-form', $args, $type, $form, $action);
filter('acfe/form/submit/user_args/action=my-user', $args, $type, $form, $action);
add_filter('acfe/form/submit/user_args/form=my-form', 'my_form_user_args', 10, 4);
function my_form_user_args($args, $type, $form, $action){
/*
* Get the form input value named 'my_field'
*/
$my_field = get_field('my_field');
if($my_field === 'Company'){
// Change First Name
$args['first_name'] = 'My name';
}
/*
* Get previous Post Action output
*/
$prev_post_action = acfe_form_get_action('post');
if(!empty($prev_post_action)){
if($prev_post_action['post_title'] === 'Company'){
// Change First Name
$args['first_name'] = 'My name';
}
}
// Stop User save
// return false;
// return
return $args;
}
Trigger a custom action after the user was created/updated/logged using the acfe/form/submit/user
hook. Usage example:
/*
* User Submit
*
* @int $user_id Created/Updated user ID
* @string $type Action type: 'insert_user', 'update_user' or 'log_user'
* @array $args Generated user arguments
* @array $form Form settings
* @string $action Action name
*/
action('acfe/form/submit/user', $user_id, $type, $args, $form, $action);
action('acfe/form/submit/user/form=my-form', $user_id, $type, $args, $form, $action);
action('acfe/form/submit/user/action=my-user', $user_id, $type, $args, $form, $action);
add_action('acfe/form/submit/user/form=my-form', 'my_form_submit', 10, 5);
function my_form_submit($user_id, $type, $args, $form, $action){
/*
* Get the form input value named 'my_field'
*/
$my_field = get_field('my_field');
if($my_field === 'Company'){
// do_something();
}
/*
* Get previous Post Action output
*/
$prev_post_action = acfe_form_get_action('post');
if(!empty($prev_post_action)){
if($prev_post_action['post_title'] === 'Company'){
// do_something();
}
}
}
The Action Output let developers retrieve the action data in a future action within the Form UI or a PHP hook. For example, the Template Tag {action:user:user_login}
will output the latest User Action “Login” setting.
If the action is named, the Template Tag will use it. Ie: {action:my-user:user_login}
. The equivalent function in PHP is acfe_form_get_action('user')
.
It is possible to change the output of a User Action using the acfe/form/output/user
filter. Usage example:
/*
* User Output
*
* @array $data User information
* @array $user_id Created/Updated user ID
* @string $type Action type: 'insert_user', 'update_user' or 'log_user'
* @array $args User arguments
* @array $form Form settings
* @string $action Action name
*/
filter('acfe/form/output/user', $data, $user_id, $type, $args, $form, $action);
filter('acfe/form/output/user/form=my-form', $data, $user_id, $type, $args, $form, $action);
filter('acfe/form/output/user/action=my-user', $data, $user_id, $type, $args, $form, $action);
add_filter('acfe/form/output/user/form=my-form', 'my_form_output', 10, 6);
function my_form_output($data, $user_id, $type, $args, $form, $action){
/*
* $data
*
* Array
* (
* [ID] => 4
* [user_login] => User
* [user_pass] => mypassword
* [user_nicename] => user
* [user_email] => [email protected]
* [user_url] =>
* [user_registered] => 2020-08-19 20:27:59
* [user_activation_key] =>
* [user_status] => 0
* [display_name] => First name Last name
* [nickname] => User
* [first_name] => First name
* [last_name] => Last name
* [description] =>
* [rich_editing] => true
* [syntax_highlighting] => true
* [comment_shortcuts] => false
* [admin_color] => fresh
* [use_ssl] => 0
* [show_admin_bar_front] => true
* [locale] =>
* [wp_capabilities] => a:1:{s:10:"subscriber";b:1;}
* [wp_user_level] => 0
* [permalink] => /author/user
* [admin_url] => /wp-admin/user-edit.php?user_id=4
* )
*/
// Get field input value
$my_field = get_field('my_field');
if($my_field === 'Company'){
// Set a custom key
$data['custom_key'] = 'custom_value';
}
// return
return $data;
}