I cannot add user to the discouse forum from a wordpress website when user added in a membership

Hi @simon i want to sync user avatar between wordpress and discourse as i already using wp discourse plugin for sso now i want when i user change avatar on the discourse website then it should also needs to change on the wordpress website how it can be possible and i want using one user avatar plugin on the wordpress website and here is the code i am using

function my_wpdc_sso_client_updated_user( $updated_user, $query ) {
		$avatar_url = $query['avatar_url'];
		$user_id = $updated_user->ID;
		// it allows us to use download_url() and wp_handle_sideload() functions
	require_once( ABSPATH . 'wp-admin/includes/file.php' );

	// download to temp dir
	$temp_file = download_url( $avatar_url );

	if( is_wp_error( $temp_file ) ) {
		return false;
	}

	// move the temp file into the uploads directory
	$file = array(
		'name'     => basename( $image_url ),
		'type'     => mime_content_type( $temp_file ),
		'tmp_name' => $temp_file,
		'size'     => filesize( $temp_file ),
	);
	$sideload = wp_handle_sideload(
		$file,
		array(
			'test_form'   => false // no needs to check 'action' parameter
		)
	);

	if( ! empty( $sideload[ 'error' ] ) ) {
		// you may return error message if you want
		return false;
	}

	// it is time to add our uploaded image into WordPress media library
	$attachment_id = wp_insert_attachment(
		array(
			'guid'           => $sideload[ 'url' ],
			'post_mime_type' => $sideload[ 'type' ],
			'post_title'     => basename( $sideload[ 'file' ] ),
			'post_content'   => '',
			'post_status'    => 'inherit',
		),
		$sideload[ 'file' ]
	);

	if( is_wp_error( $attachment_id ) || ! $attachment_id ) {
		return false;
	}

	// update medatata, regenerate image sizes
	require_once( ABSPATH . 'wp-admin/includes/image.php' );

	wp_update_attachment_metadata(
		$attachment_id,
		wp_generate_attachment_metadata( $attachment_id, $sideload[ 'file' ] )
	);

	// Return the attachment ID
	update_user_meta($user_id, '1709753088_wp_user_avatar', $attachment_id);
	update_user_meta($user_id, 'wp_user_avatar', $attachment_id);
}

as you can see i want to update meta keys of user using attachment id but attachment id is not going to created

looking to here from you

Thank You