Alias user roles 'all' and 'all-not-admin'
Replace short-hand 'admin' with 'administrator'

@param string|array $args
@return string|array
434463
protected function aliasUserRoles($args)
    {
        if (in_array('all', $args)) {
            $args = $this->getUserRoles();
        }
        if (in_array('all-not-admin', $args)) {
            $args = $this->getUserRoles(false);
        }
        $args = preg_replace('/\badmin\b/', 'administrator', $args);
        return $args;
    }
1322749
protected function filterServer(array $args): array
    {
        return Collection::make($args)->filter(function ($item) {
            return !($item instanceof \Swoole\Server);
        })->toArray();
    }
257897
public function loginStyleAccessManagement($args)
    {
        if (!$args) {
            return;
        }

        // Define defaults
        $configs = array_merge([
            'scripts'   => [],
            'styles'    => [],
        ], $args);

        // Render assets

        add_action('login_enqueue_scripts', function () use ($configs) {
            if (!empty($configs['scripts'])) {
                return;
            }

            foreach ($configs['scripts'] as $script) {
                if (3 !== count($script)) {
                    continue;
                }

                wp_enqueue_script($script[0], $script[1], $script[2]);
            }
        }, 10);

        add_action('login_enqueue_scripts', function () use ($configs) {
            if (!empty($configs['styles'])) {
                return;
            }

            foreach ($configs['styles'] as $style) {
                if (3 !== count($style)) {
                    continue;
                }

                wp_enqueue_style($style[0], $style[1], $style[2]);
            }
        }, 9);
    }
1167537
public static function keyMatch2Func(...$args)
    {
        $name1 = $args[0];
        $name2 = $args[1];

        return self::keyMatch2($name1, $name2);
    }
1199219
public static function prepareCommand(array $args)
    {
        $return = '*' . \count($args) . "\r\n";
        foreach ($args as $arg) {
            $return .= '$' . \strlen($arg) . "\r\n" . $arg . "\r\n";
        }

        return $return;
    }
520797
public function add_role( $args, $assoc_args ) {
		$user = $this->fetcher->get_check( $args[0] );

		$role = $args[1];

		self::validate_role( $role );

		$user->add_role( $role );

		WP_CLI::success( "Added '{$role}' role for {$user->user_login} ({$user->ID})." );
	}
530855
public function where(...$args): AliasDecorator
    {
        if ($args[0] instanceof \Closure) {
            call_user_func($args[0], $this);

            return $this;
        }

        //We have to prepare only first argument
        $args[0] = $this->prepare($args[0]);

        //Routing where
        call_user_func_array([$this->query, $this->target], $args);

        return $this;
    }
958950
public function adminMetaBoxesSetting($args)
    {
        if (empty($args)) {
            return;
        }

        add_action('wp_dashboard_setup', function () use ($args) {
            // Iterate on all
            foreach ($args as $widget) {
                if (!is_array($widget)) {
                    continue;
                }

                $count = count($widget);

                if (3 > $count) {
                    continue;
                }

                // Remove item
                if (3 === $count) {
                    $plugin = $widget[0];
                    $page = $widget[1];
                    $column = $widget[2];

                    remove_meta_box($plugin, $page, $column);
                } else if (4 <= $count && 'add' === $widget[0]) {
                    // Add item
                    $id = $widget[1];
                    $title = $widget[2];
                    $content = $widget[3];
                    $control = isset($widget[4]) ? $widget[4] : null;
                    $callback_args = isset($widget[5]) && is_array($widget[5]) ? $widget[5] : null;

                    wp_add_dashboard_widget($id, $title, function () use ($content) {
                        echo $content;
                    }, $control, $callback_args);
                }
            }
        });
    }
40623
public function selectOptions(array $args = []): string
    {
        // Establish args.

        $default_args = [
            // Unique.
            'allow_empty'      => true,
            'allow_arbitrary'  => true,
            'option_formatter' => null,
            'current_roles'    => null,

            // Used by {@link all()}.
            'max'         => 1000,
            'fail_on_max' => true,

            // Used by {@link total()}.
            // Used by {@link all()}.
            'include'  => [],
            'exclude'  => [],
            'no_cache' => false,
        ];
        $args = array_merge($default_args, $args);
        $args = array_intersect_key($args, $default_args);

        // Unique.
        $args['allow_empty']      = (bool) $args['allow_empty'];
        $args['allow_arbitrary']  = (bool) $args['allow_arbitrary'];
        $args['option_formatter'] = is_callable($args['option_formatter']) ? $args['option_formatter'] : null;
        $args['current_roles']    = isset($args['current_roles']) ? (array) $args['current_roles'] : null;
        $args['current_roles']    = $this->c::removeEmptys(array_map('strval', $args['current_roles']));

        // Used by {@link all()}.
        $args['max']         = max(1, (int) $args['max']);
        $args['fail_on_max'] = (bool) $args['fail_on_max'];

        // Used by {@link total()}.
        // Used by {@link all()}.
        $args['include']  = (array) $args['include'];
        $args['exclude']  = (array) $args['exclude'];
        $args['no_cache'] = (bool) $args['no_cache'];

        // Check for nothing being available (or too many).

        if (!($roles = $this->all($args))) {
            return ''; // None available.
        }
        // Initialize several working variables.

        $options         = ''; // Initialize.
        $available_roles = []; // Initialize.
        $selected_roles  = []; // Initialize.

        // Build & return all `<option>` tags.

        if ($args['allow_empty']) { // Allow ``?
            $options = '<option value=""></option>';
        }
        foreach ($roles as $_role_id => $_role) { // Array of data.
            $available_roles[] = $_role_id; // Record all available.

            if (isset($args['current_roles']) && in_array($_role_id, $args['current_roles'], true)) {
                $selected_roles[$_role_id] = $_role_id; // Flag selected role.
            }
            $_role_label         = !empty($_role['name']) ? $_role['name'] : $_role_id;
            $_role_selected_attr = isset($selected_roles[$_role_id]) ? ' selected' : '';

            // Format `<option>` tag w/ a custom formatter?

            if ($args['option_formatter']) {
                $options .= $args['option_formatter']($_role_id, [
                        'role_label'         => $_role_label,
                        'role_selected_attr' => $_role_selected_attr,
                    ], $args); // ↑ This allows for a custom option formatter.
                    // The formatter must always return an `<option></option>` tag.

            // Else format the `<option>` tag using a default behavior.
            } else { // Both front & back-end displays are the same for roles.
                $options .= '<option value="'.esc_attr($_role_id).'"'.$_role_selected_attr.'>'.
                                esc_html($_role_label).
                            '</option>';
            }
        } // unset($_role_id, $_role, $_role_label, $_role_selected_attr); // Housekeeping.

        if ($args['allow_arbitrary'] && $args['current_roles']) { // Allow arbitrary select `<option>`s?
            foreach (array_diff($args['current_roles'], $available_roles) as $_arbitrary_role_id) {
                $options .= '<option value="'.esc_attr($_arbitrary_role_id).'" selected>'.
                                esc_html($_arbitrary_role_id).
                            '</option>';
            } // unset($_arbitrary_role_id); // Housekeeping.
        }
        return $options; // HTML markup.
    }
351886
protected function getEnvironmentArgument(array $args)
	{
		foreach ($args as $k => $v)
		{
			if (substr($v, 0, strlen('--env')) == '--env')
			{
				return $v;
			}
		}

		return null;
	}
100907
private function resolveArgs(array $args)
    {
        $resolved = [];
        foreach ($args as $argDefinition) {
            switch ($argDefinition['type']) {
                case 'lookup':
                    $resolved[] = $this->lookupRecursive($argDefinition['item']);
                    break;
                case 'value':
                    $resolved[] = $argDefinition['item'];
                    break;
            }
        }

        return $resolved;
    }
784676
public function setOptions(array $args)
    {

    	$this->options = $args += [
			'filters'    => [],
			'name'      => null,
			'namespace' => null,
			'prefix'    => null,
    	];

    	$args['namespace'] && $this->setNamespace($args['namespace']);

    	$args['prefix'] && $this->setPrefixPath($args['prefix']);

    	$args['name'] && $this->setPrefixName($args['name']);

    	$args['filters'] && $this->setDefaultFilters($args['filters']);

    	return $this;
    }
1122749
protected function getExistingMatchingUser(array $args)
    {
        $user_id = $this->getUserIdFromLogin($args['user_login']);
        $user    = $this->getDriver()->user->get($user_id);

        /* users can have more than one role so needs to be a special case */
        if (array_key_exists('role', $args)) {
            $this->checkUserHasRole($user, $args['role']);
        }

        /*
         * Loop through each of the passed arguements.
         * if they are arguments which apply to users
         * then check that that which exist matches that which was specified.
         */
        foreach ($args as $parameter => $value) {
            if ($parameter === 'password') {
                continue;
            }

            if ($this->isValidUserParameter($parameter) && $user->$parameter !== $args[$parameter]) {
                throw new UnexpectedValueException('[W804] User with login: ' . $user->user_login . 'exists, but ' . $parameter . ' is ' . $user->$parameter . ' not ' . $args[$parameter] . 'which was specified');
            }
        }

        return $user;
    }
896261
public function mailAdmins($config)
    {
        $admins = $this->getService('repos:people.person')
                       ->fetchSet(array(
                           'usertype' => ComPeopleDomainEntityPerson::USERTYPE_SUPER_ADMINISTRATOR
                       ));

        $mails = array();

        foreach($admins as $admin) {
           $mails[] = array(
               'subject' => $config['subject'],
               'template' => $config['template'],
               'to' => $admin->email
           );
        }

        return $this->mail($mails);
    }
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];
	}
1014292
public function deleteUser($args)
    {
        // Get dependencies
        $userMapper = ($this->container->dataMapper)('UserMapper');

        // Delete user
        $User = $userMapper->make();
        $User->id = $args['id'];
        $userMapper->delete($User);

        // Redirect back to list of users
        return $this->redirect('adminUsers');
    }
1038583
protected function shortNames($arg)
    {
        if (!$this->isOption($arg) || $this->isLongOption($arg)) {
            return [];
        }

        return array_map(function ($i) use ($arg) {
            return mb_substr($arg, $i, 1);
        }, range(1, mb_strlen($arg) -1));
    }