Skip to:
Content

BuddyPress.org

Ticket #8401: 8401.patch

File 8401.patch, 6.9 KB (added by imath, 4 years ago)
  • src/bp-groups/bp-groups-template.php

    diff --git src/bp-groups/bp-groups-template.php src/bp-groups/bp-groups-template.php
    index d0be0cc70..2b3fe0475 100644
    function bp_group_type_directory_link( $group_type = '' ) { 
    190190                        return '';
    191191                }
    192192
    193                 return sprintf( '<a href="%s">%s</a>', esc_url( bp_get_group_type_directory_permalink( $group_type ) ), bp_groups_get_group_type_object( $group_type )->labels['name'] );
     193                $group_type_object = bp_groups_get_group_type_object( $group_type );
     194
     195                if ( ! isset( $group_type_object->labels['name'] ) ) {
     196                        return '';
     197                }
     198
     199                $group_type_text = $group_type_object->labels['name'];
     200                if ( isset( $group_type_object->labels['singular_name'] ) && $group_type_object->labels['singular_name'] ) {
     201                        $group_type_text = $group_type_object->labels['singular_name'];
     202                }
     203
     204                if ( empty( $group_type_object->has_directory ) ) {
     205                        return esc_html( $group_type_text );
     206                }
     207
     208                return sprintf(
     209                        '<a href="%s">%s</a>',
     210                        esc_url( bp_get_group_type_directory_permalink( $group_type ) ),
     211                        esc_html( $group_type_text )
     212                );
    194213        }
    195214
    196215/**
    function bp_group_type_list( $group_id = 0, $r = array() ) { 
    206225         * Return a comma-delimited list of group types.
    207226         *
    208227         * @since 2.7.0
     228         * @since 7.0.0 The `$r['label']` arguments now also accept an array containing the
     229         *              plural & singular labels to use according to the Group's number of
     230         *              group types it assigned to.
    209231         *
    210232         * @param int $group_id Group ID. Defaults to current group ID if on a group page.
    211233         * @param array|string $r {
    212234         *     Array of parameters. All items are optional.
    213          *     @type string $parent_element Element to wrap around the list. Defaults to 'p'.
    214          *     @type array  $parent_attr    Element attributes for parent element. Defaults to
    215          *                                  array( 'class' => 'bp-group-type-list' ).
    216          *     @type string $label          Label to add before the list. Defaults to 'Group Types:'.
    217          *     @type string $label_element  Element to wrap around the label. Defaults to 'strong'.
    218          *     @type array  $label_attr     Element attributes for label element. Defaults to array().
    219          *     @type bool   $show_all       Whether to show all registered group types. Defaults to 'false'. If
    220          *                                 'false', only shows group types with the 'show_in_list' parameter set to
    221          *                                  true. See bp_groups_register_group_type() for more info.
     235         *     @type string       $parent_element Element to wrap around the list. Defaults to 'p'.
     236         *     @type array        $parent_attr    Element attributes for parent element. Defaults to
     237         *                                        array( 'class' => 'bp-group-type-list' ).
     238         *     @type string|array $label          Plural and singular labels to add before the list. Defaults to
     239         *                                        array( 'plural' => 'Group Types:', 'singular' => 'Group Type:' ).
     240         *     @type string       $label_element  Element to wrap around the label. Defaults to 'strong'.
     241         *     @type array        $label_attr     Element attributes for label element. Defaults to array().
     242         *     @type bool         $show_all       Whether to show all registered group types. Defaults to 'false'. If
     243         *                                       'false', only shows group types with the 'show_in_list' parameter set to
     244         *                                        true. See bp_groups_register_group_type() for more info.
    222245         * }
    223246         * @return string
    224247         */
    function bp_group_type_list( $group_id = 0, $r = array() ) { 
    234257                                'parent_attr'       => array(
    235258                                        'class' => 'bp-group-type-list',
    236259                                ),
    237                                 'label'             => __( 'Group Types:', 'buddypress' ),
     260                                'label'             => array(),
    238261                                'label_element'     => 'strong',
    239262                                'label_attr'        => array(),
    240263                                'show_all'          => false,
    function bp_group_type_list( $group_id = 0, $r = array() ) { 
    244267                        'group_type_list'
    245268                );
    246269
     270                // Should the label be output?
     271                $has_label = ! empty( $r['label'] );
     272
     273                // Ensure Backcompatibilty in case devalopers are still using a string.
     274                if ( ! is_array( $r['label'] ) ) {
     275                        $r['label'] = array(
     276                                'plural' => __( 'Group Types:', 'buddypress' ),
     277                        );
     278                }
     279
     280                $labels = wp_parse_args(
     281                        $r['label'],
     282                        array(
     283                                'plural'   => __( 'Group Types:', 'buddypress' ),
     284                                'singular' => __( 'Group Type:', 'buddypress' ),
     285                        )
     286                );
     287
    247288                $retval = '';
    248289
    249290                if ( $types = bp_groups_get_group_type( $group_id, false ) ) {
    function bp_group_type_list( $group_id = 0, $r = array() ) { 
    256297                        }
    257298
    258299                        $before = $after = $label = '';
     300                        $count  = count( $types );
     301
     302                        if ( 1 === $count ) {
     303                                $label_text = $labels['singular'];
     304                        } else {
     305                                $label_text = $labels['plural'];
     306                        }
    259307
    260308                        // Render parent element.
    261309                        if ( ! empty( $r['parent_element'] ) ) {
    262310                                $parent_elem = new BP_Core_HTML_Element( array(
    263311                                        'element' => $r['parent_element'],
    264                                         'attr'    => $r['parent_attr']
     312                                        'attr'    => $r['parent_attr'],
    265313                                ) );
    266314
    267315                                // Set before and after.
    function bp_group_type_list( $group_id = 0, $r = array() ) { 
    274322                                $label = new BP_Core_HTML_Element( array(
    275323                                        'element'    => $r['label_element'],
    276324                                        'attr'       => $r['label_attr'],
    277                                         'inner_html' => esc_html( $r['label'] )
     325                                        'inner_html' => esc_html( $label_text ),
    278326                                ) );
    279327                                $label = $label->contents() . ' ';
    280328
    281329                        // No element, just the label.
    282                         } else {
    283                                 $label = esc_html( $r['label'] );
     330                        } elseif ( $has_label ) {
     331                                $label = esc_html( $label_text );
    284332                        }
    285333
    286334                        // The list of types.
  • src/bp-templates/bp-nouveau/buddypress/groups/single/cover-image-header.php

    diff --git src/bp-templates/bp-nouveau/buddypress/groups/single/cover-image-header.php src/bp-templates/bp-nouveau/buddypress/groups/single/cover-image-header.php
    index 07439f2f8..df18e2119 100644
     
    4646                                bp_group_type_list(
    4747                                        bp_get_group_id(),
    4848                                        array(
    49                                                 'label'        => __( 'Group Types', 'buddypress' ),
     49                                                'label'        => array(
     50                                                        'plural'   => __( 'Group Types', 'buddypress' ),
     51                                                        'singular' => __( 'Group Type', 'buddypress' ),
     52                                                ),
    5053                                                'list_element' => 'span',
    5154                                        )
    5255                                );
  • src/bp-templates/bp-nouveau/buddypress/groups/single/group-header.php

    diff --git src/bp-templates/bp-nouveau/buddypress/groups/single/group-header.php src/bp-templates/bp-nouveau/buddypress/groups/single/group-header.php
    index 92c18c48d..ffa9f447f 100644
     
    4343        bp_group_type_list(
    4444                bp_get_group_id(),
    4545                array(
    46                         'label'        => __( 'Group Types', 'buddypress' ),
     46                        'label'        => array(
     47                                'plural'   => __( 'Group Types', 'buddypress' ),
     48                                'singular' => __( 'Group Type', 'buddypress' ),
     49                        ),
    4750                        'list_element' => 'span',
    4851                )
    4952        );