Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
Commonwell
/
broker-site
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
81b06811
authored
2024-01-18 09:16:04 -0500
by
Jeremy Groot
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
load batch of new users
1 parent
11cb6f0a
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
73 additions
and
0 deletions
wp-content/themes/commonwell-broker/inc/brokers_cli.php
wp-content/themes/commonwell-broker/inc/brokers_cli.php
View file @
81b0681
...
...
@@ -7,6 +7,79 @@ if ( class_exists( 'WP_CLI' ) ) {
campaign_Monitor_LoadData
();
}
function
import_brokers_from_csv
()
{
$data
=
[];
$row
=
0
;
if
((
$handle
=
fopen
(
wp_get_upload_dir
()[
'basedir'
]
.
"/"
.
"broker-import-sheet.csv"
,
"r"
))
!==
FALSE
)
{
while
((
$rowData
=
fgetcsv
(
$handle
,
1000
,
","
))
!==
FALSE
)
{
if
(
$row
==
0
)
{
++
$row
;
continue
;
}
$data
[]
=
[
'firstname'
=>
$rowData
[
0
],
'lastname'
=>
$rowData
[
1
],
'email'
=>
$rowData
[
2
],
'broker_id'
=>
$rowData
[
3
]];
}
fclose
(
$handle
);
}
$brokerages
=
getBrokerageList
();
foreach
(
$data
as
$rd
)
{
// Create a WordPress user
$password
=
wp_generate_password
();
$email
=
sanitize_email
(
$rd
[
'email'
]);
$role
=
'broker'
;
// Set the desired role here
$user_name
=
sanitize_user
(
substr
(
$email
,
0
,
strpos
(
$email
,
'@'
)));
$userdata
=
array
(
'user_login'
=>
$user_name
,
'first_name'
=>
$rd
[
'firstname'
],
'last_name'
=>
$rd
[
'lastname'
],
'user_pass'
=>
$password
,
'user_email'
=>
$email
,
'role'
=>
$role
,
);
$user_id
=
wp_insert_user
(
$userdata
);
if
(
!
is_wp_error
(
$user_id
))
{
// User created successfully
echo
'User '
.
$email
.
' created successfully.'
;
$brokerage
=
""
;
foreach
(
$brokerages
as
$broker
)
{
if
(
$broker
[
'broker_id'
]
==
$rd
[
'broker_id'
])
{
$brokerage
=
$broker
[
'brokerage'
];
}
}
if
(
empty
(
$brokerage
))
{
echo
'Brokerage not found for '
.
$email
.
'.'
;
}
update_user_meta
(
$user_id
,
'broker_id'
,
$rd
[
'broker_id'
]);
update_user_meta
(
$user_id
,
'brokerage'
,
$brokerage
);
update_user_meta
(
$user_id
,
'wp_capabilities'
,
'a:1:{s:6:"broker";b:1;}'
);
update_user_meta
(
$user_id
,
'wp_user_level'
,
0
);
update_user_meta
(
$user_id
,
'course_points'
,
0
);
global
$wpdb
;
$wpdb
->
insert
(
'wp_uam_accessgroup_to_object'
,
[
'object_id'
=>
$user_id
,
'object_type'
=>
'_user_'
,
'general_object_type'
=>
'_user_'
,
'group_id'
=>
1
,
'group_type'
=>
'UserGroup'
]);
}
else
{
// Error creating user
echo
'Error creating user: '
.
$user_id
->
get_error_message
();
}
//s:23:"a:1:{s:6:"broker";b:1;}";
}
}
//collect rows of a csv file and store them in an associative array
function
sync_broker_teams_assignment
()
{
...
...
Please
register
or
sign in
to post a comment