[wpmu-trac] Re: [WordPress MU Trac] #415: Redirect error to admin
page
WordPress MU Trac
wpmu-trac at lists.automattic.com
Tue Oct 16 13:04:17 GMT 2007
#415: Redirect error to admin page
------------------------+---------------------------------------------------
Reporter: Giraffian | Owner: somebody
Type: defect | Status: new
Priority: high | Milestone: WPMU 2.0
Component: component1 | Version: 2.0
Severity: critical | Resolution:
Keywords: |
------------------------+---------------------------------------------------
Comment (by ktlee):
This error occurs because the primary_blog meta tag in the wp_usermeta
table didn't get change when user creating a new blog.
this is the code that is causing the infinite redirection loop.
in file wp-admin/menu.php
{{{
{{{
if (! user_can_access_admin_page()) {
global $wpdb;
// find the blog of this user first
$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;
}
}
wp_die( __('You do not have sufficient permissions to access this
page.') );
}
}}}
}}}
Before user sign up for a blog, they will not get redirection error
because user is a subscriber in your main blog i.e. blogid=1 and
by default when user sign up for user account only, they are assign to
blogid=1 with subscribe role)
The problem arise when user come back and sign up for a blog, user default
role as subscriber in the main blog got deleted, and their primary_blog
didn't get updated. As the result, when user login from sites other than
his/her site, he got forward to their primary blog which is wrong (since
it didn't get updated). Redirection keeps happening because user trying to
access the main blog backend while he or she doesn't has the proper
permission to visit the page (because when you create a new blog the role
in default blog got deleted.) etc
Unfortunately, the way to solve this problem is using phpMyAdmin to edit
user's primary_blog meta tag to his new blog id in wp_usermeta table.
Sorry, I can't really find a way to make it workaround. =(
'''To prevent this from happening:'''
When creating another blog with validate_another_blog_signup()
check if the current primary_blog tag is 1 if it's 1 changed it to the new
created blog id.
wp-signup.php line 216
change
{{{
wpmu_create_blog($domain, $path, $blog_title, $current_user->id, $meta);
confirm_another_blog_signup($domain, $path, $blog_title,
$current_user->user_login, $current_user->user_email, $meta);
}}}
to
{{{
$blogid = wpmu_create_blog($domain, $path, $blog_title,
$current_user->id, $meta);
confirm_another_blog_signup($domain, $path, $blog_title,
$current_user->user_login, $current_user->user_email, $meta);
if(get_usermeta($current_user->ID, 'primary_blog')==1)
update_usermeta($current_user->ID, 'primary_blog',
$blog_id);
}}}
donncha, you might want to include this into core, because the problem
does exits. =(
Sorry for this long posting.
--
Ticket URL: <http://trac.mu.wordpress.org/ticket/415#comment:5>
WordPress MU Trac <http://mu.wordpress.org/>
WordPress Multiuser
More information about the wpmu-trac
mailing list