Skip to content

Instantly share code, notes, and snippets.

@TommyKolkman
Last active August 29, 2015 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TommyKolkman/d61efbc6eba9cf407bbb to your computer and use it in GitHub Desktop.
Save TommyKolkman/d61efbc6eba9cf407bbb to your computer and use it in GitHub Desktop.
<?php
/*
Plugin Name: Simple Shibboleth Authentication
Author: Martin Parm
Version: 0.0.1
*/
function custom_login(){
$headers = getallheaders();
// TODO: Bail on no SSO-heaers
$user = new WP_user(null, $headers['SSO-User']);
if ($user->exists()){
if (($user->user_email != $headers['SSO-Mail']) ||
($user->first_name != $headers['SSO-GivenName']) ||
($user->last_name != $headers['SSO-Surname'])){
// Update + role
wp_update_user(array(
'ID' => $user->ID,
'user_email' => $headers['SSO-Mail'],
'first_name' => $headers['SSO-GivenName'],
'last_name' => $headers['SSO-Surname']
));
$user = new WP_user($user->ID);
}
} else {
$user_id = wp_insert_user(array(
'user_login' => $headers['SSO-User'],
'user_pass' => wp_generate_password( 12, false ),
'user_email' => $headers['SSO-Mail'],
'first_name' => $headers['SSO-GivenName'],
'last_name' => $headers['SSO-Surname']
));
$user = new WP_user($user_id);
}
$current_user_id = get_current_user_id();
if ($user->ID != $current_user_id){
wp_logout();
wp_clear_auth_cookie();
wp_set_current_user($user->ID, $headers['SSO-User']);
wp_set_auth_cookie($user->ID);
}
}
add_action( 'after_setup_theme', 'custom_login' );
function hide_bio_stuff() {
?>
<script type="text/javascript">
//<![CDATA[
jQuery(document).ready( function($) {
var form = $('#your-profile');
form.find('input#first_name').prop('readonly', true);
form.find('input#last_name').prop('readonly', true);
form.find('input#email').prop('readonly', true);
var p = form.find('tr#password');
p.next().remove();
p.remove();
});
//]]>
</script>
<style type="text/css" media="screen">
#your-profile input[readonly]{
color: rgba(51,51,51,.5);
}
</style>
<?php
}
add_action( 'admin_head-profile.php' , 'hide_bio_stuff' );
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment