Support

Account

Home Forums Front-end Issues ACF_form User Profile editing Reply To: ACF_form User Profile editing

  • Me again! So the above code worked beautifully for the email address, thanks @raffacake but I thought I might be able to do the same thing for the user_url however I don’t seem to be able to get it working.

    Any ideas where I might be going wrong?

    Thanks

    function my_acf_save_post_website( $post_id ) {
    		// bail early if no ACF data
    		if( empty($_POST['acf']) ) {
    			return;
    		}
    
    		// bail early if editing in admin
    		if( is_admin() ) {
    			return;
    		}
    
    		if( $_POST['post_id'] != 'new' ) {
    
    	$urlField = $_POST['acf']['profile_website'];
    			$wp_user_id = str_replace("user_", "", $post_id);
    
    			if (isset($urlField)) {
    				if (url_exists( $urlField )){
    					// Website exists, do not update value.
    					// Maybe output a warning.
    					update_field('profile_website', get_the_author_meta('user_url',$wp_user_id), $post_id);
    				} else {
    					$args = array(
    						'ID'         => $wp_user_id,
    						'user_url' => esc_attr( $urlField )
    					);
    					wp_update_user( $args );
    				}
    			}
    		}
    
    		// return the ID
    		return $post_id;
    	}
    	add_action('acf/save_post', 'my_acf_save_website', 20);