Skip to content

Instantly share code, notes, and snippets.

@julien-gargot
Created May 24, 2017 14:36
Show Gist options
  • Save julien-gargot/83d5315d55c7e17a4e08f705ad4b6deb to your computer and use it in GitHub Desktop.
Save julien-gargot/83d5315d55c7e17a4e08f705ad4b6deb to your computer and use it in GitHub Desktop.
Create users from array for Kirby CMS.
<?php
kirby()->routes(array(
array(
'pattern' => 'create',
'action' => function() {
if( !kirby()->site()->user() || kirby()->site()->user() != "root" )
{
go("login");
}
// $_users = array(
// array(
// 'username' => [string],
// 'email' => [string],
// 'password' => [string],
// 'firstName' => [string],
// 'lastName' => [string]
// ),
// );
foreach ($_users as $key => $u) {
try {
$user = kirby()->site()->users()->create($u);
echo 'The user <'. $u['username'] .'> has been created';
} catch(Exception $e) {
echo 'The user <'. $u['username'] .'> could not be created';
// optional error message: $e->getMessage();
}
}
}
)
));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment