Skip to:
Content
Pages
Categories
Search
Top
Bottom

I want to hide View on BP activity for logged out users


  • Dono12
    Participant

    @dono12

    I’m trying to hide the view link on buddypress user activity page.
    Location member-header.php

    filter bp_get_activity_latest_update

    What’s an example function to either redirect user, show a pop-up alert(maybe too fancy)-when clicked or just hide the View link from logged out users.

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

  • Rimon Habib
    Participant

    @rimon_habib

    you can redirect logged out users from activity page to home (or any page you prefer) using this function

    function restrict_activity_page_from_logged_out_users(){
    
    global $bp;
    if( $bp->current_component === 'activity' && !is_user_logged_in() )
    bp_core_redirect( site_url() ); // for home page; or use wp_login_url() to redirect to login page
    exit;
    
    }
    
    add_action('wp','restrict_activity_page_from_logged_out_users');

    shanebp
    Moderator

    @shanebp

    Remove the link:

    function dono_remove_view_link( $latest_update ) {
    
    	if ( ! is_user_logged_in() ) {
    	
    		$text = preg_replace('/<a href=\"(.*?)\">(.*?)<\/a>/', "\\2", $latest_update);
    		
    		$link_text =  esc_attr__( 'View', 'buddypress' );
    		
    		$latest_update = rtrim($text, $link_text);
    		
    	}
    	
    	return $latest_update;
    }
    add_filter( 'bp_get_activity_latest_update', 'dono_remove_view_link', 1, 100 );

    Dono12
    Participant

    @dono12

    Thanks Rimon and Shane bp for your reply.

    Shanebp your solution is the one I’m looking for except it doesn’t seem to have any affect. I tried the function first in bp_custom and then in funtions.php both didn’t work. What am I missing?


    shanebp
    Moderator

    @shanebp

    It worked on my install. In bp-custom.
    Were you logged out when you tried it?


    Dono12
    Participant

    @dono12

    Yes. I might add I have bbpress child theme don’t think that should matter

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