1

I'm running a BuddyPress installation with BBPress. In step 3 of the Group Creation, there is an option to add a forum for that group and I want all groups to have a forum, so I'm customising the BuddyPress file for groups; create.php and I found that the relevant code for the "should this group have a forum"-checkbox is there. I've tried setting the checked="checked"-attribute but nothing's changed.

I want to have it checked by default and then hidden with CSS, this way the user doesn't even see the choice and the forum gets created along with the group.

The according code:

<p><?php _e( 'Should this group have a forum?', 'buddypress' ); ?></p>

<div class="checkbox">
    <label for="group-show-forum"><input type="checkbox" name="group-show-forum" id="group-show-forum" value="1" checked="checked" <?php checked( bp_get_new_group_enable_forum(), true, true ); ?> /> <?php _e( 'Enable discussion forum', 'buddypress' ); ?></label>
</div>
Sainan
  • 1,274
  • 2
  • 19
  • 32

1 Answers1

0

You are setting checked twice. Try:

<input type="checkbox" name="group-show-forum" id="group-show-forum" value="1" checked="checked" /> <?php _e( 'Enable discussion forum', 'buddypress' ); ?>

Or, instead of hacking create.php, use the filter hook: apply_filters( 'bp_get_new_group_enable_forum', $forum );

function james_default_enable_forum( $forum ) {
    $forum = 1;
    return $forum;
}
add_filter( 'bp_get_new_group_enable_forum', 'james_default_enable_forum', 10, 1 );
shanebp
  • 1,904
  • 3
  • 17
  • 28
  • Thanks, works great. And thanks for taking the time to give the filter hook. It's obviously far better. – David James Oct 14 '16 at 18:40
  • You are welcome. Please accept the answer. http://stackoverflow.com/help/accepted-answer – shanebp Oct 15 '16 at 13:32
  • @shanebp you have mentioned bp_get_new_group_enable_forum as a filter and used as action !! I checked code it is a filter so why not apply_filter , aslo it is returning $forum . sorry for interruption, but I am reading buddy press from stack as no good doc found beside some stuffs in official doc . – Prafulla Kumar Sahu Jul 10 '17 at 14:01