Created
May 24, 2017 14:36
-
-
Save julien-gargot/83d5315d55c7e17a4e08f705ad4b6deb to your computer and use it in GitHub Desktop.
Create users from array for Kirby CMS.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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