WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

im creating a custom class to manage users in wordpress and chamilo but this is not the point.

Class looks like this:

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();
            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>";
        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>";
        echo "</pre>";

This is how i initialize the class in wordpress page (page-adduser.php)

$p = new Platform(array(
        'firstname'                 => 'John',
        'lastname'                  => 'Doe',
        'email'                     => 'test@example.com',
        'login'                     => 'test',
        'password'                  => 'somepass'


Then i run public function add_user_to_wordpress

$p-> add_user_to_wordpress();

So it prints data from $params array but it seems this is not running wp_insert user.

Data printed:

    [ID] => 
    [first_name] => John
    [last_name] => Doe
    [user_email] => test@example.com
    [user_login] => test
    [user_pass] => somepass
    [role] => subscriber

Can You tell me how to runn wordpress functions inside my custom class.

BTW class i loaded to function.php file in theme as a first line.

share|improve this question
It seems that wp_insert_post is working just not accepting values like $this->firstname etc. – Charles Kłyciński Dec 29 '13 at 10:37
please edit the question to add info instead of commenting on it. – Mark Kaplun Dec 29 '13 at 14:59
Do you have debugging enabled? How and where do you use this class? – s_ha_dum Dec 29 '13 at 15:56

In addition to the debugging advice from @s_ha_dum, you could try to catch the possible WP_Error thrown by wp_insert_user():

$user_id = wp_insert_user($params);

if ( is_wp_error( $user_id ) )
   echo $user_id->get_error_message();
    printf( 'User created with user_id = %d', $user_id );

Maybe the user already exists?

You could also use email_exists() and username_exists() to check.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.