Today's Posts Follow Us On Twitter! TFL Members on Twitter  
Forum search: Advanced Search  
Navigation
Marketplace
  Members Login:
Lost password?
  Forum Statistics:
Forum Members: 24,256
Total Threads: 81,169
Total Posts: 566,838
There are 40 users currently browsing (tf).
 
  Our Partners:
 
  TalkFreelance     Design and Development     Programming     PHP and MySQL :

CodeIgniter and Wordpress help

Thread title: CodeIgniter and Wordpress help
Reply    
    Thread tools Search this thread Display Modes  
03-11-2012, 10:38 AM
#1
ChrisGwynne is offline ChrisGwynne
Status: Member
Join date: Nov 2007
Location: Wales
Expertise: Development
Software: TextMate, Transmit, Photoshop.
 
Posts: 242
iTrader: 0 / 50%
 

ChrisGwynne is on a distinguished road

  Old  CodeIgniter and Wordpress help

Hey all

I have a forum developed with CodeIgniter. And I have my website, powered by Wordpress.

Basically what I'm looking to do is when a user registers on the forums, it adds those details to the Wordpress user table, so they're registered on both.

My code for the forum...

PHP Code:
/**
   * 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();
  } 
and the Wordpress register class...

PHP Code:
/**
 * 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_password12false);
    
$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'truetrue ); //Set up the Password change nag.

    
wp_new_user_notification$user_id$user_pass );

    return 
$user_id;

I don't need all the extra bumph of the Wordpress class, I'm just looking for a barebones forum values addition to the Wordpress user table.

Any help?

Reply    


Thread Tools
Display Modes

  Posting Rules  
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump:
 
  Contains New Posts Forum Contains New Posts   Contains No New Posts Forum Contains No New Posts   A Closed Forum Forum is Closed