Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
10/04/2015 01:47:36 PM (4 years ago)
Author:
imath
Message:

Improve template loading for Groups single items home pages.

  • Make sure an activity sub navigation will be generated if the displayed group has a custom front page.
  • Make sure no members sub navigation is generated if the activity component is not active and the Group has no custom front. As, in this case the home page of the group is already displaying the members template.
  • Make sure some Groups single item conditional tags are behaving the right way:
    • bp_is_group_home() is true when on the home page of the group (eg: site.url/groups/single-group/).
    • bp_is_group_activity() is true when the activity page of the group is displayed. It can be the home page of the group or its activity page (eg: site.url/groups/single-group/activity).
    • bp_is_group_members() is true when the members page of the group is displayed. It can be the home page of the group or its members page (eg: site.url/groups/single-group/members).
  • Introduce a new conditional tag: bp_is_group_custom_front() to check if the home page of the group is using a custom front template.
  • Introduce a new template tag bp_groups_front_template_part() used to choose the appropriate template to load for the home page of the group (activity, members, or the custom front).
  • Introduce a template hierarchy for the buddypress/groups/single/front.php template so that it is possible to have different front pages according to the ID, slug or status of the Group.
  • And finally make sure the introduced improvements are back compatible with themes who forgot to update their buddypress/groups/single/home.php and buddypress/activity/post-form.php templates.

Props r-a-y, boonebgorges, DJPaul, and imath :)

Fixes #6388

File:
1 edited

Legend:

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

    r10158 r10184  
    251251                $this->current_group->user_has_access = true;
    252252            }
     253
     254            // Check once if the current group has a custom front template
     255            $this->current_group->front_template = bp_groups_get_front_template( $this->current_group );
    253256
    254257        // Set current_group to 0 to prevent debug errors
     
    372375        $bp = buddypress();
    373376
     377        // If the activity component is not active and the current group has no custom front, members are displayed in the home nav
     378        if ( 'members' === $this->default_extension && ! bp_is_active( 'activity' ) && ! $this->current_group->front_template ) {
     379            $this->default_extension = 'home';
     380        }
     381
    374382        if ( ! bp_current_action() ) {
    375383            $bp->current_action = $this->default_extension;
     
    528536            }
    529537
    530             $sub_nav[] = array(
    531                 'name'            => sprintf( _x( 'Members <span>%s</span>', 'My Group screen nav', 'buddypress' ), number_format( $this->current_group->total_member_count ) ),
    532                 'slug'            => 'members',
    533                 'parent_url'      => $group_link,
    534                 'parent_slug'     => $this->current_group->slug,
    535                 'screen_function' => 'groups_screen_group_members',
    536                 'position'        => 60,
    537                 'user_has_access' => $this->current_group->user_has_access,
    538                 'item_css_id'     => 'members',
    539                 'no_access_url'   => $group_link,
    540             );
     538            if ( $this->current_group->front_template || bp_is_active( 'activity' ) ) {
     539                /**
     540                 * If the theme is using a custom front, create activity subnav.
     541                 */
     542                if ( $this->current_group->front_template && bp_is_active( 'activity' ) ) {
     543                    $sub_nav[] = array(
     544                        'name'            => _x( 'Activity', 'My Group screen nav', 'buddypress' ),
     545                        'slug'            => 'activity',
     546                        'parent_url'      => $group_link,
     547                        'parent_slug'     => $this->current_group->slug,
     548                        'screen_function' => 'groups_screen_group_activity',
     549                        'position'        => 11,
     550                        'user_has_access' => $this->current_group->user_has_access,
     551                        'item_css_id'     => 'activity',
     552                        'no_access_url'   => $group_link,
     553                    );
     554                }
     555
     556                /**
     557                 * Only add the members subnav if it's not the home's nav
     558                 */
     559                $sub_nav[] = array(
     560                    'name'            => sprintf( _x( 'Members <span>%s</span>', 'My Group screen nav', 'buddypress' ), number_format( $this->current_group->total_member_count ) ),
     561                    'slug'            => 'members',
     562                    'parent_url'      => $group_link,
     563                    'parent_slug'     => $this->current_group->slug,
     564                    'screen_function' => 'groups_screen_group_members',
     565                    'position'        => 60,
     566                    'user_has_access' => $this->current_group->user_has_access,
     567                    'item_css_id'     => 'members',
     568                    'no_access_url'   => $group_link,
     569                );
     570            }
    541571
    542572            if ( bp_is_active( 'friends' ) && bp_groups_user_can_send_invites() ) {
Note: See TracChangeset for help on using the changeset viewer.