WordPress.org

Support

Support » Plugins and Hacks » Hacks » Redirect user to dedicated page based on user role while logged in

Redirect user to dedicated page based on user role while logged in

Viewing 2 replies - 1 through 2 (of 2 total)
  • Needs some work, but maybe something like this added to your theme’s functions.php (you should create a child theme to protect your theme hacks from theme upgrades):

    function warn_redirect() {
       global $post;
       if( 1234 == $post->ID && !current_user_can('edit_pages')) {
          wp_safe_redirect('/warning-permlink');
       }
    }
    add_action('template_redirect', 'warn_redirect');

    Change 1234 to the actual ID of the My_Account page, assuming it is a WP post type ‘page’ which has IDs just as regular posts do. Change ‘edit_pages’ to a capability that the warning user does NOT have but users that do not get the warning DO have. The Members plugin makes it easy to set capabilities up any way you like. Change ‘/warning-permalink’ to the actual permalink or url to the warning page. Untested, so may need tweaking beyond the changes outlined. Good luck.

    Thank you so much BCWorkz, I’ll definitely give this a try and tweak it to match the content on my end.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Redirect user to dedicated page based on user role while logged in’ is closed to new replies.