Elgg  Version 5.1
ban.php
Go to the documentation of this file.
1 <?php
6 $user_guids = (array) get_input('user_guids');
7 if (empty($user_guids)) {
8  return elgg_error_response(elgg_echo('error:missing_data'));
9 }
10 
11 /* @var $users \ElggBatch */
13  'type' => 'user',
14  'guids' => $user_guids,
15  'limit' => false,
16  'batch' => true,
17  'batch_inc_offset' => false,
18  'metadata_name_value_pairs' => [
19  'banned' => 'no',
20  ],
21 ]);
22 
23 /* @var $user \ElggUser */
24 $count = 0;
25 foreach ($users as $user) {
26  if ($user->guid === elgg_get_logged_in_user_guid()) {
27  // can't ban yourself
28  $users->reportFailure();
29  continue;
30  }
31 
32  if ($user->ban('admin')) {
33  $count++;
34  } else {
35  $users->reportFailure();
36  }
37 }
38 
39 return elgg_ok_response('', elgg_echo('action:admin:user:bulk:ban', [$count]));
$user_guids
Bulk ban users.
Definition: ban.php:6
if(empty($user_guids)) $users
Definition: ban.php:12
elgg_ok_response($content= '', string|array $message= '', string $forward_url=null, int $status_code=ELGG_HTTP_OK)
Prepares a successful response to be returned by a page or an action handler.
elgg_echo(string $message_key, array $args=[], string $language= '')
Elgg language module Functions to manage language and translations.
Definition: languages.php:17
get_input(string $variable, $default=null, bool $filter_result=true)
Parameter input functions.
Definition: input.php:20
elgg_error_response(string|array $message= '', string $forward_url=REFERRER, int $status_code=ELGG_HTTP_BAD_REQUEST)
Prepare an error response to be returned by a page or an action handler.
elgg_get_entities(array $options=[])
Fetches/counts entities or performs a calculation on their properties.
Definition: entities.php:504
$user
Definition: ban.php:7
$count
Definition: ban.php:24
elgg_get_logged_in_user_guid()
Return the current logged in user by guid.
Definition: sessions.php:34