Skip to:
Content

BuddyPress.org

Ticket #6388: 6388.04.patch

File 6388.04.patch, 12.6 KB (added by imath, 10 years ago)
  • src/bp-core/bp-core-template.php

    diff --git src/bp-core/bp-core-template.php src/bp-core/bp-core-template.php
    index a89a0e4..8bf0cfd 100644
    function bp_is_group() { 
    24772477 * @return bool True if the current page is a single group's home page.
    24782478 */
    24792479function bp_is_group_home() {
     2480        $retval = false;
     2481
    24802482        if ( bp_is_single_item() && bp_is_groups_component() && ( ! bp_current_action() || bp_is_current_action( 'home' ) ) ) {
    2481                 return true;
     2483                $retval = true;
    24822484        }
    24832485
    2484         return false;
     2486        // Get BuddyPress instance
     2487        $bp = buddypress();
     2488
     2489        /**
     2490         * Since 2.4.0 The group home is not necessarly the activity page, this part
     2491         * is making sure outdated templates will still be able to post activities
     2492         * if the group has a custom front template.
     2493         */
     2494        if ( isset( $bp->groups->is_activity ) && true === $bp->groups->is_activity ) {
     2495                $retval = true;
     2496
     2497                // Reset the backcompat global
     2498                unset( $bp->groups->is_activity );
     2499        }
     2500
     2501        return $retval;
    24852502}
    24862503
    24872504/**
    function bp_is_group_forum() { 
    25342551 * @return True if the current page is a group's activity page.
    25352552 */
    25362553function bp_is_group_activity() {
    2537         return (bool) ( bp_is_single_item() && bp_is_groups_component() && bp_is_current_action( 'activity' ) );
     2554        $retval = false;
     2555
     2556        if ( bp_is_single_item() && bp_is_groups_component() && bp_is_current_action( 'activity' ) ) {
     2557                $retval = true;
     2558        }
     2559
     2560        if ( bp_is_group_home() && bp_is_active( 'activity' ) && ! bp_is_group_custom_front() ) {
     2561                $retval = true;
     2562        }
     2563
     2564        return $retval;
    25382565}
    25392566
    25402567/**
    function bp_is_group_forum_topic_edit() { 
    25672594 * @return bool True if the current page is part of a group's Members page.
    25682595 */
    25692596function bp_is_group_members() {
    2570         return (bool) ( bp_is_single_item() && bp_is_groups_component() && bp_is_current_action( 'members' ) );
     2597        $retval = false;
     2598
     2599        if ( bp_is_single_item() && bp_is_groups_component() && bp_is_current_action( 'members' ) ) {
     2600                $retval = true;
     2601        }
     2602
     2603        if ( bp_is_group_home() && ! bp_is_active( 'activity' ) && ! bp_is_group_custom_front() ) {
     2604                $retval = true;
     2605        }
     2606
     2607        return $retval;
    25712608}
    25722609
    25732610/**
    function bp_is_group_single() { 
    26152652}
    26162653
    26172654/**
     2655 * Is the current group page a custom front?
     2656 *
     2657 * @since 2.4.0
     2658 *
     2659 * @return bool True if the current group page is a custom front.
     2660 */
     2661function bp_is_group_custom_front() {
     2662        $bp = buddypress();
     2663        return (bool) bp_is_group_home() && ! empty( $bp->groups->current_group->front_template );
     2664}
     2665
     2666/**
    26182667 * Is the current page the Create a Blog page?
    26192668 *
    26202669 * Eg http://example.com/sites/create/.
  • src/bp-groups/bp-groups-activity.php

    diff --git src/bp-groups/bp-groups-activity.php src/bp-groups/bp-groups-activity.php
    index 5235f76..d48d801 100644
    function bp_groups_leave_group_delete_recent_activity( $group_id, $user_id ) { 
    577577add_action( 'groups_leave_group',   'bp_groups_leave_group_delete_recent_activity', 10, 2 );
    578578add_action( 'groups_remove_member', 'bp_groups_leave_group_delete_recent_activity', 10, 2 );
    579579add_action( 'groups_ban_member',    'bp_groups_leave_group_delete_recent_activity', 10, 2 );
     580
     581/**
     582 * Back compatibility for outdated templates using a custom front.php template
     583 *
     584 * @since  2.4.0
     585 *
     586 * @param  string $bp_version The current BuddyPress version
     587 */
     588function bp_groups_backcompat_is_group_activity( $bp_version = '' ) {
     589        // The template is up to date :)
     590        if ( $bp_version === '2.4.0' ) {
     591                return;
     592        }
     593
     594        /**
     595         * Outdated templates are not using the bp_is_group_activity()
     596         * conditional tag, but are still using bp_is_group_home().
     597         *
     598         * If a custom front template is found, the activity page won't be at
     599         * the home level. So we need to use a global to inform bp_is_group_home()
     600         * it should be true to let group members post activities within the
     601         * group's activity page.
     602         */
     603        if ( bp_is_group_activity() && ! bp_is_group_home() ) {
     604                buddypress()->groups->is_activity = true;
     605
     606                // Inform theme developers
     607                _doing_it_wrong( 'activity/post-form.php', __( "The activity post form template is outdated, please make sure to use bp_is_group_activity() instead of bp_is_group_home().", 'buddypress' ), 'BP 2.4.0' );
     608        }
     609}
     610add_action( 'bp_before_activity_post_form', 'bp_groups_backcompat_is_group_activity', 10, 1 );
  • src/bp-groups/bp-groups-loader.php

    diff --git src/bp-groups/bp-groups-loader.php src/bp-groups/bp-groups-loader.php
    index 0949b8a..f4c1d72 100644
    class BP_Groups_Component extends BP_Component { 
    251251                                $this->current_group->user_has_access = true;
    252252                        }
    253253
     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 );
     256
    254257                // Set current_group to 0 to prevent debug errors
    255258                } else {
    256259                        $this->current_group = 0;
    class BP_Groups_Component extends BP_Component { 
    364367
    365368                $bp = buddypress();
    366369
     370                // If the activity component is not active and the current group has no custom front, members are displayed in the home nav
     371                if ( 'members' === $this->default_extension && ! bp_is_active( 'activity' ) && ! $this->current_group->front_template ) {
     372                        $this->default_extension = 'home';
     373                }
     374
    367375                if ( ! bp_current_action() ) {
    368376                        $bp->current_action = $this->default_extension;
    369377                }
    class BP_Groups_Component extends BP_Component { 
    520528                                );
    521529                        }
    522530
    523                         $sub_nav[] = array(
    524                                 'name'            => sprintf( _x( 'Members <span>%s</span>', 'My Group screen nav', 'buddypress' ), number_format( $this->current_group->total_member_count ) ),
    525                                 'slug'            => 'members',
    526                                 'parent_url'      => $group_link,
    527                                 'parent_slug'     => $this->current_group->slug,
    528                                 'screen_function' => 'groups_screen_group_members',
    529                                 'position'        => 60,
    530                                 'user_has_access' => $this->current_group->user_has_access,
    531                                 'item_css_id'     => 'members',
    532                                 'no_access_url'   => $group_link,
    533                         );
     531                        if ( $this->current_group->front_template || bp_is_active( 'activity' ) ) {
     532                                /**
     533                                 * If the theme is using a custom front, create activity subnav.
     534                                 */
     535                                if ( $this->current_group->front_template && bp_is_active( 'activity' ) ) {
     536                                        $sub_nav[] = array(
     537                                                'name'            => _x( 'Activity', 'My Group screen nav', 'buddypress' ),
     538                                                'slug'            => 'activity',
     539                                                'parent_url'      => $group_link,
     540                                                'parent_slug'     => $this->current_group->slug,
     541                                                'screen_function' => 'groups_screen_group_activity',
     542                                                'position'        => 11,
     543                                                'user_has_access' => $this->current_group->user_has_access,
     544                                                'item_css_id'     => 'activity',
     545                                                'no_access_url'   => $group_link,
     546                                        );
     547                                }
     548
     549                                /**
     550                                 * Only add the members subnav if it's not the home's nav
     551                                 */
     552                                $sub_nav[] = array(
     553                                        'name'            => sprintf( _x( 'Members <span>%s</span>', 'My Group screen nav', 'buddypress' ), number_format( $this->current_group->total_member_count ) ),
     554                                        'slug'            => 'members',
     555                                        'parent_url'      => $group_link,
     556                                        'parent_slug'     => $this->current_group->slug,
     557                                        'screen_function' => 'groups_screen_group_members',
     558                                        'position'        => 60,
     559                                        'user_has_access' => $this->current_group->user_has_access,
     560                                        'item_css_id'     => 'members',
     561                                        'no_access_url'   => $group_link,
     562                                );
     563                        }
    534564
    535565                        if ( bp_is_active( 'friends' ) && bp_groups_user_can_send_invites() ) {
    536566                                $sub_nav[] = array(
  • src/bp-groups/bp-groups-screens.php

    diff --git src/bp-groups/bp-groups-screens.php src/bp-groups/bp-groups-screens.php
    index 325c4fb..452a0df 100644
    function groups_screen_group_request_membership() { 
    741741}
    742742
    743743/**
     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' ) );
     769}
     770
     771/**
    744772 * Handle the display of a single group activity item.
    745773 */
    746774function groups_screen_group_activity_permalink() {
  • src/bp-groups/bp-groups-template.php

    diff --git src/bp-groups/bp-groups-template.php src/bp-groups/bp-groups-template.php
    index 9104ea1..e310821 100644
    function bp_group_member_admin_pagination() { 
    43294329        }
    43304330
    43314331/**
     4332 * Output the contents of the current group's home page.
     4333 *
     4334 * You should only use this when on a single group page.
     4335 *
     4336 * @since 2.4.0
     4337 */
     4338function bp_groups_front_template_part() {
     4339        $located = bp_groups_get_front_template();
     4340
     4341        if ( false !== $located ) {
     4342                $slug = str_replace( '.php', '', $located );
     4343
     4344                /**
     4345                 * Let plugins adding an action to bp_get_template_part get it from here
     4346                 *
     4347                 * @param string $slug Template part slug requested.
     4348                 * @param string $name Template part name requested.
     4349                 */
     4350                do_action( 'get_template_part_' . $slug, $slug, false );
     4351
     4352                load_template( $located, true );
     4353
     4354        } else if ( bp_is_active( 'activity' ) ) {
     4355                bp_get_template_part( 'groups/single/activity' );
     4356
     4357        } else if ( bp_is_active( 'members'  ) ) {
     4358                bp_groups_members_template_part();
     4359        }
     4360
     4361        return $located;
     4362}
     4363
     4364/**
     4365 * Locate a custom group front template if it exists.
     4366 *
     4367 * @since 2.4.0
     4368 *
     4369 * @param  BP_Groups_Group|null $group Optional. Falls back to current group if not passed.
     4370 * @return string|bool                 Path to front template on success; boolean false on failure.
     4371 */
     4372function bp_groups_get_front_template( $group = null ) {
     4373        if ( ! is_a( $group, 'BP_Groups_Group' ) ) {
     4374                $group = groups_get_current_group();
     4375        }
     4376
     4377        if ( ! isset( $group->id ) ) {
     4378                return false;
     4379        }
     4380
     4381        if ( isset( $group->front_template ) ) {
     4382                return $group->front_template;
     4383        }
     4384
     4385        $template_names = apply_filters( 'bp_groups_get_front_template', array(
     4386                'groups/single/front-id-'     . sanitize_file_name( $group->id )     . '.php',
     4387                'groups/single/front-slug-'   . sanitize_file_name( $group->slug )   . '.php',
     4388                'groups/single/front-status-' . sanitize_file_name( $group->status ) . '.php',
     4389                'groups/single/front.php'
     4390        ) );
     4391
     4392        return bp_locate_template( $template_names, false, true );
     4393}
     4394
     4395/**
    43324396 * Output the Group members template
    43334397 *
    43344398 * @since 2.0.0
  • src/bp-templates/bp-legacy/buddypress/activity/post-form.php

    diff --git src/bp-templates/bp-legacy/buddypress/activity/post-form.php src/bp-templates/bp-legacy/buddypress/activity/post-form.php
    index fb4f175..c565331 100644
     
    1616         * Fires before the activity post form.
    1717         *
    1818         * @since 1.2.0
     19         * @since 2.4.0 Include a new parameter to hold the BuddyPress version
     20         *              when the template has evolved.
     21         *
     22         * Please, make sure to keep the '2.4.0' argument of this hook, in your
     23         * custom template
    1924         */
    20         do_action( 'bp_before_activity_post_form' ); ?>
     25        do_action( 'bp_before_activity_post_form', '2.4.0' ); ?>
    2126
    2227        <div id="whats-new-avatar">
    2328                <a href="<?php echo bp_loggedin_user_domain(); ?>">
     
    6671                                </div>
    6772                                <input type="hidden" id="whats-new-post-object" name="whats-new-post-object" value="groups" />
    6873
    69                         <?php elseif ( bp_is_group_home() ) : ?>
     74                        <?php elseif ( bp_is_group_activity() ) : ?>
    7075
    7176                                <input type="hidden" id="whats-new-post-object" name="whats-new-post-object" value="groups" />
    7277                                <input type="hidden" id="whats-new-post-in" name="whats-new-post-in" value="<?php bp_group_id(); ?>" />
  • src/bp-templates/bp-legacy/buddypress/groups/single/home.php

    diff --git src/bp-templates/bp-legacy/buddypress/groups/single/home.php src/bp-templates/bp-legacy/buddypress/groups/single/home.php
    index c8e62f4..a64ac89 100644
     
    5959
    6060                                if ( bp_group_is_visible() ) {
    6161
    62                                         // Use custom front if one exists
    63                                         $custom_front = bp_locate_template( array( 'groups/single/front.php' ), false, true );
    64                                         if     ( ! empty( $custom_front   ) ) : load_template( $custom_front, true );
    65 
    66                                         // Default to activity
    67                                         elseif ( bp_is_active( 'activity' ) ) : bp_get_template_part( 'groups/single/activity' );
    68 
    69                                         // Otherwise show members
    70                                         elseif ( bp_is_active( 'members'  ) ) : bp_groups_members_template_part();
    71 
    72                                         endif;
     62                                        // Load appropriate front template
     63                                        bp_groups_front_template_part();
    7364
    7465                                } else {
    7566