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

**URL:** <https://meta.discourse.org/t/i-cannot-add-user-to-the-discouse-forum-from-a-wordpress-website-when-user-added-in-a-membership/300025>\
**Category:** Development\
**Created:** [March 19, 2024, 4:54pm UTC](https://meta.discourse.org/t/i-cannot-add-user-to-the-discouse-forum-from-a-wordpress-website-when-user-added-in-a-membership/300025 "2024-03-19T16:54:32Z")\
**Posts on this page:** 1\
**Showing post:** 20

<div class="post-metadata">

**Author:** ![Haseeb\_Ahmed](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/haseeb_ahmed/32/372254_2.png) [@Haseeb\_Ahmed](https://meta.discourse.org/u/Haseeb_Ahmed)\
**Post date:** [May 20, 2024, 12:25pm UTC](https://meta.discourse.org/t/i-cannot-add-user-to-the-discouse-forum-from-a-wordpress-website-when-user-added-in-a-membership/300025/20 "2024-05-20T12:25:02Z")

</div>

Hi @simon i want to sync user avatar between wordpress and discourse as i already using [wp discourse](https://github.com/discourse/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

```plaintext
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

---

_[View the full topic](https://meta.discourse.org/t/i-cannot-add-user-to-the-discouse-forum-from-a-wordpress-website-when-user-added-in-a-membership/300025)._
