knaveenchand (@knaveenchand)

Forum Replies Created

Viewing 2 replies - 1 through 2 (of 2 total)
  • In reply to: Q and A using bbpress

    knaveenchand
    Participant

    @knaveenchand

    Thanks for both @Lync and @netweb. I have been able to use lead topic function and it worked. I have reviewed the link you sent as an alternative to str_replace. I now have a different yet related question: Is it possible to have different headers for different forums. For instance, can I have one template for Q and A forum and another template for Jobs forum, and so on…? In each of the forum, I would prefer a different header. Is it possible to get this done through PO MO files or str_replace or any other functions? Thanks for your help.


    knaveenchand
    Participant

    @knaveenchand

    Thanks for the hint provided by @Rafael. I would like to add here that in order to keep the change in tact, it is better to edit it through our functions.php file in our theme directory so that even if bbpress gets updated, our changes remain intact. So I created these two functions along add_filter functions:

    /**
     * The main forum loop. THIS IS CUSTOMISED TO ORDERBY TITLE INSTEAD OF MENU_ID
     *
     * WordPress makes this easy for us.
     *
     * @since bbPress (r2464)
     *
     * @param mixed $args All the arguments supported by {@link WP_Query}
     * @uses WP_Query To make query and get the forums
     * @uses bbp_get_forum_post_type() To get the forum post type id
     * @uses bbp_get_forum_id() To get the forum id
     * @uses get_option() To get the forums per page option
     * @uses current_user_can() To check if the current user is capable of editing
     *                           others' forums
     * @uses apply_filters() Calls 'bbp_has_forums' with
     *                        bbPres::forum_query::have_posts()
     *                        and bbPres::forum_query
     * @return object Multidimensional array of forum information
     */
    function mybbp_has_forums( $args = '' ) {
    	$bbp = bbpress();
    
    	// Setup possible post__not_in array
    	$post_stati[] = bbp_get_public_status_id();
    
    	// Check if user can read private forums
    	if ( current_user_can( 'read_private_forums' ) )
    		$post_stati[] = bbp_get_private_status_id();
    
    	// Check if user can read hidden forums
    	if ( current_user_can( 'read_hidden_forums' ) )
    		$post_stati[] = bbp_get_hidden_status_id();
    
    	// The default forum query for most circumstances
    	$defaults = array (
    		'post_type'      => bbp_get_forum_post_type(),
    		'post_parent'    => bbp_is_forum_archive() ? 0 : bbp_get_forum_id() ,
    		'post_status'    => implode( ',', $post_stati ),
    		'posts_per_page' => get_option( '_bbp_forums_per_page', 50 ),
    		'orderby'        => 'title',
    		'order'          => 'ASC'
    	);
    	$bbp_f = bbp_parse_args( $args, $defaults, 'has_forums' );
    
    	// Run the query
    	$bbp->forum_query = new WP_Query( $bbp_f );
    
    	return apply_filters( 'mybbp_has_forums', $bbp->forum_query->have_posts(), $bbp->forum_query );
    }
    add_filter('bbp_has_forums','mybbp_has_forums');
    
    //this is CUSTOMIZED to just get the subforums ordered by title instead of menu_id
    
    function myybbp_forum_get_subforums( $args = '' ) {
    
    	// Use passed integer as post_parent
    	if ( is_numeric( $args ) )
    		$args = array( 'post_parent' => $args );
    
    	// Setup possible post__not_in array
    	$post_stati[] = bbp_get_public_status_id();
    
    	// Super admin get whitelisted post statuses
    	if ( is_super_admin() ) {
    		$post_stati = array( bbp_get_public_status_id(), bbp_get_private_status_id(), bbp_get_hidden_status_id() );
    
    	// Not a super admin, so check caps
    	} else {
    
    		// Check if user can read private forums
    		if ( current_user_can( 'read_private_forums' ) ) {
    			$post_stati[] = bbp_get_private_status_id();
    		}
    
    		// Check if user can read hidden forums
    		if ( current_user_can( 'read_hidden_forums' ) ) {
    			$post_stati[] = bbp_get_hidden_status_id();
    		}
    	}
    
    	$defaults = array(
    		'post_parent'    => 0,
    		'post_type'      => bbp_get_forum_post_type(),
    		'post_status'    => implode( ',', $post_stati ),
    		'posts_per_page' => get_option( '_bbp_forums_per_page', 50 ),
    		'orderby'        => 'title',
    		'order'          => 'ASC'
    	);
    	$r = bbp_parse_args( $args, $defaults, 'forum_get_subforums' );
    	$r['post_parent'] = bbp_get_forum_id( $r['post_parent'] );
    
    	// No forum passed
    	$sub_forums = !empty( $r['post_parent'] ) ? get_posts( $r ) : '';
    
    	return apply_filters( 'mybbp_forum_get_sub_forums', (array) $sub_forums, $args );
    }
    add_filter('bbp_forum_get_sub_forums','mybbp_forum_get_sub_forums');
    

    This may not be elegant solution but it saves us from the annoying impacts on bbpress updates.

    I would love to hear from developers on this forum on how best this can be implemented without copy-pasting the entire function just to change one small variable and then giving it a new function name and then adding filters. Is there a better way, friends?

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