Skip to:
Content

BuddyPress.org

Changeset 11145


Ignore:
Timestamp:
09/21/2016 10:53:11 PM (10 years ago)
Author:
r-a-y
Message:

Groups: Introduce group type functionality on the Groups Directory page.

If a group type of foo is registered with the has_directory parameter,
you can view a group directory for foo at:
example.com/groups/type/foo/

See #7210.

Location:
trunk/src
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-core/bp-core-template.php

    r11048 r11145  
    26872687 */
    26882688function bp_is_groups_directory() {
    2689         if ( bp_is_groups_component() && ! bp_current_action() && ! bp_current_item() ) {
     2689        if ( bp_is_groups_component() && ! bp_is_group() && ( ! bp_current_action() || ( bp_action_variable() && bp_is_current_action( bp_get_groups_group_type_base() ) ) ) ) {
    26902690                return true;
    26912691        }
  • trunk/src/bp-groups/bp-groups-functions.php

    r11144 r11145  
    24462446
    24472447/**
     2448 * Get the "current" group type, if one is provided, in group directories.
     2449 *
     2450 * @since 2.7.0
     2451 *
     2452 * @return string
     2453 */
     2454function bp_get_current_group_directory_type() {
     2455
     2456        /**
     2457         * Filters the "current" group type, if one is provided, in group directories.
     2458         *
     2459         * @since 2.7.0
     2460         *
     2461         * @param string $value "Current" group type.
     2462         */
     2463        return apply_filters( 'bp_get_current_group_directory_type', buddypress()->groups->current_directory_type );
     2464}
     2465
     2466/**
    24482467 * Delete a group's type when the group is deleted.
    24492468 *
  • trunk/src/bp-groups/bp-groups-screens.php

    r11091 r11145  
    2626function groups_directory_groups_setup() {
    2727        if ( bp_is_groups_directory() ) {
     28                // Set group type if available.
     29                if ( bp_is_current_action( bp_get_groups_group_type_base() ) && bp_action_variable() ) {
     30                        $matched_types = bp_groups_get_group_types( array(
     31                                'has_directory'  => true,
     32                                'directory_slug' => bp_action_variable(),
     33                        ) );
     34
     35                        // Redirect back to group directory if no match.
     36                        if ( empty( $matched_types ) ) {
     37                                bp_core_redirect( bp_get_groups_directory_permalink() );
     38                        }
     39
     40                        // Set our global variable.
     41                        buddypress()->groups->current_directory_type = reset( $matched_types );
     42                }
     43
    2844                bp_update_is_directory( true, 'groups' );
    2945
  • trunk/src/bp-groups/bp-groups-template.php

    r11129 r11145  
    7070                 */
    7171                return apply_filters( 'bp_get_groups_root_slug', buddypress()->groups->root_slug );
     72        }
     73
     74/**
     75 * Output the group type base slug.
     76 *
     77 * @since 2.7.0
     78 */
     79function bp_groups_group_type_base() {
     80        echo esc_url( bp_get_groups_group_type_base() );
     81}
     82        /**
     83         * Get the group type base slug.
     84         *
     85         * The base slug is the string used as the base prefix when generating group
     86         * type directory URLs. For example, in example.com/groups/type/foo/, 'foo' is
     87         * the group type and 'type' is the base slug.
     88         *
     89         * @since 2.7.0
     90         *
     91         * @return string
     92         */
     93        function bp_get_groups_group_type_base() {
     94                /**
     95                 * Filters the group type URL base.
     96                 *
     97                 * @since 2.7.0
     98                 *
     99                 * @param string $base
     100                 */
     101                return apply_filters( 'bp_groups_group_type_base', _x( 'type', 'group type URL base', 'buddypress' ) );
    72102        }
    73103
    … …  
    174204        }
    175205
     206        $group_type = bp_get_current_group_directory_type();
     207        if ( ! $group_type && ! empty( $_GET['group_type'] ) ) {
     208                if ( is_array( $_GET['group_type'] ) ) {
     209                        $group_type = $_GET['group_type'];
     210                } else {
     211                        // Can be a comma-separated list.
     212                        $group_type = explode( ',', $_GET['group_type'] );
     213                }
     214        }
     215
    176216        // Default search string (too soon to escape here).
    177217        $search_query_arg = bp_core_get_component_search_query_arg( 'groups' );
    … …  
    197237                'slug'               => $slug,
    198238                'search_terms'       => $search_terms,
    199                 'group_type'         => '',
     239                'group_type'         => $group_type,
    200240                'group_type__in'     => '',
    201241                'group_type__not_in' => '',
    … …  
    50805120
    50815121/**
     5122 * Echo the current group type message.
     5123 *
     5124 * @since 2.7.0
     5125 */
     5126function bp_current_group_directory_type_message() {
     5127        echo bp_get_current_group_directory_type_message();
     5128}
     5129        /**
     5130         * Generate the current group type message.
     5131         *
     5132         * @since 2.7.0
     5133         *
     5134         * @return string
     5135         */
     5136        function bp_get_current_group_directory_type_message() {
     5137                $type_object = bp_groups_get_group_type_object( bp_get_current_group_directory_type() );
     5138
     5139                $message = sprintf( __( 'Viewing groups of the type: %s', 'buddypress' ), '<strong>' . $type_object->labels['singular_name'] . '</strong>' );
     5140
     5141                /**
     5142                 * Filters the current group type message.
     5143                 *
     5144                 * @since 2.7.0
     5145                 *
     5146                 * @param string $message Message to filter.
     5147                 */
     5148                return apply_filters( 'bp_get_current_group_type_message', $message );
     5149        }
     5150
     5151/**
    50825152 * Is the current page a specific group admin screen?
    50835153 *
  • trunk/src/bp-groups/classes/class-bp-groups-component.php

    r11091 r11145  
    8484         */
    8585        public $types = array();
     86
     87        /**
     88         * Current directory group type.
     89         *
     90         * @see groups_directory_groups_setup()
     91         *
     92         * @since 2.7.0
     93         * @var string
     94         */
     95        public $current_directory_type = '';
    8696
    8797        /**
  • trunk/src/bp-groups/classes/class-bp-groups-theme-compat.php

    r10520 r11145  
    4141
    4242                // Group Directory.
    43                 if ( ! bp_current_action() && ! bp_current_item() ) {
     43                if ( bp_is_groups_directory() ) {
    4444                        bp_update_is_directory( true, 'groups' );
    4545
  • trunk/src/bp-templates/bp-legacy/buddypress/groups/groups-loop.php

    r11008 r11145  
    1919 */
    2020do_action( 'bp_before_groups_loop' ); ?>
     21
     22<?php if ( bp_get_current_group_directory_type() ) : ?>
     23        <p class="current-group-type"><?php bp_current_group_directory_type_message() ?></p>
     24<?php endif; ?>
    2125
    2226<?php if ( bp_has_groups( bp_ajax_querystring( 'groups' ) ) ) : ?>
Note: See TracChangeset for help on using the changeset viewer.