Skip to:
Content
Pages
Categories
Search
Top
Bottom

[Resolved] Hide profile if not profile-owner


  • myjosephines
    Participant

    @myjosephines

    I have googled and searched this forum, and tried different types of codes. But nothing works well. Most of the examples given are several years old. So I hope to work it out by posting this question instead.

    I would like to hide the members profile by using if statement where it checks if the person visiting a profile is the profile-owner or not.

    A few of the codes I have tried (I also tried some functions-ones) are:

    <?php
    if ( bp_is_my_profile() == 1 )
    {
    
    echo 'yes';
    
    } else {
    
    echo 'no';
    
    }
    ?>
    <?php
        global $bp;
    	
        $current_user_id = (int) trim($bp->loggedin_user->id);
    
        $author_id  = (int) trim($bp->displayed_user->id);
    
        if ($current_user_id !== $author_id) :?>
    
    no
    <?php else : ?>
    yes
    
    <?php endif; ?>

    Both of the examples give out the same echo on both being logged in and at my own profile, and for being logged out. So it’s not doing what I’d like it to do. :/

Viewing 1 replies (of 1 total)

  • myjosephines
    Participant

    @myjosephines

    And of course I find a solution AFTER I post this. 😛

    I think this code into the function solved it:

    function my_private_profiles() {
    
        // Bail if not a profile page.
        if ( ! bp_is_user_profile() )
            return;
    
        // Allow admin users.
        if ( current_user_can( 'manage_options' ) )
            return;
    
        // Allow the profile owner.
        if ( bp_loggedin_user_id() == bp_displayed_user_id() )
            return;
    
        // If we get to here, redirect to homepage.
        bp_core_redirect( home_url() );
    }
    add_action( 'init', 'my_private_profiles' );
Viewing 1 replies (of 1 total)
  • The topic ‘[Resolved] Hide profile if not profile-owner’ is closed to new replies.
Skip to toolbar