Skip to:
Content

BuddyPress.org

Changeset 10184


Ignore:
Timestamp:
10/04/2015 01:47:36 PM (9 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

Location:
trunk/src
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-activity/bp-activity-functions.php

    r10077 r10184  
    31053105 * @uses bp_is_activity_directory() to check if the current page is the activity
    31063106 *       directory.
    3107  * @uses bp_is_active() to check if the group component is active.
    31083107 * @uses bp_is_group_activity() to check if on a single group, the current page
    31093108 *       is the group activities.
    3110  * @uses bp_is_group_home() to check if the current page is a single group home
    3111  *       page.
    31123109 *
    31133110 * @return bool True if activity heartbeat is enabled, otherwise false.
     
    31203117    }
    31213118
    3122     if ( bp_is_activity_directory() ) {
     3119    if ( bp_is_activity_directory() || bp_is_group_activity() ) {
    31233120        $retval = true;
    31243121    }
    31253122
    3126     if ( bp_is_active( 'groups') ) {
    3127         // If no custom front, then activities are loaded in group's home
    3128         $has_custom_front = bp_locate_template( array( 'groups/single/front.php' ), false, true );
    3129 
    3130         if ( bp_is_group_activity() || ( ! $has_custom_front && bp_is_group_home() ) ) {
    3131             $retval = true;
    3132         }
    3133     }
    3134 
    31353123    return $retval;
    31363124}
  • trunk/src/bp-core/bp-core-template.php

    r10152 r10184  
    25532553 */
    25542554function bp_is_group_activity() {
    2555     return (bool) ( bp_is_single_item() && bp_is_groups_component() && bp_is_current_action( 'activity' ) );
     2555    $retval = false;
     2556
     2557    if ( bp_is_single_item() && bp_is_groups_component() && bp_is_current_action( 'activity' ) ) {
     2558        $retval = true;
     2559    }
     2560
     2561    if ( bp_is_group_home() && bp_is_active( 'activity' ) && ! bp_is_group_custom_front() ) {
     2562        $retval = true;
     2563    }
     2564
     2565    return $retval;
    25562566}
    25572567
     
    25862596 */
    25872597function bp_is_group_members() {
    2588     return (bool) ( bp_is_single_item() && bp_is_groups_component() && bp_is_current_action( 'members' ) );
     2598    $retval = false;
     2599
     2600    if ( bp_is_single_item() && bp_is_groups_component() && bp_is_current_action( 'members' ) ) {
     2601        $retval = true;
     2602    }
     2603
     2604    if ( bp_is_group_home() && ! bp_is_active( 'activity' ) && ! bp_is_group_custom_front() ) {
     2605        $retval = true;
     2606    }
     2607
     2608    return $retval;
    25892609}
    25902610
     
    26312651function bp_is_group_single() {
    26322652    return (bool) ( bp_is_groups_component() && bp_is_single_item() );
     2653}
     2654
     2655/**
     2656 * Is the current group page a custom front?
     2657 *
     2658 * @since 2.4.0
     2659 *
     2660 * @return bool True if the current group page is a custom front.
     2661 */
     2662function bp_is_group_custom_front() {
     2663    $bp = buddypress();
     2664    return (bool) bp_is_group_home() && ! empty( $bp->groups->current_group->front_template );
    26332665}
    26342666
  • trunk/src/bp-groups/bp-groups-filters.php

    r10148 r10184  
    270270    }
    271271
    272     if ( $load_mentions || ( bp_is_group_activity() || bp_is_group_home() ) ) {
     272    if ( $load_mentions || bp_is_group_activity() ) {
    273273        return true;
    274274    }
  • 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() ) {
  • trunk/src/bp-groups/bp-groups-screens.php

    r10158 r10184  
    739739     */
    740740    bp_core_load_template( apply_filters( 'groups_template_group_request_membership', 'groups/single/home' ) );
     741}
     742
     743/**
     744 * Handle the loading of a single group's activity.
     745 *
     746 * @since 2.4.0
     747 */
     748function groups_screen_group_activity() {
     749
     750    if ( ! bp_is_single_item() ) {
     751        return false;
     752    }
     753
     754    /**
     755     * Fires before the loading of a single group's activity page.
     756     *
     757     * @since 2.4.0
     758     */
     759    do_action( 'groups_screen_group_activity' );
     760
     761    /**
     762     * Filters the template to load for a single group's activity page.
     763     *
     764     * @since 2.4.0
     765     *
     766     * @param string $value Path to a single group's template to load.
     767     */
     768    bp_core_load_template( apply_filters( 'groups_screen_group_activity', 'groups/single/activity' ) );
    741769}
    742770
  • 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 *
  • trunk/src/bp-templates/bp-legacy/buddypress-functions.php

    r10180 r10184  
    929929
    930930    $activity_id = 0;
    931     if ( empty( $_POST['object'] ) && bp_is_active( 'activity' ) ) {
     931    $item_id     = 0;
     932    $object      = '';
     933
     934
     935    // Try to get the item id from posted variables.
     936    if ( ! empty( $_POST['item_id'] ) ) {
     937        $item_id = (int) $_POST['item_id'];
     938    }
     939
     940    // Try to get the object from posted variables.
     941    if ( ! empty( $_POST['object'] ) ) {
     942        $object  = sanitize_key( $_POST['object'] );
     943
     944    // If the object is not set and we're in a group, set the item id and the object
     945    } elseif ( bp_is_group() ) {
     946        $item_id = bp_get_current_group_id();
     947        $object = 'groups';
     948    }
     949
     950    if ( ! $object && bp_is_active( 'activity' ) ) {
    932951        $activity_id = bp_activity_post_update( array( 'content' => $_POST['content'] ) );
    933952
    934     } elseif ( $_POST['object'] == 'groups' ) {
    935         if ( ! empty( $_POST['item_id'] ) && bp_is_active( 'groups' ) )
    936             $activity_id = groups_post_update( array( 'content' => $_POST['content'], 'group_id' => $_POST['item_id'] ) );
     953    } elseif ( 'groups' === $object ) {
     954        if ( $item_id && bp_is_active( 'groups' ) )
     955            $activity_id = groups_post_update( array( 'content' => $_POST['content'], 'group_id' => $item_id ) );
    937956
    938957    } else {
    939958
    940959        /** This filter is documented in bp-activity/bp-activity-actions.php */
    941         $activity_id = apply_filters( 'bp_activity_custom_update', false, $_POST['object'], $_POST['item_id'], $_POST['content'] );
     960        $activity_id = apply_filters( 'bp_activity_custom_update', false, $object, $item_id, $_POST['content'] );
    942961    }
    943962
  • trunk/src/bp-templates/bp-legacy/buddypress/activity/post-form.php

    r10150 r10184  
    6767                <input type="hidden" id="whats-new-post-object" name="whats-new-post-object" value="groups" />
    6868
    69             <?php elseif ( bp_is_group_home() ) : ?>
     69            <?php elseif ( bp_is_group_activity() ) : ?>
    7070
    7171                <input type="hidden" id="whats-new-post-object" name="whats-new-post-object" value="groups" />
  • trunk/src/bp-templates/bp-legacy/buddypress/groups/single/home.php

    r10181 r10184  
    7878                if ( bp_group_is_visible() ) {
    7979
    80                     // Use custom front if one exists
    81                     $custom_front = bp_locate_template( array( 'groups/single/front.php' ), false, true );
    82                     if     ( ! empty( $custom_front   ) ) : load_template( $custom_front, true );
    83 
    84                     // Default to activity
    85                     elseif ( bp_is_active( 'activity' ) ) : bp_get_template_part( 'groups/single/activity' );
    86 
    87                     // Otherwise show members
    88                     elseif ( bp_is_active( 'members'  ) ) : bp_groups_members_template_part();
    89 
    90                     endif;
     80                    // Load appropriate front template
     81                    bp_groups_front_template_part();
    9182
    9283                } else {
Note: See TracChangeset for help on using the changeset viewer.