Hi,
I try to register new user with acf_form() but the meta user values are not saved…
My form :
$html = '<input type="hidden" name="action_form" value="inscription_accueilli"/>';
$args = array(
'post_id' => 'new',
'html_before_fields' => $html,
'field_groups' => array(412,472,473),
'form' => true,
'uploader' => 'basic',
'return' => 'http://xxx/inscription/merci-pour-votre-inscription',
'submit_value' => 'INSCRIPTION'
);
acf_form($args);
My acf/pre_save_post for create new user :
function register_accueilli($post_id) {
$action = $_POST['action_form'];
if ( $action == "inscription_accueilli" && $post_id == "new" ) {
$f = $_POST['acf'];
$prenom = $f['field_580dda605ce41'];
$nom = $f['field_580dda605cdc8'];
$email = $f['field_580f277e392bc'];
$pseudo = sanitize_title($prenom." ".$nom);
if ( !username_exists($pseudo) && !email_exists($email) ) {
$random_password = wp_generate_password( $length = 8, false );
$key_active = wp_generate_password( $length = 20, false );
$user_id = wp_create_user( $pseudo, $random_password, $email );
$user_id_role = new WP_User($user_id);
$user_id_role->set_role('accueilli');
update_user_meta($user_id, 'pseudo', $pseudo );
update_user_meta($user_id, 'key_new', $key_active );
$test_inscription = wp_update_user( array(
'ID' => $user_id,
'first_name' => $prenom,
'last_name' => $nom,
'user_login' => $pseudo,
'user_nicename' => $prenom . " " . $nom,
'display_name' => $prenom . " " . $nom
));
$values_emails = array(
'prenom' => $prenom,
'nom' => $nom,
'pseudo' => $pseudo,
'mdp' => $random_password,
'url_activer' => get_bloginfo('url')."/inscription/activer-votre-compte/?key=".$key_active
);
envoyer_mail($email,232, $values_emails);
}
}
return $post_id;
}
For edit the meta value, i have an other form with another pre_save as this and he works…
Can you help me ?
I have found !
function register_accueilli($post_id) {
$action = $_POST['action_form'];
if ( $action == "inscription_accueilli" ) {
$f = $_POST['acf'];
$prenom = $f['field_580dda605ce41'];
$nom = $f['field_580dda605cdc8'];
$email = $f['field_580f277e392bc'];
$pseudo = sanitize_title($prenom." ".$nom);
if ( !username_exists($pseudo) && !email_exists($email) ) {
$random_password = wp_generate_password( $length = 8, false );
$key_active = wp_generate_password( $length = 20, false );
$user_id = wp_create_user( $pseudo, $random_password, $email );
$user_id_role = new WP_User($user_id);
$user_id_role->set_role('accueilli');
update_user_meta($user_id, 'pseudo', $pseudo );
update_user_meta($user_id, 'key_new', $key_active );
$test_inscription = wp_update_user( array(
'ID' => $user_id,
'first_name' => $prenom,
'last_name' => $nom,
'user_login' => $pseudo,
'user_nicename' => $prenom . " " . $nom,
'display_name' => $prenom . " " . $nom
));
$values_emails = array(
'prenom' => $prenom,
'nom' => $nom,
'pseudo' => $pseudo,
'mdp' => $random_password,
'url_activer' => get_bloginfo('url')."/inscription/activer-votre-compte/?key=".$key_active
);
envoyer_mail($email,232, $values_emails);
/* ------ ADD THE DO_ACTION SAVE POST ------ */
do_action('acf/save_post', "user_".$user_id);
}
}
}
add_filter('acf/pre_save_post' , 'register_accueilli' );
You must be logged in to reply to this topic.
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!
CPT registration is coming to ACF! We demoed the new feature during the most recent session of ACF Chat Fridays. Check out the summary for the details. https://t.co/k2KQ3WWBAz
— Advanced Custom Fields (@wp_acf) March 7, 2023
© 2023 Advanced Custom Fields.
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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.