regnalf (@regnalf)

Forum Replies Created

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

  • regnalf
    Participant

    @regnalf

    as no one answer this, i tried it by myself. i found a function in bbp-style-pack plugin for that.

    if (function_exists('bsp_is_forum_unread_amount'))
    {
    	
    	add_shortcode( 'bbp_count_new', 'bbpress_count_new' );
    	function bbpress_count_new( $atts )
    	{
    		
    		$output = "";
    		$count_new = 0;
    		
    
    		$query_foren = new WP_Query(array( 'post_type' => 'forum' ));
    		
    		
    		while($query_foren->have_posts())
    		{
    			$query_foren->the_post();
    			
    			$post_id = get_the_id();
    			
    			$bbp_forum_privategroups = get_post_meta( $post_id, '_private_group');			
    			$bbp_user_privategroups = preg_split('/\*/', get_user_meta (get_current_user_id(), 'private_group', true), -1, PREG_SPLIT_NO_EMPTY);
    			
    			if ( count( $bbp_forum_privategroups ) == 0 )
    			{
    				$amount_unr = bsp_is_forum_unread_amount( $post_id );
    				$count_new += $amount_unr->amount;
    			}
    			else
    			{
    				if ( count( array_intersect( $bbp_forum_privategroups, $bbp_user_privategroups )) > 0 )
    				{
    					$amount_unr = bsp_is_forum_unread_amount( $post_id );
    					$count_new += $amount_unr->amount;
    				}
    			}
    		}
    		
    		if ($count_new > 0 )
    		{
    			ob_start();
    			?><span style="margin-left: 0.3rem; font-size: 0.8rem; padding: 0.4rem;"> <?php echo($count_new); ?></span><?php
    			$output = ob_get_contents();
    			ob_end_clean();
    		}
    		
    		return $output;
    	}
    
    	
    }

    i hope i didn’t oversee something, because it is also combined with private forum groups!


    regnalf
    Participant

    @regnalf

    I don’t know how you excactly you want to style the forum index page, but i found out that the index page doesn’t have the bbpress class included in the body tag like the sub pages. So i had the problem too that i couldn’t style the index page.

    Here is my code i use to add this class, and others, to the body tag for the index page. Then you can style the index page with css.

    add_filter( 'body_class', 'bbpress_add_body_class' );
    function bbpress_add_body_class( $classes )
    {
    
    	global $wp;
    
    	$bbpress_index = get_option ('_bbp_root_slug');
    	$bbpress_search = get_option ('_bbp_search_slug');
    	
    
    	if (strpos($wp->request, $bbpress_index) !== false)
    	{
    		$classes[] = "bbpress";		
    	}
    
    	if ($wp->request == $bbpress_index)
    	{
    		$classes[] = "bbpress-index";
    	}
    
    	if (strpos($wp->request, $bbpress_index . "/" . $bbpress_search) !== false)
    	{
    		$classes[] = "bbpress-search";		
    	}
    	
    
    	return $classes;
    	
    }

    regnalf
    Participant

    @regnalf

    Thanks Robin!

    And here for the record the full code i use:

    add_filter('bbp_get_breadcrumb', 'bbpress_filter_breadcrumbs', 10, 4);
    function bbpress_filter_breadcrumbs ($trail, $crumbs, $r, $args)
    {
       return '<div class="bbp-breadcrumbs">' . $trail . '</div>';
    }
    

    regnalf
    Participant

    @regnalf

    use if(strpos($wp->request, $bbpress_index) !== false) if you also want to restrict all possible sub-urls!


    regnalf
    Participant

    @regnalf

    bbpress private groups does a good job to hide forums, but that still doesn’t remove the index page. if anyone needs to restrict the index page for a complete private forum, here is the code:

    add_action( 'wp', 'restrict_bbpress' );
    function restrict_bbpress()
    {
    
    	global $wp;
    	global $wp_query;	
    	
    	$bbpress_index = get_option ('_bbp_root_slug');
    	
    	if ($wp->request == $bbpress_index)
    	{
    
    		$user = get_userdata(get_current_user_id());
    		
    // Example for a user role member
    		if (! is_user_logged_in() || 
    		    ! in_array( 'member', (array) $user->roles ))
    		{
    			$wp_query->set_404();
    			status_header( 404 );
    		}
    
    	}
    
    }

    regnalf
    Participant

    @regnalf

    WOW, Thanks for that fast reply!!! I will check it out.

    Thank you


    regnalf
    Participant

    @regnalf

    Ok, can i restrict this more for a specific user role?

    Actually i want to have a forum that is for special members only. So nothing should be visible, accessable or should be found without a special role.


    regnalf
    Participant

    @regnalf

    I need this functionality too, no answers yet?

    In reply to: CSS on Index Page

    regnalf
    Participant

    @regnalf

    I wanted to style the body tag too, in the subpages like topic or forum the css class is in the body class section. the #bbpress-forums is deeper inside the page.


    regnalf
    Participant

    @regnalf

    It’s about the [bbp-forum-index], but it seem that the failure is coming from my theme (pro from theme.co)

    If I style the page with their builder the output seems to be broken. It works if the page is created with the standard WordPress editor.

    I will contact them about this.


    regnalf
    Participant

    @regnalf

    Found this, while searching for a solution with the shortcode on an own page. This issues seems still exist in 2021!!! If i create a page with shortcode the page show an empty page if the forum index has the same permalink as the the page!

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