Handle integration with the user_register and profile_update hooks.

@see wp_insert_user

@param int         $user_id       User ID.
@param object|null $old_user_data Object containing user's data prior to update.
765167
public function save_user( $user_id, $old_user_data = null ) {

		$is_new_item = false;

		if ( 'user_register' == current_filter() ) {
			$is_new_item = true;
		}

		$nonced = wp_verify_nonce( pods_v( 'pods_meta', 'post' ), 'pods_meta_user' );

		if ( ! $is_new_item && false === $nonced ) {
			return;
		}

		if ( is_object( $user_id ) ) {
			$user_id = $user_id->ID;
		}

		$groups = $this->groups_get( 'user', 'user' );

		$id = $user_id;

		if ( ! is_object( self::$current_pod ) || self::$current_pod->pod !== 'user' ) {
			self::$current_pod = pods( 'user', $id, true );
		} elseif ( is_object( self::$current_pod ) && (int) self::$current_pod->id() !== (int) $id ) {
			self::$current_pod->fetch( $id );
		}

		$pod  = self::$current_pod;
		$data = array();

		if ( $pod ) {
			$rest_enable = (boolean) pods_v( 'rest_enable', $pod->pod_data['options'], false );

			// Block REST API saves, we handle those separately in PodsRESTHandlers
			if ( defined( 'REST_REQUEST' ) && REST_REQUEST && $rest_enable ) {
				return;
			}
		}

		if ( false !== $nonced && ! empty( $groups ) ) {
			foreach ( $groups as $group ) {
				if ( empty( $group['fields'] ) ) {
					continue;
				}

				foreach ( $group['fields'] as $field ) {
					if ( false === PodsForm::permission( $field['type'], $field['name'], $field, $group['fields'], $pod, $id ) ) {
						if ( ! pods_v( 'hidden', $field['options'], false ) ) {
							continue;
						}
					}

					$data[ $field['name'] ] = '';

					if ( isset( $_POST[ 'pods_meta_' . $field['name'] ] ) ) {
						$data[ $field['name'] ] = $_POST[ 'pods_meta_' . $field['name'] ];
					}
				}
			}

			if ( $is_new_item ) {
				do_action( 'pods_meta_create_pre_user', $data, $pod, $id, $groups );
			}

			do_action( 'pods_meta_save_pre_user', $data, $pod, $id, $groups, $is_new_item );
		}

		if ( $is_new_item || false !== $nonced ) {
			pods_no_conflict_on( 'user' );

			if ( ! empty( $pod ) ) {
				// Fix for Pods doing it's own sanitizing
				$data = pods_unslash( (array) $data );

				$pod->save( $data, null, null, array( 'is_new_item' => $is_new_item, 'podsmeta' => true ) );
			} elseif ( ! empty( $id ) ) {
				foreach ( $data as $field => $value ) {
					update_user_meta( $id, $field, $value );
				}
			}

			pods_no_conflict_off( 'user' );
		}

		if ( false !== $nonced && ! empty( $groups ) ) {
			if ( $is_new_item ) {
				do_action( 'pods_meta_create_user', $data, $pod, $id, $groups );
			}

			do_action( 'pods_meta_save_user', $data, $pod, $id, $groups, $is_new_item );
		}

	}
1206280
public static function addUserToGroup($user_id, $group_id)
	{
		// Get the user's existing entries
		$entries = self::all()
			->whereEquals('user_id', $user_id)
			->rows();

		$existing = array();
		foreach ($entries as $entry)
		{
			$existing[] = $entry->get('group_id');
		}

		$group_id = (is_array($group_id) ? $group_id : array($group_id));

		$blank = self::blank();

		// Loop through groups to be added
		foreach ($group_id as $group)
		{
			$group = intval($group);

			// Is the group already an existing entry?
			if (in_array($group, $existing))
			{
				// Skip.
				continue;
			}

			$query = $blank->getQuery()
				->insert($blank->getTableName())
				->values(array(
					'user_id'  => $user_id,
					'group_id' => $group
				));

			if (!$query->execute())
			{
				return false;
			}
		}

		return true;
	}
382956
public function updateUserAsync($user_id, $payload_account)
    {
        return $this->updateUserAsyncWithHttpInfo($user_id, $payload_account)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }
639178
public function updateUser(User $user)
    {
        $request = $user->toJson();
        $this->client->put(sprintf('/v2/user/%s', $user->getId()), $request);
    }
1316820
public function Merge($OldUserID, $NewUserID) {
      $OldUser = $this->GetID($OldUserID, DATASET_TYPE_ARRAY);
      $NewUser = $this->GetID($NewUserID, DATASET_TYPE_ARRAY);
      
      if (!$OldUser || !$NewUser) {
         throw new Gdn_UserException("Could not find one or both users to merge.");
      }
      
      $Map = array('UserID', 'Name', 'Email', 'CountVisits', 'CountDiscussions', 'CountComments');
      
      $Result = array('MergeID' => NULL, 'Before' => array(
         'OldUser' => ArrayTranslate($OldUser, $Map),
         'NewUser' => ArrayTranslate($NewUser, $Map)));
      
      // Start the merge.
      $MergeID = $this->MergeStart($OldUserID, $NewUserID);
      
      // Copy all discussions from the old user to the new user.
      $this->MergeCopy($MergeID, 'Discussion', 'InsertUserID', $OldUserID, $NewUserID);
      
      // Copy all the comments from the old user to the new user.
      $this->MergeCopy($MergeID, 'Comment', 'InsertUserID', $OldUserID, $NewUserID);
      
      // Copy all of the activities.
      $this->MergeCopy($MergeID, 'Activity', 'NotifyUserID', $OldUserID, $NewUserID);
      $this->MergeCopy($MergeID, 'Activity', 'InsertUserID', $OldUserID, $NewUserID);
      $this->MergeCopy($MergeID, 'Activity', 'ActivityUserID', $OldUserID, $NewUserID);
      
      // Copy all of the activity comments.
      $this->MergeCopy($MergeID, 'ActivityComment', 'InsertUserID', $OldUserID, $NewUserID);
      
      // Copy all conversations.
      $this->MergeCopy($MergeID, 'Conversation', 'InsertUserID', $OldUserID, $NewUserID);
      $this->MergeCopy($MergeID, 'ConversationMessage', 'InsertUserID', $OldUserID, $NewUserID, 'MessageID');
      $this->MergeCopy($MergeID, 'UserConversation', 'UserID', $OldUserID, $NewUserID, 'ConversationID');
      
      $this->MergeFinish($MergeID);
      
      $OldUser = $this->GetID($OldUserID, DATASET_TYPE_ARRAY);
      $NewUser = $this->GetID($NewUserID, DATASET_TYPE_ARRAY);
      
      $Result['MergeID'] = $MergeID;
      $Result['After'] = array(
         'OldUser' => ArrayTranslate($OldUser, $Map),
         'NewUser' => ArrayTranslate($NewUser, $Map));
      
      return $Result;
   }
1244956
public function updateUser(User $user, UserUpdater $up)
    {
        $up->updateUser($user, $this->getEncoder());
        $em = $this->getRegistry()->getManager();
        $em->persist($user);
        $em->flush();
    }
670327
public function change_password($old_password, $new_password, $username = null)
	{
		try
		{
			return (bool) $this->update_user(array('old_password' => $old_password, 'password' => $new_password), $username);
		}
		// Only catch the wrong password exception
		catch (SimpleUserWrongPassword $e)
		{
			return false;
		}
	}
421324
protected function setUser(array $userData, & $user = null)
    {
        // Generic birthdate parsing
        $user->birthday = date('Y-m-d H:i:s', strtotime($user->birthday));

        // If no external user is passed set as current user
        if (isset($user)) {
            $this->user = & $user;
        }
    }
1062209
protected function updateUsers()
    {
        $user_id = $this->getAuthUserId();
        if (!($user_id > 0)) {
            return;
        }

        if (!$this->isDirty('updated_by')) {
            $this->updated_by = $user_id;
        }

        if (!$this->exists && !$this->isDirty('created_by')) {
            $this->created_by = $user_id;
        }
    }
524592
def update_user(id, user, opts = {})
      data, _status_code, _headers = update_user_with_http_info(id, user, opts)
      return data
    end
268635
public function save(Userinfo $userinfo, Userinfo $olduserinfo = null, $new = false)
	{
		$this->debugger->set(null, array());

		//create an array to store the debug info
		$debug_info = array();
		$error_info = array();


		$plugins = Factory::getPlugins();

		if ($userinfo instanceof Userinfo) {
			// Recover the old data of the user
			// This is then used to determine if the username was changed
			$updateUsername = false;

			if ($userinfo->getJname() !== null && $olduserinfo->getJname() !== null) {
				if ($new == false && $userinfo instanceof Userinfo && $olduserinfo instanceof Userinfo) {
					if ($userinfo->getJname() == $olduserinfo->getJname() && $userinfo->username != $olduserinfo->username) {
						$updateUsername = true;
					}
				}
			}
			$exsistingUser = User::search($olduserinfo, true);

			foreach ($plugins as $plugin) {
				try {
					$userPlugin = Factory::getUser($plugin->name);
					if ($userPlugin->validateUser($userinfo)) {
						if ($updateUsername) {
							if ($exsistingUser instanceof Userinfo) {
								$pluginUserinfo = $userPlugin->getUser($exsistingUser);

								if ($pluginUserinfo instanceof Userinfo) {
									try {
										$userPlugin->resetDebugger();
										$userPlugin->updateUsername($userinfo, $pluginUserinfo);
										if (!$userPlugin->debugger->isEmpty('error')) {
											$error_info[$plugin->name . ' ' . Text::_('USERNAME') . ' ' . Text::_('UPDATE') . ' ' . Text::_('ERROR') ] = $userPlugin->debugger->get('error');
										}
										if (!$userPlugin->debugger->isEmpty('debug')) {
											$debug_info[$plugin->name . ' ' . Text::_('USERNAME') . ' ' . Text::_('UPDATE') . ' ' . Text::_('DEBUG') ] = $userPlugin->debugger->get('debug');
										}
									} catch (Exception $e) {
										$status[LogLevel::ERROR][] = Text::_('USERNAME_UPDATE_ERROR') . ': ' . $e->getMessage();
									}
								} else {
									$error_info[$plugin->name] = Text::_('NO_USER_DATA_FOUND');
								}
							}
						}
						//run the update user to ensure any other userinfo is updated as well
						$userPlugin->resetDebugger();
						$pluginUserinfo = $userPlugin->updateUser($userinfo, 1);
						$debug = $userPlugin->debugger->get();

						if (!empty($debug[LogLevel::ERROR])) {
							$error_info[$plugin->name] = $debug[LogLevel::ERROR];
						}
						if (!empty($debug[LogLevel::DEBUG])) {
							$debug_info[$plugin->name] = $debug[LogLevel::DEBUG];
						}
						if (!$pluginUserinfo instanceof Userinfo) {
							//make sure the userinfo is available
							$pluginUserinfo = $userPlugin->getUser($userinfo);
						}
						//update the jfusion_users table
						if ($pluginUserinfo instanceof Userinfo) {
							$userPlugin->updateLookup($pluginUserinfo, $userinfo);
						}
					}
				} catch (Exception $e) {
					$error_info[$plugin->name] = array($e->getMessage());
				}
			}
		}
		$this->debugger->set('debug', $debug_info);
		$this->debugger->set('error', $error_info);
		return true;
	}
623991
public static function destroyByUser($user_id)
	{
		$user_id = (is_array($user_id) ? $user_id : array($user_id));

		$blank = self::blank();

		$query = $blank->getQuery()
			->delete($blank->getTableName())
			->whereIn('user_id', $user_id);

		if (!$query->execute())
		{
			return false;
		}

		return true;
	}
57548
function user_context($data, $merge=true)
    {
        if ($merge && $this->context->user !== null) {
            // bail if data is null
            if (!$data) {
                return;
            }
            $this->context->user = array_merge($this->context->user, $data);
        } else {
            $this->context->user = $data;
        }
    }
863468
public function userSave($value, int $user_id)
    {
        $this->setValue($value);

        if (! $this->getOption('multiple', false)) {
            $this->saveUserSingleValue($this->getRawValue(), $user_id);
        } else {
            $this->saveUserMultipleValue($this->getRawValue(), $user_id);
        }
    }
837446
public void addUserToCache(User user) {
        users.compute(user.getId(), (key, value) -> {
            Optional.ofNullable(value)
                    .map(Reference::get)
                    .filter(oldUser -> oldUser != user)
                    .map(Cleanupable.class::cast)
                    .ifPresent(Cleanupable::cleanup);

            WeakReference<User> result = new WeakReference<>(user, usersCleanupQueue);
            userIdByRef.put(result, key);
            return result;
        });
    }
754150
public function deleted(User $user)
    {
        \DB::table((new Revision())->getTable())->insert([
            [
                'revisionable_type' => $user->getMorphClass(),
                'revisionable_id' => $user->id,
                'key' => 'deleted_at',
                'old_value' => $user,
                'new_value' => new \DateTime(),
                'user_id' => (\Auth::check() ? \Auth::user()->id : null),
                'created_at' => new \DateTime(),
                'updated_at' => new \DateTime(),
            ]
        ]);
    }
1061449
public function setNewActiveContributionToSection(User $user = null)
    {
        $oldActiveContribution = $this->getActiveContribution();
        $newActiveContribution = new Contribution();
        $newActiveContribution->setSection($this);
        if (null === $oldActiveContribution) {
            if (null === $user) {
                $user = $this->getAuthor();
            }
        } else {
            if (null === $user) {
                $user = $oldActiveContribution->getContributor();
            }
            if (null === $user) {
                $user = $this->getAuthor();
            }
            $newActiveContribution->setTitle($oldActiveContribution->getTitle());
            $newActiveContribution->setText($oldActiveContribution->getText());
        }
        $newActiveContribution->setContributor($user);
        $this->setActiveContribution($newActiveContribution);
    }