Index of /Andrej Ciho/Old Blog/WordPress MU/WPMU CAS Integration

Back Parent Directory 2006-10-28 20:28

NOTE: This plugin worked well with WPMU 1.3.2 and is kept here only for historical reasons. You should probably use the wpcas plugin instead:

I was asked to set up WordPress MultiUser (WPMU) for a project for Cornerstone University. They already had most of their online services integrated into a single sign-on using phpCAS and asked me to integrate WPMU with it as well. This document attempts to enable others to easily duplicate the same integration. I will also list some of the implications that I had to address as a consequence of the integration.

Before you start

Download phpCAS and after extracting it, copy the folder esup-phpcas-x.x.xx/source/CAS into the ./wp-content/mu-plugins folder of your WPMU install so that the path to CAS.php is ./wp-content/mu-plugins/CAS/CAS.php.

Make sure, that you have access to your MySQL database either through phpMyAdmin or another similar tool or at least that you can execute queries through the command line.

CAS modification

In the CAS that you copied into your mu-plugins folder: Comment out the following section in the beginning of CAS/PGTStorate/pgt-db.php so that it looks like this:

if (!class_exists('DB')) {

(Otherwise you’ll see errors.)


Make a backup copy of your current ./wp-login.php and replace the content of the original file with my wp-login.php.

Make a backup copy of your current ./wp-content/mu-plugins/pluggable.php and replace it with my pluggable.php. Edit the file and modify the CASloginURL and CASlogoutURL variables based on your setup.

Admin username

Most likely your username in your CAS user directory is not ‘admin’. At least mine wasn’t. In order for you to be able to log in to your WPMU install, you’ll have to edit the users table (wp_users) to change the username (user_login) of admin (ID = 1) to your CAS user directory username.

Since your username is no longer ‘admin’, WPMU may not consider you a site administrator (administrator of the site and all blogs). If this is the case, you will have to modify the function is_site_admin() in ./wp-includes/wpmu-functions.php to include the following clause:

$userid = get_current_user_id();
if ($userid == 1) return true;

What this will accomplish is that the person with userid = 1 (the person who installed WPMU) is considered a site admin regardless of their username.

Once you are the site admin again, you can add more users to have the same permissions in the Site Admin | Options section of the WPMU control panel / dash board. If that still doesn’t give them site admin permissions, you can hardcode their username in the same is_site_admin() function, although I would not recommend that. You would just insert some thing like this inside the is_site_admin() function:

if ($user_login === 'a12345') {return true;}

Welcome email

When you create a new blog in the site admin area, an email is sent to the new user created at the same time. The email contains a random password generated by WordPress – a password that will not work, because you are using CAS instead of the WordPress authentication. So in order to avoid any confusion, you’ll have to change the text of this Welcome email. Even though it may seem that the place you could edit that text is in the site admin area, the text is actually hard-coded into a php file. So to make the change you’ll have to edit it there.

Copy the function wp_new_user_notification from ./wp-includes/pluggable.php and insert it into ./wp-content/mu-plugins/pluggable.php at the end of the file. The functions in pluggable.php in wp-includes are preceded by
if ( !function_exists) (meaning if it was already defined earlier) because you can first define them in pluggable.php in mu-plugins which gets executed earlier in the sequence.

All that to say: if you want to modify a function that’s in ./wp-includes/pluggable.php, you are best off to copy it to ./wp-content/mu-plugins/pluggable.php first and modify it there so that you have as many of your WPMU modifications in one place – the mu-plugins folder – as possible.

But back to our wp_new_user_notification function. Now that it’s in ./wp-content/mu-plugins/pluggable.php, modify the line that says:

$message .= sprintf(__('Password: %s'), $plaintext_pass) . "\r\n";

to say something like:

$message .= sprintf(__('Password: (use your domain password)'), $plaintext_pass) . "\r\n";

That should be it. If you discover other things that may have to be addresses due to the integration, please let me know so that I can add them here for everyone to benefit from.

If you make any improvements, I kindly ask that you send them to me as a courtesy.

Comments (5) to “WPMU CAS Integration”

  1. Many thanks for this, Andrej.

  2. Andrej,
    YOU are absolutely a genius,
    thank you.

  3. Hi, We’re trying to CASify wpmu and following your great instructions, but are stumbling at the final hurdle. When we try to login we get the following error

    Warning: fclose(): supplied argument is not a valid stream resource in ../wp-login.php on line 70

    A ticket is being passed through in the URL and usernames etc are working as it appears I am logged in, but I can’t get any further – I have tried RC4 and RC8 of phpCAS with no luck and am using wpmu 1.3.3. Your thoughts would be much appreciated

  4. This doesn’t seem to be working with the latest WPMU.
    Do you have plans on doing it?

  5. We’re using WPMU at my school and needed a solution just like this.

    Working from your instructions here and a plugin from Stephen Schwink, I coded up a new plugin that works in WordPress and WordPressMU to do CAS integration. Most importantly, it doesn’t require making any changes to the core WP files.

    In case it helps anybody else, I’ve posted it at the plugins directory and my blog:

    Thanks for your pointers, they really helped get me going.

This website is powered by WordPress, using the IndexOf theme.