Skip to:
Content
Pages
Categories
Search
Top
Bottom

BBPress Create Forum Shortcode not working


  • deandimarzo
    Participant

    @deandimarzo

    I’m using the [bbp-forum-form] shortcode to allow forum moderators to add subforums on our site (is there a better way to do this?) and when submitting the form I get the error “ERROR: Your forum must have a parent.”

    I’ve dug through the source code thoroughly to figure out what would be causing this and I just can’t track it down. Any ideas?

Viewing 1 replies (of 1 total)

  • Robin W
    Moderator

    @robin-w

    yes this seems to be a bug.

    in

    \bbpress\includes\forums\functions.php

    line 197 has

    // No forum parent was passed (should never happen)
    	if ( empty( $forum_parent_id ) ) {
    		bbp_add_error( 'bbp_new_forum_missing_parent', __( '<strong>ERROR</strong>: Your forum must have a parent.', 'bbpress' ) );

    but a top level forum will have zero so empty !

    (I’m not a bbpress author, I just help moderate here, so not under my direct powers to change)

    To correct this for another user, I did the following :

    created a hidden forum – then noted the ID (in this case 4537)

    then in

    \bbpress\templates\default\bbpress\form-forum.php

    changed line 138 etc. from

    <p>
    						<label for="bbp_forum_parent_id"><?php esc_html_e( 'Parent Forum:', 'bbpress' ); ?></label><br />
    
    						<?php
    							bbp_dropdown( array(
    								'select_id' => 'bbp_forum_parent_id',
    								'show_none' => esc_html__( '&mdash; No parent &mdash;', 'bbpress' ),
    								'selected'  => bbp_get_form_forum_parent(),
    								'exclude'   => bbp_get_forum_id()
    							) );
    						?>
    					</p>

    to

    <?php
    					//the code in incudes/forums/functions won't let post parent be blank.
    					//to get this to work, we have created a hidden forum in the site.  This forums ID is 4537
    					//if the hidden forum exists, then use this forums id 
    					//otherwise show the post parent section
    					$forum_parent_id = bbp_get_forum_id( 4537 );
    					if (!empty( $forum_parent_id )) { ?>
    					 <input type="hidden" id="bbp_forum_parent_id" name="bbp_forum_parent_id" value="4537">
    					 <?php
    					}
    					else {
    					?>
    					<p>
    						<label for="bbp_forum_parent_id"><?php esc_html_e( 'Parent Forum:', 'bbpress' ); ?></label><br />
    
    						<?php
    							bbp_dropdown( array(
    								'select_id' => 'bbp_forum_parent_id',
    								'show_none' => esc_html__( '&mdash; No parent &mdash;', 'bbpress' ),
    								'selected'  => bbp_get_form_forum_parent(),
    								'exclude'   => bbp_get_forum_id()
    							) );
    						?>
    					</p>
    					<?php } ?>

    This template then gets saved to your child themes directory as

    wp-content/themes/%your-theme-name%/bbpress/form-forum.php

    bbPress will now use this template instead of the original

    Finally, add an action to re-write the parent forum from 4537 to zero post forum creation

    add_action( 'bbp_new_forum_post_extras', 'ltc_limit_forum', 10 ,1  );
    
    function ltc_limit_forum ($forum_id) {
    	//this function is fired when a forum is created
    	//set post parent to zero
    	wp_update_post(
    		array(
    			'ID' => $forum_id, 
    			'post_parent' => 0
    			)
    	);
    }

    Put this in your child theme’s function file –

    ie wp-content/themes/%your-theme-name%/functions.php

    where %your-theme-name% is the name of your theme

    or use

    Code Snippets

    You could amend that function to have an if statement so if forum parent is 4537 then create forum parent as 0, but in this case there were no times when a sub forum was being created, so it was not needed.

    I know this is quite convoluted, but it worked !!

    There is a trac ticket for this issue somewhere, so the authors are aware

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