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'm looking a way to avoid regular users go to profile and dashboard page. Have this little code to work with profile page:

function lockdown_profile()
{
    global $current_user;
    return !current_user_can( 'manage_options' ) ? wp_redirect("/profile") : true;
}
add_action('show_user_profile', "lockdown_profile");

And works, but i need to do the same for dashboard page, any ideas?

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

show_user_profile is the wrong hook to use. You should redirect before anything gets sent to the browser (eg. before headers are sent).

Fortunately there are actions that happen much earlier: load-{$pagename} is the one you want. So you can hook into load-index.php and load-profile.php to throw people back to the front end.

<?php
add_action( 'load-profile.php', 'wpse35742_maybe_redirect' );
add_action( 'load-index.php', 'wpse35742_maybe_redirect' );
function wpse35742_maybe_redirect()
{
    if( current_user_can( 'manage_options' ) ) return;
    wp_redirect( home_url( '/profile' ), 302 );
    exit();
}

All that said, you would be better off adding a new role that has even more limited capabilities than the typical subscribers: don't let them view the dashboard or their profiles (the read capability).

share|improve this answer
    
This work great, thank you. –  greenbandit Dec 7 '11 at 6:21
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.