2012-03-12 16 views
1

私はCodeIgniterで開発されたフォーラムを持っています。そして私はWordpressによって動力を与えられた私のウェブサイトを持っています。CodeIgniterとWordpressの統合

基本的に私がやってみたいのは、ユーザーがフォーラムに登録し、その詳細をWordpressのユーザーテーブルに追加して、両方に登録されている場合です。

フォーラムのための私のコード...

/** 
* Create new user record 
* 
* @param array 
* @param bool 
* @return array 
*/ 

// username email password last_ip key 
function create_user($data) 
{ 
$sql = "INSERT INTO users (username, 
      email, 
      password, 
      last_ip, 
      created, 
      activated 
     ) VALUES ( 
      ?, ?, ?, ?, ?, ? 
     )"; 

$this->db->query($sql, array( 
          $data['username'], 
          $data['email'], 
          $data['password'], 
          $data['last_ip'], 
          date("Y-m-d H:i:s", utc_time()), 
          $data['activated'] 
          )); 

if ($user_id = $this->db->insert_id()) { 
    $this->create_profile($user_id); 
    return TRUE; 
} 
return FALSE; 
} 

function activate_user($username) 
{ 
$this->db->query("UPDATE users SET activated = 1 WHERE username = ?", $username); 
return $this->db->affected_rows(); 
} 

とWordpressのレジスタクラス...

/** 
* Handles registering a new user. 
* 
* @param string $user_login User's username for logging in 
* @param string $user_email User's email address to send password and add 
* @return int|WP_Error Either user's ID or error on failure. 
*/ 
function register_new_user($user_login, $user_email) { 
$errors = new WP_Error(); 

$sanitized_user_login = sanitize_user($user_login); 
$user_email = apply_filters('user_registration_email', $user_email); 

// Check the username 
if ($sanitized_user_login == '') { 
    $errors->add('empty_username', __('<strong>ERROR</strong>: Please enter a username.')); 
} elseif (! validate_username($user_login)) { 
    $errors->add('invalid_username', __('<strong>ERROR</strong>: This username is invalid because it uses illegal characters. Please enter a valid username.')); 
    $sanitized_user_login = ''; 
} elseif (username_exists($sanitized_user_login)) { 
    $errors->add('username_exists', __('<strong>ERROR</strong>: This username is already registered, please choose another one.')); 
} 

// Check the e-mail address 
if ($user_email == '') { 
    $errors->add('empty_email', __('<strong>ERROR</strong>: Please type your e-mail address.')); 
} elseif (! is_email($user_email)) { 
    $errors->add('invalid_email', __('<strong>ERROR</strong>: The email address isn’t correct.')); 
    $user_email = ''; 
} elseif (email_exists($user_email)) { 
    $errors->add('email_exists', __('<strong>ERROR</strong>: This email is already registered, please choose another one.')); 
} 

do_action('register_post', $sanitized_user_login, $user_email, $errors); 

$errors = apply_filters('registration_errors', $errors, $sanitized_user_login, $user_email); 

if ($errors->get_error_code()) 
    return $errors; 

$user_pass = wp_generate_password(12, false); 
$user_id = wp_create_user($sanitized_user_login, $user_pass, $user_email); 
if (! $user_id) { 
    $errors->add('registerfail', sprintf(__('<strong>ERROR</strong>: Couldn’t register you... please contact the <a href="mailto:%s">webmaster</a> !'), get_option('admin_email'))); 
    return $errors; 
} 

update_user_option($user_id, 'default_password_nag', true, true); //Set up the Password change nag. 

wp_new_user_notification($user_id, $user_pass); 

return $user_id; 
} 

私は「、Wordpressのクラスのすべての余分なbumphを必要としません。私はちょうどWordpressのユーザーテーブルに加えて、ベアボーンフォーラムの値を探しています。

助けが必要ですか? DBは、あなたのメインコントローラでそれをVARを割り当てるワードプレスを使用するには

$db['wordpress'] 

$db['default'] //priority 

+0

明白になるべきあなたの質問は何ですか?他人にあなたの仕事をさせたくないのですか? – Shomz

答えて

0

2つのデータベース・コンフィグは、あなたのCodeIgniterの設定ファイルに必要となります。

$this->wordpress_db = $this->load->database('wordpress', TRUE); 

//Normal query 
$this->db->query(); 

//wordpress Query 
$this->wordpress_db->query(); 

残りは

関連する問題