I am working on WordPress MU and trying to build one plugin to add user to multiple sites. so far did everything to loop through sites. But while assigning user to site as below using add_user_to_blog am getting error see below.
add_user_to_blog( $blogid, $amsuserid, $urole );
Getting the following error:
Fatal error: Call to undefined function get_userdata() in wp-includesms-functions.php on line 181
if I disable the line “add_user_to_blog” no errors.
full function here:
function amsAddUsertoSites()
{
$siteslist=$_POST['updatesites'];
$urole=$_POST['setrole'];
$addtoallblogs=$_POST['allsites'];
$amsuserid=$_POST['userid'];
if($addtoallblogs) {
//add_user_to_blog( $blogid, $user_id, "administrator" );
$blogs = get_blogs();
foreach($blogs as $blog=>$blogid)
{
add_user_to_blog( $blogid, $amsuserid,$urole );
}
}
else {
foreach($siteslist as $blog=>$blogid)
{
add_user_to_blog( $blogid, $amsuserid,$urole );
}
}
}
get_userdata()
is a pluggable function, you can find its declaration inwp-includes/pluggable.php
. That means, plugins can declare it earlier, and it is not declared, when a plugin is loaded.When you look at
wp-settings.php
, you can see the load order:Wait at least for
plugins_loaded
, before you do more than callingadd_action()
oradd_filter()
.