Its possible to change wp usertable
-
Hi i want to change table
“wp_user” to “accounts”
And strings
User_login to login
User_pass to passwordIts possible;
-
Possible? Yes, I guess it can be done if you really realyl want to. Is it a good idea? Definatly not! Is it easy? Nowhere close, It’s going to be extremely difficult.
The columns are referenced throughout the WordPress core code, along with a lot of themes and plugins, so changing the name of them would mean that you’d need to basically hack a big chunck of the sites code to get it to work.
My big question is – why do you want to make this change? Is there a reason that you can’t work with the existing column names as they are now?
I will make a l2j server and i want all wordpress registered users access the game
It’s probably not going to be that simple, unless l2j server uses the same columns as the wp_users table (which I doubt), then just having the same name isn’t going to help you.
I want to change the wordpress core to use the l2j server “accounts” table as “wp_users” table
-
This reply was modified 7 years, 8 months ago by
mslave.
Anyone please
You can extend WP to authenticate users through other means and store data in other manners. What you do not want to do is swap one table for another, or replace the users table. You extend WP by using filter and action hooks. For example, the “authenticate” filter can be used to authenticate users by other means.
Please do not bump your topics. It does not further your cause like you think it will. In fact, appearing needy will discourage some volunteers from wanting to help you. And little more than 3 hours until you bump? This is not a paid help desk. If you really need help that fast, you should hire someone that is obligated to be responsive to your demands. Volunteers do not respond well to that.
We know you’re new here, so no big deal about bumping… this time ??
I cannot agree more with bcworkz, and Id suggest exactly the same thing. Don’t modify the WordPress system – but create a bridge between the two so that everything can work in it’s own (correct) way.
I found this plugin for Drupal. This plugin autocreate the user with same credentials on second database. Its possible to make plugin for wordpress ?
Features
On Drupal Register form create 2 users with same username password and email
First on the Drupal Database and Second on the L2j DatabaseAfter change the drupal user password this plugin auto change the password on l2J database.
<?php /** * @file * Allows users to login on a Drupal website through L2J Server. * * Validate login, profile and register forms. */ /** * Implements hook_help(). * * Retrieve the project help page. */ function l2j_connect_help($path, $arg) { switch ($path) { case 'admin/help#l2j_connect': { return ('<p>' . t('This module allows users to authenticate an external L2jserver System.') . '</p>'); } } } /** * Implements hook_form_FORM_ID_alter(). */ function l2j_connect_form_user_login_block_alter(&$form, $form_state) { return l2j_connect_form_user_login_alter($form, $form_state); } /** * Implements hook_form_FORM_ID_alter(). * * Alter validation for user_login. */ function l2j_connect_form_user_login_alter(&$form, $form_state) { $form['#validate'][] = 'l2j_connect_login_validate'; } /** * Implements hook_form_FORM_ID_alter(). * * Alter validation for user_profile_form. */ function l2j_connect_form_user_profile_form_alter(&$form, $form_state) { $form['#validate'][] = 'l2j_connect_user_profile_form_validate'; } /** * Implements hook_form_FORM_ID_alter(). * * Alter validation for user_register_form. */ function l2j_connect_form_user_register_form_alter(&$form, &$form_state) { $form['#validate'][] = 'l2j_connect_user_register_form_validate'; } /** * Validate the user_register_form submit. */ function l2j_connect_user_register_form_validate($form, &$form_state) { $login = $form_state['values']['name']; $mail = $form_state['values']['mail']; if (empty($form_state['values']['pass'])) { $pass = user_password(); } else { $pass = $form_state['values']['pass']; } if (l2j_connect_login_exists($login)) { form_set_error('name', t('Sorry, the username exists in our L2J Database')); } else if (l2j_connect_mail_exists($mail)) { form_set_error('mail', t('Sorry, the mail exists in our L2J Database')); } else { $details = array( 'login' => $login, 'pass' => $pass, 'mail' => $mail, 'access' => 0, ); $account = (object) $details; l2j_connect_external_create_account($account); } return TRUE; } /** * Validate the user_login form submit. */ function l2j_connect_login_validate($form, &$form_state) { $username = $form_state['values']['name']; $password = $form_state['values']['pass']; // Exists the user in our loginserver? if (!l2j_connect_account_loggin_in($username, $password)) { form_set_error('name', t('There is a problem with your account, please contact an Administrator')); } user_login_authenticate_validate($form, $form_state); } /** * Validate the user_profile_form submit. */ function l2j_connect_user_profile_form_validate($form, &$form_state) { if (l2j_connect_account_exists($form_state['values']['name'], $form_state['values']['mail'])) { $details = array( 'login' => $form_state['values']['name'], 'pass' => $form_state['values']['pass'], 'mail' => $form_state['values']['mail'] ); $account = (object) $details; l2j_connect_external_update_account($account); } else { form_set_error('name', t('There is a problem with your account, please contact an Administrator')); } } /** * Check if a given account exists in L2j loginserver. */ function l2j_connect_login_exists($login) { db_set_active('loginserver'); $result = db_query('SELECT login from {accounts} WHERE login=:login', array(':login' => $login)); $exists = FALSE; foreach ($result as $row) { $exists = TRUE; } db_set_active(); return $exists; } /** * Check if a given email exists in L2j loginserver. */ function l2j_connect_mail_exists($mail) { db_set_active('loginserver'); $result = db_query('SELECT email from {accounts} WHERE email=:mail', array(':mail' => $mail)); $exists = FALSE; foreach ($result as $row) { $exists = TRUE; } db_set_active(); return $exists; } /** * Retrieve the mail info with an account as parameter from L2j loginserver. */ function l2j_connect_retrieve_mail($login) { db_set_active('loginserver'); $result = db_query('SELECT email from {accounts} WHERE login=:login', array(':login' => $login))->fetchField(); db_set_active(); return $result; } /** * Retrieve the login info with an email as parameter from L2j loginserver. */ function l2j_connect_retrieve_login($mail) { db_set_active('loginserver'); $result = db_query('SELECT login from {accounts} WHERE email=:email', array(':email' => $mail))->fetchField(); db_set_active(); return $result; } /** * Check if an L2j account exists in L2j loginserver. */ function l2j_connect_account_exists($login, $email) { db_set_active('loginserver'); $result = db_query('SELECT login, email from {accounts} WHERE login=:login AND email=:email', array(':login' => $login, ':email' => $email)); $exists = FALSE; foreach ($result as $row) { $exists = TRUE; } db_set_active(); return $exists; } /** * Log in L2j loginserver with a given username and password. */ function l2j_connect_account_loggin_in($username, $password) { db_set_active('loginserver'); $result = db_query('SELECT login, password, accessLevel from {accounts} WHERE login=:login AND password=:password AND accessLevel=0', array(':login' => $username, ':password' => l2j_connect_encrypt($password))); $exists = FALSE; foreach ($result as $row) { $exists = TRUE; } db_set_active(); return $exists; } /** * Create an external account in L2j loginserver. */ function l2j_connect_external_create_account($account) { db_set_active('loginserver'); $result = db_insert('accounts') ->fields(array( 'login' => $account->login, 'password' => l2j_connect_encrypt($account->pass), 'email' => $account->mail, 'accessLevel' => $account->access, )) ->execute(); db_set_active(); drupal_set_message(t('The Account has been created in the Loginserver database.'), 'status'); return TRUE; } /** * Update an external account in L2j loginserver. */ function l2j_connect_external_update_account($account) { db_set_active('loginserver'); $fields = array( 'login' => $account->login ); if (!empty($account->pass)) { $fields['password'] = l2j_connect_encrypt($account->pass); } $result = db_update('accounts') ->fields($fields) ->condition('login', $account->login, '=') ->execute(); db_set_active(); return TRUE; } /** * Encrypt a password to match the current L2j loginserver encrypt method. */ function l2j_connect_encrypt($pass) { return base64_encode(pack("H*", sha1(utf8_encode($pass)))); }
This plugin read this from drupal site configuration file
$databases = array ( 'loginserver' => array ( 'default' => array ( 'database' => 'l2jls', 'username' => 'root', 'password' => '', 'host' => 'localhost', 'port' => '', 'driver' => 'mysql', 'prefix' => '', ) ),'gameserver' => array ( 'default' => array ( 'database' => 'l2jgs', 'username' => 'root', 'password' => '', 'host' => 'localhost', 'port' => '', 'driver' => 'mysql', 'prefix' => '', ) ), );
Sure, you can make a plugin that authenticates users through other means. Using data from a different table, DB, server, whatever. What you cannot do is attempt to use Drupal code in WP. Whatever authentication process you concoct needs to hook into the “authenticate” filter. It must be able to return a WP_User object on success, or a WP_Error object on failure.
It doesn’t matter where the data comes from to create a WP_User object. The user table is ideal, but any data will do as long as it matches up with the object WP would create. Your authentication can even create the object from the WP user table, but authenticate elsewhere using other data. There just needs to be some relationship between the WP user and the remotely authenticated user. It could be as simple as a usermeta value that is the user ID to authenticate through a different DB.
-
This reply was modified 7 years, 8 months ago by
- The topic ‘Its possible to change wp usertable’ is closed to new replies.