Home › Forums › Backend Issues (wp-admin) › wp_insert_user on save › Reply To: wp_insert_user on save
I had no luck changing the order, but I’ve fixed this by just unsetting the post data, then adding it back on after the user has been created. Here’s the complete function, in case it’s of use to someone else.
add_filter('publish_homeowner', 'homeowner_postdata');
function homeowner_postdata( $post_id ) {
global $wpdb;
$username = preg_replace("/[^A-Za-z0-9]/", "", strtolower(get_the_title($post_id)));
$email = preg_replace("/[^A-Za-z0-9]/", "", strtolower(str_replace(" ", ".", get_the_title($post_id))));
$random_password = wp_generate_password( 8, false );
$userargs = array(
'user_pass' => $random_password,
'user_login' => $username,
'user_email' => $email,
'role' => 'homeowner'
);
$acf_nonce = $_POST['acf_nonce'];
$_POST['acf_nonce'] = '';
$status = wp_insert_user( $userargs );
if ( is_wp_error($status) ) {
//echo "User not created.";
} else {
$_POST['acf_nonce'] = $acf_nonce;
//echo "User created.";
}
}
}
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.