Skip to:
Content

BuddyPress.org

Changeset 11176


Ignore:
Timestamp:
10/06/2016 07:55:32 AM (3 years ago)
Author:
r-a-y
Message:

Groups Admin: Better support for multiple group types.

If more than one group type is registered:

  • When editing a group, you can now set multiple group types for that group.
  • When viewing the Groups admin dashboard, all group types for a group are displayed in the "Group Type" column.

See #7210.

Location:
trunk/src/bp-groups
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-groups/bp-groups-admin.php

    r11139 r11176  
    10471047    }
    10481048
    1049     $types = bp_groups_get_group_types( array(), 'objects' );
    1050     $current_type = bp_groups_get_group_type( $group->id );
     1049    $types         = bp_groups_get_group_types( array(), 'objects' );
     1050    $current_types = bp_groups_get_group_type( $group->id, false );
     1051    $backend_only  = bp_groups_get_group_types( array( 'show_in_create_screen' => false ) );
    10511052    ?>
    10521053
     
    10551056        esc_html_e( 'Select group type', 'buddypress' );
    10561057    ?></label>
    1057     <select name="bp-groups-group-type" id="bp-groups-group-type">
    1058         <option value="" <?php selected( '', $current_type ); ?>><?php /* translators: no option picked in select box */ esc_attr_e( '----', 'buddypress' ) ?></option>
     1058
     1059    <ul class="categorychecklist form-no-clear">
    10591060        <?php foreach ( $types as $type ) : ?>
    1060             <option value="<?php echo esc_attr( $type->name ) ?>" <?php selected( $type->name, $current_type ) ?>><?php echo esc_html( $type->labels['singular_name'] ) ?></option>
     1061            <li>
     1062                <label class="selectit"><input value="<?php echo esc_attr( $type->name ) ?>" name="bp-groups-group-type[]" type="checkbox" <?php checked( true, in_array( $type->name, $current_types ) ); ?>>
     1063                    <?php
     1064                        echo esc_html( $type->labels['singular_name'] );
     1065                        if ( in_array( $type->name, $backend_only ) ) {
     1066                            printf( ' <span class="description">%s</span>', esc_html__( '(Not available on the frontend)', 'buddypress' ) );
     1067                        }
     1068                    ?>
     1069
     1070                </label>
     1071            </li>
     1072
    10611073        <?php endforeach; ?>
    1062     </select>
     1074
     1075    </ul>
    10631076
    10641077    <?php
     
    10731086 */
    10741087function bp_groups_process_group_type_update( $group_id ) {
    1075     if ( ! isset( $_POST['bp-group-type-nonce'] ) || ! isset( $_POST['bp-groups-group-type'] ) ) {
     1088    if ( ! isset( $_POST['bp-group-type-nonce'] ) ) {
    10761089        return;
    10771090    }
     
    10841097    }
    10851098
    1086     // Group type string must either reference a valid group type, or be empty.
    1087     $group_type = wp_unslash( $_POST['bp-groups-group-type'] );
    1088     if ( $group_type && ! bp_groups_get_group_type_object( $group_type ) ) {
    1089         return;
    1090     }
     1099    $group_types = ! empty( $_POST['bp-groups-group-type'] ) ? wp_unslash( $_POST['bp-groups-group-type'] ) : array();
    10911100
    10921101    /*
     
    10941103     * fishy with the POST request, so we can fail silently.
    10951104     */
    1096     if ( bp_groups_set_group_type( $group_id, $group_type ) ) {
     1105    if ( bp_groups_set_group_type( $group_id, $group_types ) ) {
    10971106        // @todo Success messages can't be posted because other stuff happens on the page load.
    10981107    }
  • trunk/src/bp-groups/bp-groups-template.php

    r11166 r11176  
    224224     *     @type string $label_element  Element to wrap around the label. Defaults to 'strong'.
    225225     *     @type array  $label_attr     Element attributes for label element. Defaults to array().
     226     *     @type bool   $show_all       Whether to show all registered group types. Defaults to 'false'. If
     227     *                                 'false', only shows group types with the 'show_in_list' parameter set to
     228     *                                  true. See bp_groups_register_group_type() for more info.
    226229     * }
    227230     * @return string
     
    239242            'label'          => __( 'Group Types:', 'buddypress' ),
    240243            'label_element'  => 'strong',
    241             'label_attr'     => array()
     244            'label_attr'     => array(),
     245            'show_all'       => false,
    242246        ), 'group_type_list' );
    243247
     
    246250        if ( $types = bp_groups_get_group_type( $group_id, false ) ) {
    247251            // Make sure we can show the type in the list.
    248             $types = array_intersect( bp_groups_get_group_types( array( 'show_in_list' => true ) ), $types );
    249             if ( empty( $types ) ) {
    250                 return $retval;
     252            if ( false === $show_all ) {
     253                $types = array_intersect( bp_groups_get_group_types( array( 'show_in_list' => true ) ), $types );
     254                if ( empty( $types ) ) {
     255                    return $retval;
     256                }
    251257            }
    252258
  • trunk/src/bp-groups/classes/class-bp-groups-list-table.php

    r11162 r11176  
    716716        }
    717717
    718         // Get the group type.
    719         $type = bp_groups_get_group_type( $item['id'] );
    720 
    721         // Output the
    722         if ( $type_obj = bp_groups_get_group_type_object( $type ) ) {
    723             $url         = add_query_arg( array( 'bp-group-type' => urlencode( $type ) ) );
    724             $retval = '<a href="' . esc_url( $url ) . '">' . esc_html( $type_obj->labels['singular_name'] ) . '</a>';
    725         }
     718        add_filter( 'bp_get_group_type_directory_permalink', array( $this, 'group_type_permalink_use_admin_filter' ), 10, 2 );
     719        $retval = bp_get_group_type_list( $item['id'], array(
     720            'parent_element' => '',
     721            'label_element'  => '',
     722            'label'          => '',
     723            'show_all'       => true
     724        ) );
     725        remove_filter( 'bp_get_group_type_directory_permalink', array( $this, 'group_type_permalink_use_admin_filter' ), 10, 2 );
    726726
    727727        /**
     
    734734         */
    735735        echo apply_filters_ref_array( 'bp_groups_admin_get_group_type_column', array( $retval, $item ) );
     736    }
     737
     738    /**
     739     * Filters the group type list permalink in the Group Type column.
     740     *
     741     * Changes the group type permalink to use the admin URL.
     742     *
     743     * @since 2.7.0
     744     *
     745     * @param  string $retval Current group type permalink.
     746     * @param  object $type   Group type object.
     747     * @return string
     748     */
     749    public function group_type_permalink_use_admin_filter( $retval, $type ) {
     750        return add_query_arg( array( 'bp-group-type' => urlencode( $type->name ) ) );
    736751    }
    737752
Note: See TracChangeset for help on using the changeset viewer.