WPMU permissions hack for new users

If you are using or administrating WordPress Multi-User you may have come across the following error message for new users creating just a login name (not getting blog):

You do not have sufficient permissions to access this page.

This problem can get pretty frustrating if you are using a single blog on WPMU that has several users. For example, I created one blog for my class this Summer that has six additional users. Each of the students created a login name without a problem, but when they tried to sign on to the site (and I had given them all editing permissions) they received the above message. This can be worked around clunkily with a couple of hard refreshes and a handy edit button on a post, but there is a better hack.

On the WPMU forums I found the following solution. According to this thread, and others like it, this is a more general issue with WPMU 1.0 and hasn’t really been addressed as of yet. However, as is often the case with open source applications, someone has come up with a quick hack that has worked perfectly for me thus far. Below is the code for the plugin to make this problem go away.
<?php
/*
Plugin Name: ADRX No Caps User Login
Plugin URI:
Description: This plugin determines what happens when a user logins in at a blog for which s/he has no capabilites.
*/
function adrx_nocaps_login() {
global $current_site, $current_blog, $current_user, $user_ID, $wpdb;
if (!is_blog_user() || !is_site_admin) { // no caps and not site admin
if ($current_blog->domain==$current_site->domain) { // logged in at main site — no caps
// if user has blog, send user there - code copied from menu.php
$primary_blog = $wpdb->get_var( “SELECT meta_value FROM {$wpdb->usermeta} WHERE user_id = ‘$user_ID’ AND meta_key = ‘primary_blog’” );
if( $primary_blog ) {
$newblog = $wpdb->get_row( “SELECT * FROM {$wpdb->blogs} WHERE blog_id = ‘{$primary_blog}’” );
if( $newblog != null ) {
header( “Location: http://” . $newblog->domain . $newblog->path . “wp-admin/” );
exit;
}
}
}
// user has no caps here
// user either has no existing primary blog of his/her own or did not log in at main site
// redirect to front page of the blog at which s/he logged in
header( “Location: http://” . $current_blog->domain. “/” );
exit;
}
}
add_action(’admin_menu’, ‘adrx_nocaps_login’);
?>

Just copy the above code into a text editor, save it as adrx.php, and copy it into the mu-plugins folder of your WPMU install. That’s it! Hopefully this will be solved in the next version, for it is a pretty big problem if you are going to have a multi-user blog within this environment.

Related posts

0 Responses to “WPMU permissions hack for new users”


  1. No Comments

Leave a Reply




EDUPUNK: DIY EdTech

about

bavatuesdays.com is an ongoing conversation about media of all kinds ...

Testimonials:

Generations from now, they won't call it the Internet anymore. They'll just say, "I logged on to the Jim Groom this morning.
-Joe McMahon
Everything Jim Groom touches is gold. He's like King Midas, but with the Internet.
-Serena Epstein

I am Jim Groom

Find out more about me here.

browse the bavarchive

I'm a twit

random gems from bavarchive

Free Rice Go Dog Go Word and image WPMu Blog Upload Space Quota April 2008 Calendar for the Bam Cinematek Hercules in the Haunted World
View more photos >

My netflix


Polls

What are your five favorite film adaptations of a Stephen King novel or story?

View Results

Loading ... Loading ...