Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I need to have users land on a specific admin page based on user role in WP 3.0 multi-site enabled. I found this

function fb_redirect_2() {

    if ( preg_match('#wp-admin/?(index.php)?$#', $_SERVER['REQUEST_URI']) ) {
        if ( function_exists('admin_url') ) {
            wp_redirect( admin_url('edit-comments.php') );
        } else {
            wp_redirect( get_option('siteurl') . '/wp-admin/' . 'edit-comments.php' );
        }
    }
}
if ( is_admin() )
    add_action( 'admin_menu', 'fb_redirect_2' );

And changed

if ( is admin() ) 

to

if ( current_user_can('edit_posts') )

but this isn't working...

Any Suggestions?

share|improve this question
    
Did you confirm this code as working before you tweaked it? –  editor Jan 18 '11 at 23:00
add comment

1 Answer

you need to populate the

current_user_can('') 

function before using it using

  get_currentuserinfo();

so try this code:

add_action( 'admin_menu', 'fb_redirect_2' );

function fb_redirect_2(){
    get_currentuserinfo();
    if ( current_user_can('edit_posts')){
    //redirect here
    }
}
share|improve this answer
    
Thanks! This worked great. Obviously I know enough PHP to be dangerous;-) I am also finding this works for WP standard roles, however on the custom roles defined in functions.php it totally ignores the whole thing??? Anyone have any idea - I'm off to search... –  Ann Jan 19 '11 at 0:00
    
did you define the capabilities of the custom roles? –  Bainternet Jan 19 '11 at 0:29
    
yes. in the functions.php file It seems to be dependent on what happens first - the role declaration or the redirect rule? –  Ann Jan 19 '11 at 17:34
    
Actually if user tries to log in at main domain, the rule is ignored because of the role specification for that site... works fine when they log in at maindomain.com/theirsite. I am now looking for a way to have the user re-directed to their member blog backend... if any body has an suggestions I would gladly accept! Meanwhile searching... –  Ann Jan 21 '11 at 19:44
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.