Skip to:
Content
Pages
Categories
Search
Top
Bottom

How to hide CPT Links from profile view


  • ingohaeck
    Participant

    @ingohaeck

    For privacy issues I want to hide certain links on profile view.
    i use the snippet, mentioned here (see script below):
    one

    This works fine with BP related links, but I cannot hide links from CPT like rtMedia and the link of this:

    `function bp_postsonprofile() {
    add_action( ‘bp_template_content’, ‘profile_screen_posts_show’ );
    bp_core_load_template( apply_filters( ‘bp_core_template_plugin’, ‘members/single/plugins’ ) );
    }

    function profile_screen_posts_show() {

    $myposts = get_posts( array(
    ‘posts_per_page’ => -1,
    ‘author’ => bp_displayed_user_id(),
    ‘post_type’ => ‘post’
    ));

    if( ! empty($myposts) ) {

    echo ‘<ul>’;

    foreach($myposts as $post) {
    setup_postdata( $post );
    echo ‘<li><a href=”‘ . get_permalink($post->ID) . ‘”>’ . get_the_title($post->ID) . ‘</a></i>’;
    }

    echo ‘</ul>’;

    wp_reset_postdata();

    } else {

    echo ‘<div class=”info” id=”message”><p>’. bp_displayed_user_fullname() .’ hat keine Beiträge veröffentlicht.</p></div>’;
    }
    }

    add_action ( ‘profile_screen_posts_show’ );`

    function bpfr_hide_tabs() {
    global $bp;
    /**
    * class_exists() & bp_is_active are recommanded to avoid problems during updates
    * or when Component is deactivated
    */

    if( class_exists( ‘bbPress’ ) || bp_is_active ( ‘groups’ ) ) :

    /** here we fix the conditions.
    * Are we on a profile page ? | is user site admin ? | is user logged in ?
    */
    if ( bp_is_user() && !is_super_admin() && !is_user_logged_in() ) {

    /* and here we remove our stuff ! */
    bp_core_remove_nav_item( ‘activity’ );
    bp_core_remove_nav_item( ‘friends’ );
    bp_core_remove_nav_item( ‘groups’ );
    bp_core_remove_nav_item( ‘posts’ );
    bp_core_remove_nav_item( ‘forums’ );
    bp_core_remove_nav_item( ‘media’ );
    }
    endif;
    }
    add_action( ‘bp_setup_nav’, ‘bpfr_hide_tabs’, 15 );

Viewing 3 replies - 1 through 3 (of 3 total)

  • leog371
    Participant

    @leog371

    Just to be sure of what your asking, Are you trying to hide these from everyone including the person who owns the profile?

    Just in case you dont want to hide them from the profile owner, you should know that any links that are edit, upload rtmedia links only display for the profile owner and no one else and most other things like this are hidden by default from users and friends anyways. Only a profile owner can upload and make changes to his profile or post activity on their profiles.

    Also, each member has privacy options in their profile settings. You can set defaults in the dashboard for this as well.

    If this is not the case, could you clarify what you hope to achieve?

    If you simply wish to remove links for everyone in your site including the profile owner, just use something like this in bp-custom.php file

    /* Example to Remove subnav tabs from Group Settings  https://codex.buddypress.org/developer/navigation-api/#examples*/ 	
    	function remove_group_manager_subnav_tabs() {   
        // site admin will see all tabs
        if ( ! bp_is_group() || ! ( bp_is_current_action( 'admin' ) && bp_action_variable( 0 ) ) || is_super_admin() ) {
            return;
        }
           // all subnav items are listed here.
           // comment those you want to show
            $hide_tabs = array(             
            //  'group-settings'    => 1,
            //    'delete-group'      => 1,
             //   'group-avatar'      => 1,
            //  'group-invites'     => 1,
             //   'manage-members'    => 1,
            //  'forum'             => 1,
            //  'group-cover-image' => 1
            );
                       
            $parent_nav_slug = bp_get_current_group_slug() . '_manage';
      
        //Remove the nav items
        foreach ( array_keys( $hide_tabs ) as $tab ) {
            bp_core_remove_subnav_item( $parent_nav_slug, $tab, 'groups' );
        }   
    }
    add_action( 'bp_actions', 'remove_group_manager_subnav_tabs' );

    ingohaeck
    Participant

    @ingohaeck

    Thank for your hint. To clarify my issue:
    I just want to remove the „media“- tab for logged out users, that rtmedia adds to the profile . The snippet, which I posted before does the job an removes all tabs, but not the media tab.


    Peter Hardy-vanDoorn
    Participant

    @petervandoorn

    This may depend on your theme, and I don’t have rtmedia installed so you’ll have to work it out for yourself, but you should be able to just hide that tab using CSS.

    On my install of BuddyPress a class of logged-in is added to the body element when the user is logged in. Check your page to make sure that this is the same for you too.

    If it is, you can add CSS to target the rtmedia tab for people who aren’t logged in. Like I said, I don’t have rtmedia installed, so you’ll have to find out the class or ID of the media tab you want to get rid of for yourself (sorry!). But, for the sake of this example, let’s pretend it has an ID of “rtmediatab”.

    So, you could add a line something like this to your CSS and the tab would be hidden:

    body:not(.logged-in) #rtmediatab { display: none; }

    Obviously it doesn’t remove it completely as the underlying HTML will still be in the page, but it won’t be visible on the page and that’s better than nothing.

    Hope that helps

Viewing 3 replies - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.
Skip to toolbar