Created
April 23, 2020 14:02
-
-
Save woodwardtw/9130683cf411166efc2f7b9d57d0474c to your computer and use it in GitHub Desktop.
check on faculty-ish status
This file contains 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
//write to user profile if user is faculty | |
function user_status ($user){ | |
//attempt to differentiate between new user ID and edit profile user object | |
if (is_numeric($user)){ | |
$user_id = $user; | |
$user_info = get_userdata($user_id); | |
$email = $user_info->user_email; | |
} else { | |
$email = $user->user_email; | |
$user_id = $user->ID; | |
} | |
$url_email = urlencode($email); | |
$url = 'https://phonebook.vcu.edu/?Qname=' . $url_email . '&Qdepartment=*'; | |
$ch = curl_init(); | |
curl_setopt($ch, CURLOPT_URL, $url); | |
//return the transfer as a string | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); | |
// $output contains the output string | |
$output = curl_exec($ch); | |
$fail = preg_match('/No matches/', $output, $matches); | |
$user = get_user_meta($user_id); | |
$exists = get_user_meta($user_id, 'user_vcu_status'); | |
if ($fail == 0) { | |
$status = 'faculty'; | |
if ($exists){ | |
update_user_meta( $user_id, 'user_vcu_status', $status ); | |
} else { | |
add_user_meta( $user_id, 'user_vcu_status', $status, true ); | |
} | |
} else { | |
$status = 'student'; | |
if ($exists){ | |
update_user_meta( $user_id, 'user_vcu_status', $status ); | |
} else { | |
add_user_meta( $user_id, 'user_vcu_status', $status, true ); | |
} | |
} | |
curl_close($ch); | |
} | |
add_action ('wpmu_new_user', 'user_status', 10, 1); | |
add_action( 'edit_user_profile', 'user_status', 10, 1 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment