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 am currently using the wp_login hook to run a php function when a user logins. However, I want to show users who login notifications (a pop up with recent posts, etc) and I was planning to do this by running a javascript function.

Is it possible to edit the page shown to the user after login?

This is the code I have so far:

add_action( 'wp_login', 'my_login_function' );
add_action( 'wp_footer', 'the_footer_function' );

function the_footer_function(){
    if (defined('FIRST_RUN')){
        echo "<script>jQuery(document).ready( function(){alert('hello');});</script>";
        define('FIRST_RUN', false);
    }
}

function my_login_function($user_login){
     global $altdb;
     $user_info = get_userdatabylogin($user_login);
     $wonAwards = $altdb->get_var("SELECT achievement_id FROM user_".$user_info->ID." WHERE isTold='false'");
     define('FIRST_RUN', true);
     //$altdb->query("UPDATE user_".$user_info->ID." SET isTold='true' WHERE isTold = false") or die(mysql_error());
}

Any help is appreciated.

share|improve this question
add comment

2 Answers

up vote 2 down vote accepted
add_filter( "login_redirect", "my_login_redirect", 10, 3 );
function my_login_redirect( $redirect_to, $request, $user )
{
    return home_url( "/your_page/" );
}

Should about do it for you. Modified from a script that I had running in wp3.3.1.

Docs: home_url(), login_redirect

share|improve this answer
add comment

you may try using the wp_redirect() function, I was doing that in the past but I don't know how it will behave in the recent releases (in theory it should work)

share|improve this answer
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.