WordPress.org

Ready to get started?Download WordPress

Forums

Use wordpress's login for outside standalone application? (2 posts)

  1. fallenpeace
    Member
    Posted 1 year ago #

    Okay basically, I have a music project I picked up from a friend that ive been working on for the the past couple of weeks. Its divided into three parts, A main website (powered by wordpress) - a custom user panel (powered by codeigniter) - and a radio/music player (Powered by codeigniter).

    Oddly enough, all three parts have their own login system. So users need to register on each separate area which is horrible. I am not worried about the custom user panel because that is being removed and we will just be themeing the original wordpress dashboard to our liking.

    Basically I want to combine the radio/music player with the wordpress login/register system so the usernames and passwords are the same throughout the main wordpress site and the musicplayer.

    The radio uses a basic login/register system and here's the corresponding functions:

    public function uregister() {
        $this->load->helper( array('form') );
        if( $_POST['submit'] ) {
            $data = array("ra_fullname"=>$_POST['fname'],
                          "ra_email"=>$_POST['uemail'],
                          "ra_password"=>$_POST['upassword']);
            $this->db->insert('ws_radio_user', $data);
            redirect( site_url() );
        }
    
        $data = array();
        $this->load->view('user_register', $data );
    } 
    
    public function ulogin() {
        $this->load->helper( array('form') );
        if( isset( $_POST['submit']) ) {
            $data = $this->db->query("select * from ws_radio_user where ra_email = '".$_REQUEST['lemail']."' and ra_password = '".$_REQUEST['lupassword']."'")->row();
            if( $data ) {
                $sess_array = array(
                                'id' => $data->uid,
                                'username' => $data->ra_email
                              );
                $this->session->set_userdata('logged_in', $sess_array);
                redirect('http://radio.#.com');
            } else {
               $data = array();
               $data['error'] = "username password does not match";
               redirect('http://radio.#.com');
            }
        }
    
        $data = array();
        $this->load->view('login_view', $data );
    }
    public function logout() {
        $this->load->helper( array('form') );
        $this->session->unset_userdata('logged_in');
        $this->session->sess_destroy();
        redirect('http://radio.#.com', 'refresh');
    }

    I am nowhere near a professional when it comes to php, so any insight would be extremely helpful, in replacing this login (which obviously only reads and writes plaintext) with the wordpress login system.

    Also both the wordpress tables and the radio tables are in the same database ^.^

  2. bcworkz
    Member
    Posted 1 year ago #

    I would suggest using WP as the main user management engine. Every function related to this in WP should have a filter or action you could hook into to do related functions on the other platforms.

    For example, when a new user registers in WP, wp_insert_user() is called to make the needed entries to the DB. This function has a 'user_register' action that you can hook into. Your hook function will be passed the new user ID, with this, you can get any pertinent information that needs to be added to the other platform's tables to register a user there dynamically via code.

    A similar process is followed for every user management function such as updating data, logging in, logging out, etc. Determine which functions are used in each case and check the source code to determine which hook would work for your needs.

    If the tables are all in the same DB, you can use $wpdb methods to access the tables of other platforms, which is a little easier than straight PHP mysql functions.

Topic Closed

This topic has been closed to new replies.

About this Topic