All users.

@since 160524 User utils.

@param array $args Behavioral args.

@return \WP_User[] Array of users.
16091
public function all(array $args = []): array
    {
        // Establish args.

        $default_args = [
            // Unique.
            'max'         => PHP_INT_MAX,
            'fail_on_max' => false,

            // Also used by {@link total()}.
            'filters' => [
                'orderby' => 'display_name',
            ],
            'no_cache' => false,
        ];
        $args = array_merge($default_args, $args);
        $args = array_intersect_key($args, $default_args);

        // Unique.
        $args['max']         = max(1, (int) $args['max']);
        $args['fail_on_max'] = (bool) $args['fail_on_max'];

        // Also used by {@link total()}.
        $args['filters']  = (array) $args['filters'];
        $args['no_cache'] = (bool) $args['no_cache'];

        // Check cache; already did this query?

        $cache_keys = $args; // Keys to consider when checking the cache.
        unset($cache_keys['no_cache']); // Cache key exclusions.

        if (($users = &$this->cacheKey(__FUNCTION__, $cache_keys)) !== null && !$args['no_cache']) {
            return $users; // Already cached this.
        }
        // Automatically fail if there are too many; when/if desirable.

        if ($args['fail_on_max'] && $this->total($args) > $args['max']) {
            return $users = []; // Fail; too many.
        }
        // Return the array of all user objects now.

        $WP_User_Query = new \WP_User_Query(array_merge($args['filters'], [
            'fields' => 'all_with_meta', 'offset' => 0, 'paged' => 1, 'number' => -1, 'count_total' => true,
        ]));
        return $users = $WP_User_Query->get_results();
    }
445605
public function showusers($req, $res, $args)
    {
        Container::get('hooks')->fire('controller.admin.users.showusers');

        $search_ip = $args['ip'];

        if (!@preg_match('%^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$%', $search_ip) &&
            !@preg_match('%^((([0-9A-Fa-f]{1,4}:){7}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){6}:'.
                '[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){5}:([0-9A-Fa-f]{1,4}:)?[0-9A-Fa-f]{1,4})|'.
                '(([0-9A-Fa-f]{1,4}:){4}:([0-9A-Fa-f]{1,4}:){0,2}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){3}:'.
                '([0-9A-Fa-f]{1,4}:){0,3}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){2}:([0-9A-Fa-f]{1,4}:)'.
                '{0,4}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){6}((\b((25[0-5])|(1\d{2})|(2[0-4]\d)|'.
                '(\d{1,2}))\b)\.){3}(\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b))|(([0-9A-Fa-f]{1,4}:)'.
                '{0,5}:((\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b)\.){3}(\b((25[0-5])|(1\d{2})|'.
                '(2[0-4]\d)|(\d{1,2}))\b))|(::([0-9A-Fa-f]{1,4}:){0,5}((\b((25[0-5])|(1\d{2})|(2[0-4]\d)|'.
                '(\d{1,2}))\b)\.){3}(\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b))|([0-9A-Fa-f]{1,4}::'.
                '([0-9A-Fa-f]{1,4}:){0,5}[0-9A-Fa-f]{1,4})|(::([0-9A-Fa-f]{1,4}:){0,6}[0-9A-Fa-f]{1,4})|'.
                '(([0-9A-Fa-f]{1,4}:){1,7}:))$%', $search_ip)) {
            throw new  RunBBException(__('Bad IP message'), 400);
        }

        // Fetch user count
        $num_users = $this->model->getNumUsersIp($search_ip);

        // Determine the user offset (based on $_GET['p'])
        $num_pages = ceil($num_users / 50);

        $p = (!Input::query('p') || Input::query('p') <= 1 || Input::query('p') > $num_pages) ?
            1 : intval(Input::query('p'));
        $start_from = 50 * ($p - 1);

        return View::setPageInfo([
            'title' => [Utils::escape(ForumSettings::get('o_board_title')), __('Admin'),
                __('Users'), __('Results head')],
            'active_page' => 'admin',
            'admin_console' => true,
            'paging_links' => '<span class="pages-label">' . __('Pages') . ' </span>' .
                Url::paginateOld($num_pages, $p, '?ip_stats=' . $search_ip),
            'page' => $p,
            'start_from' => $start_from,
            'info' => $this->model->getInfoPoster($search_ip, $start_from),
        ])->display('@forum/admin/users/show_users');
    }
20296
public function url( array $args = [] ) {
		$url = get_author_posts_url( $this->ID );
		if ( $args ) {
			$url = add_query_arg( $args, $url );
		}

		return $url;
	}
792044
public function get_all_objects( $args, $attached = array() ) {
		$objects = $this->get_objects( $args );

		$attached_objects = array();
		foreach ( $objects as $object ) {
			$attached_objects[ $this->get_id( $object ) ] = $object;
		}

		if ( ! empty( $attached ) ) {
			$is_users = $this->field->options( 'query_users' );
			$args[ $is_users ? 'include' : 'post__in' ] = $attached;
			$args[ $is_users ? 'number' : 'posts_per_page' ] = count( $attached );

			$new = $this->get_objects( $args );

			foreach ( $new as $object ) {
				if ( ! isset( $attached_objects[ $this->get_id( $object ) ] ) ) {
					$attached_objects[ $this->get_id( $object ) ] = $object;
				}
			}
		}

		return $attached_objects;
	}
362147
public function children( array $args = []) {
        $args = wp_parse_args( $args, [
            'parent'  => $this->ID,
            'fields'  => 'ids',
            'orderby' => 'comment_date_gmt',
            'order'   => 'ASC'
        ] );

        $query = new WP_Comment_Query;
        return $query->query( $args );
    }
520318
protected function _users()
    {
        if (CommonFunctions::executeProgram('who', '', $strBuf, PSI_DEBUG)) {
            if (strlen($strBuf) > 0) {
                $lines = preg_split('/\n/', $strBuf);
                $this->sys->setUsers(count($lines));
            }
        } elseif (CommonFunctions::executeProgram('uptime', '', $buf, PSI_DEBUG) && preg_match("/,\s+(\d+)\s+user[s]?,/", $buf, $ar_buf)) {
        //} elseif (CommonFunctions::executeProgram('uptime', '', $buf) && preg_match("/,\s+(\d+)\s+user[s]?,\s+load average[s]?:\s+(.*),\s+(.*),\s+(.*)$/", $buf, $ar_buf)) {
            $this->sys->setUsers($ar_buf[1]);
        } else {
            $processlist = glob('/proc/*/cmdline', GLOB_NOSORT);
            if (is_array($processlist) && (($total = count($processlist)) > 0)) {
                $count = 0;
                $buf = "";
                for ($i = 0; $i < $total; $i++) {
                    if (CommonFunctions::rfts($processlist[$i], $buf, 0, 4096, false)) {
                        $name = str_replace(chr(0), ' ', trim($buf));
                        if (preg_match("/^-/", $name)) {
                            $count++;
                        }
                    }
                }
                if ($count > 0) {
                    $this->sys->setUsers($count);
                }
            }
        }
    }
820074
public function getUsers() {
        $routeUser = $this->getUser();
        $queryUsers = $this->query->get('users', []);

        if (!$routeUser && !$queryUsers) {
            return [];
        } elseif (!$queryUsers) {
            return [$routeUser];
        } elseif (!$routeUser) {
            return $queryUsers;
        }

        return array_merge([$routeUser], $queryUsers);
    }
753073
public function userEnqueue($markup, array $args = [])
    {
        if (!isset($args['for_user_id'])) {
            $args['for_user_id'] = (int) get_current_user_id();
        }
        if (!$args['for_user_id']) {
            return; // Nothing to do.
        }
        $this->enqueue($markup, $args);
    }
806053
public function getUsers($options = [])
    {
        $query_params = [];

        if (!empty($options['from_timestamp'])) {
            $query_params['from_ts'] = $options['from_timestamp'];
        }

        if (!empty($options['limit'])) {
            $query_params['limit'] = $options['limit'];
        }

        return $this->apiRequest([
            'method' => 'GET',
            'path' => '/users',
            'jwt' => $this->getServerToken()['token'],
            'query' => $query_params
        ]);
    }
1070370
public function create($args)
    {
        $extra_roles = [];

        // Store multiple roles; WP can only assign one on user creation.
        if (! empty($args['role'])) {
            if (! is_array($args['role'])) {
                $args['role'] = array_map('trim', explode(',', $args['role']));
            }

            $extra_roles  = $args['role'];
            $args['role'] = array_shift($extra_roles);
        }

        $args    = wp_slash($args);
        $user_id = wp_insert_user($args);

        if (is_wp_error($user_id)) {
            throw new UnexpectedValueException(sprintf('[W615] Failed creating new user: %s', $user_id->get_error_message()));
        }

        $wp_user = get_user_by('ID', $user_id);

        // Assign any extra roles.
        foreach ($extra_roles as $role) {
            $wp_user->add_role($role);
        }

        return $this->get($user);
    }
1033162
public function log(...$args)
    {
        foreach ($this->loggers as $callback) {
            call_user_func_array($callback, $args);
        }

        return $this;
    }
1251044
protected function getSplatCallVars($args)
    {
        $isSplatCall = false;
        $variables = [];
        foreach ($args as $arg) {
            if ($arg->unpack) {
                $isSplatCall = true;
            }
            $variables[] = $arg->value;
        }
        if (! $isSplatCall) {
            return;
        }
        return $variables;
    }
1198621
public function add( $args, $_ ) {

		$successes = 0;
		$errors    = 0;
		$users     = $this->fetcher->get_many( $args );
		if ( count( $users ) !== count( $args ) ) {
			$errors = count( $args ) - count( $users );
		}
		$user_logins      = wp_list_pluck( $users, 'user_login' );
		$super_admins     = self::get_admins();
		$num_super_admins = count( $super_admins );

		foreach ( $user_logins as $user_login ) {
			if ( in_array( $user_login, $super_admins, true ) ) {
				WP_CLI::warning( "User '{$user_login}' already has super-admin capabilities." );
				continue;
			}

			$super_admins[] = $user_login;
			$successes++;
		}

		if ( count( $super_admins ) === $num_super_admins ) {
			if ( $errors ) {
				$user_count = count( $args );
				WP_CLI::error( "Couldn't grant super-admin capabilities to {$errors} of {$user_count} users." );
			} else {
				WP_CLI::success( 'Super admins remain unchanged.' );
			}
		} else {
			if ( update_site_option( 'site_admins', $super_admins ) ) {
				if ( $errors ) {
					$user_count = count( $args );
					WP_CLI::error( "Only granted super-admin capabilities to {$successes} of {$user_count} users." );
				} else {
					$message = $successes > 1 ? 'users' : 'user';
					WP_CLI::success( "Granted super-admin capabilities to {$successes} {$message}." );
				}
			} else {
				WP_CLI::error( 'Site options update failed.' );
			}
		}
	}
418807
public function make(array $args = array()) {
        $userModel = new Model_User();
        if (!empty($args)) {
            $id = $args[0];
        } else {
            $id = Garp_Cli::prompt('What is the id or email address of the user?');
        }
        $select = $userModel->select();
        if (is_numeric($id)) {
            $filterColumn = 'id';
        } else {
            $filterColumn = 'email';
        }
        $select->where($filterColumn . ' = ?', $id);
        $user = $userModel->fetchRow($select);
        if (!$user) {
            Garp_Cli::errorOut('Error: could not find user with ' . $filterColumn . ' ' . $id);
        } else {
            $user->role = 'admin';
            if ($user->save()) {
                // For completeness sake, check if the user has an AuthLocal
                // record. We disregard the fact wether the user already has any
                // of the other Auth- records.
                $authLocalModel = new Model_AuthLocal();
                $authLocalRecord = $authLocalModel->fetchRow(
                    $authLocalModel->select()->where('user_id = ?', $user->id)
                );
                if (!$authLocalRecord) {
                    $newAuthLocalData = array(
                        'password' => trim(Garp_Cli::prompt('Choose a password:')),
                        'user_id'  => $user->id
                    );
                    $authLocalModel->insert($newAuthLocalData);
                }
                Garp_Cli::lineOut(
                    'User with ' . $filterColumn . ' ' . $id .
                    ' is now administrator'
                );
            } else {
                Garp_Cli::errorOut(
                    'Error: could not make user with ' . $filterColumn . ' ' . $id .
                    ' administrator'
                );
            }
        }
    }
969931
public static function evaluateArgs(array $args)
    {

        $parsedArgs = [];

        foreach ($args as $key=>$value) {

            if ($value instanceof self) {
                $parsedArgs[$key] = static::callFast($value);
                continue;
            }
            $parsedArgs[$key] = $args[$key];
        }

        return $parsedArgs;

    }
592509
public function adm_delete_user($args) {
		if (!$this->store_is_logged_in())
			return [AdminStoreError::USER_NOT_LOGGED_IN];

		if (!isset($args['post']))
			return [AdminStoreError::DATA_INCOMPLETE];
		if (!Common::check_idict($args['post'], ['uid']))
			return [AdminStoreError::DATA_INCOMPLETE];
		extract($args['post']);

		if (!$this->authz_delete_user($uid))
			return [AdminStoreError::USER_NOT_AUTHORIZED];

		# cannot delete root
		if ($uid == 1)
			return [AdminStoreError::USER_NOT_AUTHORIZED];

		if (!$this->store->query(
			"SELECT uid FROM udata WHERE uid=? LIMIT 1",
			[$uid])
		) {
			# user does not exist
			$this->logger->warning(sprintf(
				"Zapmin: usrdel: not found: uid=%s.",
				$uid
			));
			return [AdminStoreError::USER_NOT_FOUND];
		}

		# delete user data and its related session history via
		# foreign key constraint
		$this->store->delete('udata', ['uid' => $uid]);

		# in case of self-delete, router must send redirect header
		# or location.reload from the client side
		$this->logger->info(sprintf(
			"Zapmin: usrdel successful: uid=%s.",
			$uid
		));
		return [0];
	}
509599
private function getParams(array $args)
    {
        if (count($args) == 0) {
            return [];
        }

        $params = array_slice($args, -1)[0];

        return is_array($params) ? $params : [];
    }