Group Mods

  • Profile picture of @mercime
  • Profile picture of r-a-y
  • Profile picture of Hugo

Hiding activity content for non-logged users (5 posts)

Started 1 year, 3 months ago by: josemv

  • Profile picture of josemv josemv said 1 year, 3 months ago:

    Hi there,

    I realized that instead of blocking the whole activity page to non-logged users I could just hide the activity content and leave the activity header intact
    How can I achieve this ? So far, the only thing I found is @nuprn1 code here: http://etivite.com/groups/buddypress/forum/topic/quick-tip-hide-activity-updates-andor-replies-by-types-for-non-logged-visitors-in-users/

    //block activity stream parent comment and children replies
    function my_bp_get_activity_content_body( $content, $activity ) {
    	global $activities_template, $bp;
    
    	if ( is_user_logged_in() )
    		return $content;
    
    	if ( !my_bp_get_activity_content_body_hide_check($activities_template->activity->type) )
    		return $content;
    
    	$activity->children = null;
    
    	$content .= sprintf( __( 'To view this activity - please <a href="%s" title="Create an account">log in</a> first.', 'buddypress' ), $bp->root_domain . '/wp-login.php?redirect_to=' . urlencode( bp_activity_get_permalink( $activities_template->activity->id ) ) );
    	if ( bp_get_signup_allowed() )
    		$content .= '<span class="acomment-loginlink">'. sprintf( __( ' You can also <a href="%s" title="Create an account">create an account</a>.', 'buddypress' ), site_url( BP_REGISTER_SLUG . '/' ) ) .'</a></span>';
    
    	return $content;
    
    }
    add_filter('bp_get_activity_content_body', 'my_bp_get_activity_content_body', 1, 2);
    
    //any type here to define
    function my_bp_get_activity_content_body_hide_check( $type ) {
    	return in_array( $type, apply_filters( 'bp_activity_block_denied_activity_types', array( 'activity_update' ) ) );
    }

    But I do not know how to tailor it to my needs…any help is appreciated !

  • Profile picture of josemv josemv said 1 year, 3 months ago:

    Anyone ?

  • Profile picture of Virtuali Virtuali said 1 year, 3 months ago:

    Put it into your bp-custom.php, and there ya go!

    Although it hasn’t been updated to work in the latest versions on buddypress, so I am not guaranteeing that it will work.

  • Profile picture of TimCarey TimCarey said 1 year, 2 months ago:

    Would you know how to do this for the group-header? I would like the group-header too be nonexistent during a certain condition. But I like to do this in my plug in.

  • Profile picture of josemv josemv said 1 year, 2 months ago:

    @gunju2221 yep, did that, but all it does is add “To view this activity – please log in first. You can also create an account.” after showing the activty, it does not hide it for unlogged users. Using 1.2.7 with 3.0.5