我正在创建一个自定义类来管理wordpress和chamilo中的用户,但这不是重点。
类如下所示:
class Platform
{
private $security_key = \'..\';
private $secret_key;
private $firstname;
private $lastname;
private $status;
private $email;
private $login;
private $password;
private $encrypt_method = "md5";
private $original_user_id_name = "uid";
private $original_user_id_value;
public function __construct()
{
$arguments = func_get_args();
if(!empty($arguments))
foreach($arguments[0] as $key => $property)
if(property_exists($this, $key))
$this->{$key} = $property;
}
/*
* Do autoryzacji z chamilo potrzeba IP clienta + auth_code.
* Z tych danych jest tworzyony API_KEY potrzeby podczas komunikacje z platformą.
* Funkcje sprawdzają akutalne IP oraz auth_code platformy i generują API_KEY
*/
public function check_client_ip()
{
$ip = trim($_SERVER[\'REMOTE_ADDR\']);
if (!empty($_SERVER[\'HTTP_X_FORWARDED_FOR\'])) {
list($ip1,$ip2) = split(\',\',$_SERVER[\'HTTP_X_FORWARDED_FOR\']);
$ip = trim($ip1);
}
return $ip;
}
public function generate_secret_key()
{
$ip_address = $this->check_client_ip();
$secret_key = sha1($ip_address.$this->security_key);
return $secret_key;
}
/*
* Dodawanie użytkownika w Chamilo
*/
public function add_user_to_chamilo()
{
$params = array(
\'firstname\' => $this->firstname,
\'lastname\' => $this->lastname,
\'status\' => \'5\', // 5 STUDENT - 1 TEACHER - zawsze ustawiamy na studenta - konta administracyjne będziemy tworzyć ręcznie
\'email\' => $this->email,
\'loginname\' => $this->login,
\'password\' => $this->password, // encrypted using sha1
\'encrypt_method\' => \'md5\',
\'language\' => \'Polish\',
\'official_code\' => \'\',
\'phone\' => \'\',
\'expiration_date\' => \'0000-00-00\',
\'original_user_id_name\' => \'uid\', // the extra user field that will be automatically created in the user profile see: main/admin/user_fields.php
\'original_user_id_value\' => $this->wp_user_id, // third party user id
\'secret_key\' => $this->generate_secret_key(),
);
echo "<pre>";
print_r($params);
echo "</pre>";
//$client = new SoapClient(\'http://....pl/registration.soap.php?wsdl\');
//$response = $client->WSCreateUserPasswordCrypted($params);
}
/*
* Dodawanie użytkownika w Wordpress
*/
public function add_user_to_wordpress()
{
$params = array(
\'ID\' => \'\',
\'first_name\' => $this->firstname,
\'last_name\' => $this->lastname,
\'user_email\' => $this->email,
\'user_login\' => $this->login,
\'user_pass\' => $this->password,
\'role\' => \'subscriber\'
);
echo "<pre>";
print_r($params);
echo "</pre>";
wp_insert_user($params);
}
}
这是我在wordpress页面(page adduser.php)中初始化类的方式
$p = new Platform(array(
\'firstname\' => \'John\',
\'lastname\' => \'Doe\',
\'email\' => \'[email protected]\',
\'login\' => \'test\',
\'password\' => \'somepass\'
)
);
然后我运行公共函数add\\u user\\u to\\u wordpress
$p-> add_user_to_wordpress();
所以它从$params数组打印数据,但似乎它没有运行wp\\u insert user。
打印数据:
Array
(
[ID] =>
[first_name] => John
[last_name] => Doe
[user_email] => [email protected]
[user_login] => test
[user_pass] => somepass
[role] => subscriber
)
你能告诉我如何在我的自定义类中运行wordpress函数吗。
BTW类i加载到函数。php文件以主题作为第一行。