Elgg  Version 6.3
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  if (elgg_get_config('security_notify_user_ban')) {
34  // this can't be handled by the delayed notification system as it won't send notifications to banned users
35  $user->notify('ban', $user);
36  }
37 
38  $count++;
39  } else {
40  $users->reportFailure();
41  }
42 }
43 
44 return elgg_ok_response('', elgg_echo('action:admin:user:bulk:ban', [$count]));
$user
Definition: ban.php:7
if(empty($user_guids)) $users
Definition: ban.php:12
$user_guids
Bulk ban users.
Definition: ban.php:6
$count
Definition: ban.php:24
elgg_get_config(string $name, $default=null)
Get an Elgg configuration value.
get_input(string $variable, $default=null, bool $filter_result=true)
Parameter input functions.
Definition: input.php:20
elgg_get_entities(array $options=[])
Fetches/counts entities or performs a calculation on their properties.
Definition: entities.php:507
elgg_echo(string $message_key, array $args=[], string $language='')
Elgg language module Functions to manage language and translations.
Definition: languages.php:17
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_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_logged_in_user_guid()
Return the current logged in user by guid.
Definition: sessions.php:34