-
-
Save bulentsakarya/4ab88726b9383abfcc02009e18d899af to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function check_status( WP_User $user ) { | |
/* 1. WordPress dbsinde kullanıcı var mı, yok mu? */ | |
if(email_exists( $user->user_email )) { | |
/* 2. Kullanıcı abone mi yönetici mi? */ | |
if ( !in_array( 'subscriber', (array) $user->roles ) ) { | |
// Devam et | |
return $user; | |
} else { | |
/* 3. Diğer sistemde aboneliği aktif mi? */ | |
if (get_cURL($user->user_email, $user->pass)) { | |
return $user; | |
} else { | |
return false; | |
} | |
} | |
} else { | |
/* 4. Wordpress sitede bilgisi yok ama diğer sitede var mı? */ | |
if (get_cURL($user->user_email, $user->pass)) { | |
/* 5. Diğer sitede bilgisi varsa wordpress sitesine de ekle */ | |
wp_create_user( $user->user_email, $user->pass, $user->user_email ); | |
wp_signon($user->user_email, $user->pass); | |
} else { | |
$message = esc_html__( 'Abonelik bilgileri bulunamadı.', 'bsauth'); | |
return new WP_Error( 'user_not_verified', $message ); | |
} | |
} | |
// devam et | |
return $user; | |
} | |
add_filter( 'wp_authenticate', 'check_status' ); | |
function get_cURL($username, $password) { | |
$url = "https://api.url"; | |
$ch = curl_init(); | |
curl_setopt($ch, CURLOPT_URL, $url); | |
curl_setopt($ch, CURLOPT_POST, 1); | |
curl_setopt($ch, CURLOPT_POSTFIELDS, "email=$username&password=$password"); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | |
$server_output = curl_exec($ch); | |
curl_close($ch); | |
return json_decode($server_output, true); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment