Advertisement
MrPauloeN

Wordpress Custom Login / Mechanizm Logowanie

Feb 20th, 2019
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.30 KB | None | 0 0
  1. // Custom Login Engine
  2.  
  3. function custom_login() {
  4.    
  5.     global $errors;
  6.  
  7.    
  8.     if  ( isset( $_POST['submit'] ) && ( $_POST['submit'] == 'submit' )) {
  9.        
  10.         if ( ! isset( $_POST['czystespalanie__nonce__field'] ) || ! wp_verify_nonce( $_POST['czystespalanie__nonce__field'], 'czystespalanie__nonce__cf_msg' )) {
  11.  
  12.            print '<h1>Sorry, but <strong><i>something went wrong.</i></strong> Contact with admin </h1>';
  13.            return;
  14.         }      
  15.        
  16.         $res = czystespalanie__post_captcha( $_POST['g-recaptcha-response'] );
  17.  
  18.         if ( !$res['success'] ){
  19.             $errors = 'Udowodnij, że nie jesteś robotem i zaznacz pole reCaptcha lub wykonaj instrukcje z obrazka.';
  20.         } else {
  21.        
  22.             $login_data = array();
  23.             $login_data['user_login'] = sanitize_user($_POST['log']);
  24.             $login_data['user_password'] = esc_attr($_POST['pwd']);
  25.  
  26.             $user = wp_signon( $login_data, false );
  27.  
  28.             if ( is_wp_error( $user ) ) {
  29.                
  30.                 $errors = 'Niepoprawny login lub hasło.';
  31.                
  32.             } else {
  33.                    
  34.                 wp_clear_auth_cookie();
  35.                
  36.                 wp_set_current_user( $user->ID, $user->user_login );
  37.                 wp_set_auth_cookie( $user->ID );
  38.            
  39.                 $redirect_to = ( is_array( $user->roles ) && in_array( 'administrator', $user->roles ) ) ? admin_url() : home_url('/forum');           
  40.                
  41.                 wp_safe_redirect( $redirect_to );
  42.                 exit;
  43.             }
  44.         }
  45.     }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement