Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have a problem when I want to get user id WordPress after login in file wp_login.php, I tried to insert some code in this file, after line wp_safe_redirect($redirect_to); in login case.

I must get user id after login to update my custom WordPress table.

session_start();
require( dirname(__FILE__) . '/wp-load.php' );
global $wpdb;

$session_id     = session_id(); 
$current_user   = wp_get_current_user();
$id_user        = $current_user->ID;

$wpdb->query( 
    $wpdb->prepare("UPDATE wp_shortlist SET id_user='$id_user' WHERE id_session='$session_id' ")
);

any idea to get user id after login in file wp_login.php?

share|improve this question
    
You have the biggest security hole there. Care to tell me your web address? Seriously, don't modify the core files! –  Waldermort Sep 19 '13 at 5:54
    
you are editing in the defoult core wordpress files and it may affect to your site and also when you update you version all the changes will lost so try to work only in your custom theme –  Vikas Gautam Sep 19 '13 at 6:01
    
yes i know that if i change my core files, maybe i can get security hole but i'm very confused how to get user id after succesfull login . can i hook action after user login like after_setup_theme via function.php ? –  Ardi Wirawan Sep 19 '13 at 6:05
add comment

1 Answer

up vote 1 down vote accepted

As said above modifying the core files is a bad idea, by doing so you are opening up security holes and on top of all this you loose the changes made on up-gradation.

To do the above you can try the wp_login hook, put the codes in your active theme's functions.php

function after_login() {
    $current_user = wp_get_current_user();
    $id_user = $current_user->ID;
       // The query you were trying would go here.
}
add_action( 'wp_login', 'after_login' );

Hope it helps !

share|improve this answer
    
still can't get user id :( –  Ardi Wirawan Sep 20 '13 at 6:38
    
Can You please check if the query you are writing is right, please check the syntax too. Try and run the query in the phpmyadmin. –  Maruti Mohanty Sep 20 '13 at 6:58
    
yes, i have checked my query and also try and run in phpmyadmin. the problem is i can't get current user id after login . –  Ardi Wirawan Sep 20 '13 at 7:07
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.