0

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?

1
  • Did you confirm this code as working before you tweaked it? – editor Jan 18 '11 at 23:00
2

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
    }
}
4
  • 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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