2

I'm trying to output the password of a newly created user in plain text using the user_register hook as explained in this answer. However, upon doing a var_dump of $_POST, I don't see any password output. Can user_register actually do this?

If not, might you have any ideas on a hook that would do this for a new user?

Thanks for any insight!

Edit: Below is the code that I'm using, along with the var_dump
The code that I'm using for the password is from this accepted answer.

add_action('user_register', 'registration_save');

function registration_save($user_id){
    global $wpdb;
    echo "user saved";
    ob_start();
    var_dump($_POST);
    $result = ob_get_clean();
    echo file_put_contents("file_put_test.txt","Hello World".$result."Password: ".$_POST['pass1']);
    $result = $wpdb->query($wpdb->prepare("REPLACE INTO test
                                          (user,newpass)
                                          values(%s,%s)",
                                          array(
                                              $_POST['username'],
                                              $_POST['pass1']
                                            )
    ));
2
  • Please, show the code you're using. And check the guide How to Ask.
    – brasofilo
    Commented Oct 4, 2013 at 0:14
  • @brasofilo Thanks for the response; I've added the code to the question above. It seems not to output either of the variables to the table listed. Commented Oct 4, 2013 at 1:13

2 Answers 2

1

There's an action hook in /wp-admin/includes/user.php to check if both password fields match:

add_action( 'check_passwords', function( $user, $pass1, $pass2 ) 
{
    var_dump($pass1);
    die();
}, 10, 3 );
2
  • 1
    Thanks that was quite helpful! I also ended up needing a a way to access the randomly generated passwords when a user creates a new account. I posted that answer as well. This worked for all other cases though. Commented Oct 4, 2013 at 18:14
  • Nice addition. Duly noted ;)
    – brasofilo
    Commented Oct 4, 2013 at 19:11
1

Found a solution to the randomly generated passwords. Since I was using a randomly generated password for new users I needed to implement the random_password hook. I got the idea from this answer. See below for how I implemented it:

add_filter('random_password', 'random_pass_save');
function random_pass_save($pass){
    echo file_put_contents("random_pass_save.txt", "Hello world, here's my saved random pass ".$pass);
    return $pass;
}

One thing that sort of tripped me up when I first used it was that, unless you put the return statement on the bottom, your email won't send and the password won't work. So, just a heads up.

1
  • All add_filters have to return something, unlike add_actions
    – brasofilo
    Commented Oct 4, 2013 at 19:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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