BP_REST_Group_Settings_Endpoint::get_forum_fields( integer $group_id )
Get Group forum Settings.
Description
Parameters
- $group_id
-
(Required) Group ID.
Return
(mixed|void)
Source
File: bp-groups/classes/class-bp-rest-group-settings-endpoint.php
protected function get_forum_fields( $group_id ) { $fields = array(); buddypress()->groups->current_group = groups_get_group( $group_id ); if ( ! bp_is_active( 'forums' ) || ! function_exists( 'bbp_is_group_forums_active' ) || ! bbp_is_group_forums_active() ) { return new WP_Error( 'bp_rest_invalid_group_setting_nav', __( 'Sorry, you are not allowed to see the forum group settings options.', 'buddyboss' ), array( 'status' => 400, ) ); } $forum_id = 0; $forum_ids = bbp_get_group_forum_ids( $group_id ); // Get the first forum ID. if ( ! empty( $forum_ids ) ) { $forum_id = (int) is_array( $forum_ids ) ? $forum_ids[0] : $forum_ids; } $checked = bp_get_new_group_enable_forum() || bp_group_is_forum_enabled( $group_id ); $fields[] = array( 'label' => esc_html__( 'Group Forum Settings', 'buddyboss' ), 'name' => '', 'description' => esc_html__( 'Create a discussion forum to allow members of this group to communicate in a structured, bulletin-board style fashion.', 'buddyboss' ), 'field' => 'heading', 'value' => '', 'options' => array(), ); $fields[] = array( 'label' => esc_html__( 'Yes. I want this group to have a discussion forum.', 'buddyboss' ), 'name' => 'bbp-edit-group-forum', 'description' => esc_html__( 'Saying no will not delete existing forum content.', 'buddyboss' ), 'field' => 'checkbox', 'value' => $checked, 'options' => array(), ); if ( bbp_is_user_keymaster() ) { $forum_field = array( 'label' => esc_html__( 'Group Forum:', 'buddyboss' ), 'name' => 'bbp_group_forum_id', 'description' => esc_html__( 'Only site administrators can reconfigure which forum belongs to this group.', 'buddyboss' ), 'field' => 'select', 'value' => $forum_id, 'options' => array(), ); $forums = get_posts( array( 'post_type' => 'forum', 'numberposts' => -1, 'orderby' => 'menu_order title', 'order' => 'ASC', 'disable_categories' => true, ) ); if ( ! empty( $forums ) ) { $forum_field['options'][] = array( 'label' => esc_html__( '(No Forum)', 'buddyboss' ), 'value' => '', 'description' => '', 'is_default_option' => empty( $forum_id ), ); foreach ( $forums as $forum ) { $title = $forum->post_title; if ( '' === $title ) { /* translators: %d: ID of a post. */ $title = sprintf( __( '#%d (no title)', 'buddyboss' ), $forum->ID ); } $forum_field['options'][] = array( 'label' => $title, 'value' => $forum->ID, 'description' => '', 'is_default_option' => $forum_id === $forum->ID, ); } } $fields[] = $forum_field; } return apply_filters( 'bp_rest_group_settings_forum', $fields, $group_id ); }
Questions?
We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.