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-template.php

    r10160 r10184  
    43444344
    43454345/**
     4346 * Output the contents of the current group's home page.
     4347 *
     4348 * You should only use this when on a single group page.
     4349 *
     4350 * @since 2.4.0
     4351 */
     4352function bp_groups_front_template_part() {
     4353    $located = bp_groups_get_front_template();
     4354
     4355    if ( false !== $located ) {
     4356        $slug = str_replace( '.php', '', $located );
     4357
     4358        /**
     4359         * Let plugins adding an action to bp_get_template_part get it from here
     4360         *
     4361         * @param string $slug Template part slug requested.
     4362         * @param string $name Template part name requested.
     4363         */
     4364        do_action( 'get_template_part_' . $slug, $slug, false );
     4365
     4366        load_template( $located, true );
     4367
     4368    } else if ( bp_is_active( 'activity' ) ) {
     4369        bp_get_template_part( 'groups/single/activity' );
     4370
     4371    } else if ( bp_is_active( 'members'  ) ) {
     4372        bp_groups_members_template_part();
     4373    }
     4374
     4375    return $located;
     4376}
     4377
     4378/**
     4379 * Locate a custom group front template if it exists.
     4380 *
     4381 * @since 2.4.0
     4382 *
     4383 * @param  BP_Groups_Group|null $group Optional. Falls back to current group if not passed.
     4384 * @return string|bool                 Path to front template on success; boolean false on failure.
     4385 */
     4386function bp_groups_get_front_template( $group = null ) {
     4387    if ( ! is_a( $group, 'BP_Groups_Group' ) ) {
     4388        $group = groups_get_current_group();
     4389    }
     4390
     4391    if ( ! isset( $group->id ) ) {
     4392        return false;
     4393    }
     4394
     4395    if ( isset( $group->front_template ) ) {
     4396        return $group->front_template;
     4397    }
     4398
     4399    $template_names = apply_filters( 'bp_groups_get_front_template', array(
     4400        'groups/single/front-id-'     . sanitize_file_name( $group->id )     . '.php',
     4401        'groups/single/front-slug-'   . sanitize_file_name( $group->slug )   . '.php',
     4402        'groups/single/front-status-' . sanitize_file_name( $group->status ) . '.php',
     4403        'groups/single/front.php'
     4404    ) );
     4405
     4406    return bp_locate_template( $template_names, false, true );
     4407}
     4408
     4409/**
    43464410 * Output the Group members template
    43474411 *
Note: See TracChangeset for help on using the changeset viewer.