Website Summary Files Commits Branches @commit @diff @stats
path: root / wp-content / plugins / dx-users / login-user-class.php
blob: 7bc4f1e00b3f334385286fe66fab6c02edb7136f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<?php
class LoginUser {
    function init() {
        add_action( 'admin_post_nopriv_process_login', array($this, 'try_login_user' ));
    }

    function try_login_user() {
        $creds = array(
            'user_login'    => sanitize_text_field( $_POST['email'] ),
            'user_password' => sanitize_text_field( $_POST['password'] ),
            'remember'      => true
        );

        $user = wp_signon( $creds );

        if ( is_wp_error( $user ) ) {
            wp_die( $user->get_error_message() );
        }

        wp_set_current_user( $user->data->ID );

        wp_redirect( home_url() ); exit;    
    }
}