/**
Email
*/
function ym_email($to, $subject, $message)
{
    ym_email_add_filters();
    wp_mail($to, $subject, $message);
    ym_email_remove_filters();
}
Esempio n. 2
0
 function create($email, $sub_id = false, $smflag = false, $username = false, $password = false, $custom_fields = false, $package = false, $expire_date = false)
 {
     global $wpdb;
     // is email a email?
     if (empty($email)) {
         return new WP_Error('empty_email', __('<strong>ERROR</strong>: Please type your e-mail address.'));
     } else {
         if (!is_email($email)) {
             return new WP_Error('invalid_email', __('<strong>ERROR</strong>: The email address isn&#8217;t correct.'));
         }
     }
     if (email_exists($email)) {
         return new WP_Error('existing_user_email', __('This email address is already registered.'));
     }
     if (!$username) {
         $username = $email;
     }
     if ($username) {
         if (username_exists($username)) {
             return new WP_Error('existing_user_login', __('This Username is already registered.'));
         }
     }
     if (!$password) {
         $password = wp_generate_password(12, false);
     }
     $pw_hash = wp_hash_password($password);
     //$user_id = wp_create_user($username,$password,$email); - can't be used due to register action
     $user_login = $username;
     $user_pass = $pw_hash;
     $user_email = $email;
     $user_nicename = $username;
     $display_name = $username;
     $user_registered = gmdate('Y-m-d H:i:s');
     $user_url = $custom_fields['user_url'];
     $data = compact('user_pass', 'user_email', 'user_url', 'user_nicename', 'display_name', 'user_registered');
     $data = stripslashes_deep($data);
     $wpdb->insert($wpdb->users, $data + compact('user_login'));
     $user_id = (int) $wpdb->insert_id;
     $rich_editing = 'true';
     $comment_shortcuts = 'false';
     $admin_color = 'fresh';
     $use_ssl = 0;
     update_user_meta($user_id, 'rich_editing', $rich_editing);
     update_user_meta($user_id, 'comment_shortcuts', $comment_shortcuts);
     update_user_meta($user_id, 'admin_color', $admin_color);
     update_user_meta($user_id, 'use_ssl', $use_ssl);
     $this->ID = $user_id;
     //Custom Fields
     if ($custom_fields) {
         //take the array and check the field names
         if (is_array($custom_fields)) {
             $ym_custom = get_user_meta($user_id, 'ym_custom_fields', TRUE);
             foreach ($custom_fields as $field => $value) {
                 $custom_field = ym_get_custom_field_by_name($field);
                 if ($custom_field) {
                     $ym_custom[$custom_field['id']] = $value;
                     //Patch to fix first_name & last_name not populating on import
                     if (in_array($custom_field['name'], array('first_name', 'last_name'))) {
                         update_user_meta($user_id, $custom_field['name'], $value);
                     }
                 }
             }
             update_user_meta($user_id, 'ym_custom_fields', $ym_custom);
         }
     }
     // package
     if (isset($sub_id) || isset($package)) {
         if (isset($sub_id)) {
             // pass to payment engine
             $pay = new ym_payment_gateway();
             $pay->code = 'ym_create';
             $pay->name = 'ym_create';
             $pay->nomore_email = TRUE;
             // call full update
             $pay->do_buy_subscription($sub_id, $user_id, TRUE);
             //Override the expire date if its set
             if ($expire_date) {
                 $data = array('expire_date' => $expire_date);
                 //Update the user data
                 $this->update($data);
                 $this->save();
             }
         } elseif (isset($package) && is_array($package)) {
             $this->account_type = $package['account_type'];
             $this->duration = $package['duration'];
             $this->duration_type = $package['duration_type'];
             if ($package['expire_date']) {
                 $this->expire_date = intval($package['expire_date']);
             } else {
                 $this->expire_date = $this->expiry_time($package['duration'], $package['duration_type']);
             }
             $this->role = $package['role'];
             $this->last_pay_date = time();
             $this->status_str = __('API Account: ', 'ym') . ucwords($this->account_type);
             // make active
             $this->status = YM_STATUS_ACTIVE;
             @ym_log_transaction(YM_ACCOUNT_TYPE_ASSIGNATION, $this->account_type, $user_id);
             //Update the user data
             $this->save();
             //log in transaction table
             @ym_log_transaction(YM_ACCESS_EXTENSION, date(YM_DATEFORMAT, time()), $user_id);
             @ym_log_transaction(YM_USER_STATUS_UPDATE, 'Active', $user_id);
             //Set a role
             if (!$this->role) {
                 $this->role = 'subscriber';
             }
             $this->updaterole($this->role);
         }
     }
     //last thing, send notification if flag is set
     if ($smflag) {
         ym_email_add_filters();
         wp_new_user_notification($user_id, $password);
         ym_email_remove_filters();
     }
     do_action('yourmember_user_created', $user_id, $password);
     //tidy up after ourselves
     wp_cache_delete($user_id, 'users');
     wp_cache_delete($user_login, 'userlogins');
     // call user_register?
     //do_action('user_register', $user_id);
     return $user_id;
 }