Skip to:
Content
Pages
Categories
Search
Top
Bottom

Forum Replies Created

Viewing 1 replies (of 1 total)
  • @rammysons

    Participant

    Hello,

    It seems like you’re working on a multi-author website and you’re looking for a way to control access to user profiles. Specifically, you’ve implemented code to deny access to administrators’ profiles, and you’re interested in extending this functionality to subscribers as well.

    To achieve this, you can modify the code you provided to include conditions for subscribers. Here’s an example of how you might achieve this:

    php
    Copy code
    // deny access to admins and subscribers profiles. Users are redirected to the homepage
    function bpfr_hide_admins_and_subs_profile() {
    global $bp;

    // Get the current user’s role
    $current_user = wp_get_current_user();
    $user_roles = $current_user->roles;

    // Check if the user is an admin or a subscriber
    if (bp_is_profile && $bp->loggedin_user->id != 1 &&
    (in_array(‘administrator’, $user_roles) || in_array(‘subscriber’, $user_roles))) :
    wp_redirect(home_url());
    exit;
    endif;
    }
    add_action(‘wp’, ‘bpfr_hide_admins_and_subs_profile’, 1);
    This code snippet checks if the currently displayed user’s role is either “administrator” or “subscriber,” and if the conditions are met, it redirects the user to the homepage.

    Remember to replace ‘administrator’ and ‘subscriber’ with the actual role names used in your WordPress setup.

    Thank you for reaching out, and a special shoutout to “TWITCHFOLLOWERFORGE“. If you have any further questions or need additional assistance, feel free to ask!

Viewing 1 replies (of 1 total)
Skip to toolbar