Support

Account

Forum Replies Created

  • 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.";  
            }
         }
    }
  • Thanks Elliot,
    Unsetting $_POST[‘acf_nonce’] before inserting the user stops the ACF fields from being passed to the new user account. That works great, but the publish hook fires before the post is saved, meaning the ACF fields are not saved to the custom post record.

    Do you know if there’s a way to change the order of the publish function to fire after the post save? I’ll of course experiment with this too and post back here if I find a solution.

    Thanks again

Viewing 2 posts - 1 through 2 (of 2 total)