Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
07/22/2022 11:44:14 AM (4 years ago)
Author:
imath
Message:

Introduce a function to only get the "Join/Leave Group" button args

bp_groups_get_group_join_button_args() eases the process of getting these arguments and removes the need for BP Nouveau's workaround.
Deprecate the bp_nouveau_groups_catch_button_args() as no more needed.

Props hnla

See #7126
See #8722

File:
1 edited

Legend:

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

    r13296 r13302  
    35643564        echo bp_get_group_join_button( $group );
    35653565}
    3566         /**
    3567          * Return button to join a group.
    3568          *
    3569          * @since 1.0.0
    3570          *
    3571          * @param object|bool $group Single group object.
    3572          * @return false|string
    3573          */
    3574         function bp_get_group_join_button( $group = false ) {
    3575                 global $groups_template;
    3576 
    3577                 // Set group to current loop group if none passed.
    3578                 if ( empty( $group ) ) {
    3579                         $group =& $groups_template->group;
     3566
     3567        /**
     3568         * Get the arguments for the Join button group
     3569         *
     3570         * @since 11.0.0
     3571         *
     3572         * @param BP_Groups_Group $group The group object.
     3573         * @return Array The arguments for the Join button group
     3574         */
     3575        function bp_groups_get_group_join_button_args( $group = null ) {
     3576                $button_args = array();
     3577
     3578                if ( empty( $group->id ) ) {
     3579                        return $button_args;
    35803580                }
    35813581
    35823582                // Don't show button if not logged in or previously banned.
    35833583                if ( ! is_user_logged_in() || bp_group_is_user_banned( $group ) ) {
    3584                         return false;
     3584                        return $button_args;
    35853585                }
    35863586
    35873587                // Group creation was not completed or status is unknown.
    35883588                if ( empty( $group->status ) ) {
    3589                         return false;
     3589                        return $button_args;
    35903590                }
    35913591
    … …  
    35963596                        $group_admins = groups_get_group_admins( $group->id );
    35973597                        if ( ( 1 == count( $group_admins ) ) && ( bp_loggedin_user_id() === (int) $group_admins[0]->user_id ) ) {
    3598                                 return false;
     3598                                return $button_args;
    35993599                        }
    36003600
    36013601                        // Setup button attributes.
    3602                         $button = array(
     3602                        $button_args = array(
    36033603                                'id'                => 'leave_group',
    36043604                                'component'         => 'groups',
    … …  
    36093609                                'link_href'         => wp_nonce_url( trailingslashit( bp_get_group_permalink( $group ) . 'leave-group' ), 'groups_leave_group' ),
    36103610                                'link_text'         => __( 'Leave Group', 'buddypress' ),
     3611                                'link_title'        => __( 'Leave Group', 'buddypress' ),
    36113612                                'link_class'        => 'group-button leave-group',
    36123613                        );
    … …  
    36183619                        switch ( $group->status ) {
    36193620                                case 'hidden' :
    3620                                         return false;
     3621                                        return $button_args;
    36213622
    36223623                                case 'public':
    3623                                         $button = array(
     3624                                        $button_args = array(
    36243625                                                'id'                => 'join_group',
    36253626                                                'component'         => 'groups',
    … …  
    36303631                                                'link_href'         => wp_nonce_url( trailingslashit( bp_get_group_permalink( $group ) . 'join' ), 'groups_join_group' ),
    36313632                                                'link_text'         => __( 'Join Group', 'buddypress' ),
     3633                                                'link_title'        => __( 'Join Group', 'buddypress' ),
    36323634                                                'link_class'        => 'group-button join-group',
    36333635                                        );
    … …  
    36393641                                        // show an "Accept Invitation" button.
    36403642                                        if ( $group->is_invited ) {
    3641                                                 $button = array(
     3643                                                $button_args = array(
    36423644                                                        'id'                => 'accept_invite',
    36433645                                                        'component'         => 'groups',
    … …  
    36483650                                                        'link_href'         => add_query_arg( 'redirect_to', bp_get_group_permalink( $group ), bp_get_group_accept_invite_link( $group ) ),
    36493651                                                        'link_text'         => __( 'Accept Invitation', 'buddypress' ),
     3652                                                        'link_title'        => __( 'Accept Invitation', 'buddypress' ),
    36503653                                                        'link_class'        => 'group-button accept-invite',
    36513654                                                );
    … …  
    36543657                                        // show a "Request Sent" button.
    36553658                                        } elseif ( $group->is_pending ) {
    3656                                                 $button = array(
     3659                                                $button_args = array(
    36573660                                                        'id'                => 'membership_requested',
    36583661                                                        'component'         => 'groups',
    … …  
    36633666                                                        'link_href'         => bp_get_group_permalink( $group ),
    36643667                                                        'link_text'         => __( 'Request Sent', 'buddypress' ),
     3668                                                        'link_title'        => __( 'Request Sent', 'buddypress' ),
    36653669                                                        'link_class'        => 'group-button pending membership-requested',
    36663670                                                );
    … …  
    36693673                                        // show a "Request Membership" button.
    36703674                                        } else {
    3671                                                 $button = array(
     3675                                                $button_args = array(
    36723676                                                        'id'                => 'request_membership',
    36733677                                                        'component'         => 'groups',
    … …  
    36783682                                                        'link_href'         => wp_nonce_url( trailingslashit( bp_get_group_permalink( $group ) . 'request-membership' ), 'groups_request_membership' ),
    36793683                                                        'link_text'         => __( 'Request Membership', 'buddypress' ),
     3684                                                        'link_title'        => __( 'Request Membership', 'buddypress' ),
    36803685                                                        'link_class'        => 'group-button request-membership',
    36813686                                                );
    … …  
    36873692
    36883693                /**
    3689                  * Filters the HTML button for joining a group.
     3694                 * Filters the arguments of the button for joining a group.
    36903695                 *
    36913696                 * @since 1.2.6
    36923697                 * @since 2.4.0 Added $group parameter to filter args.
    36933698                 *
    3694                  * @param string $button HTML button for joining a group.
    3695                  * @param object $group BuddyPress group object
    3696                  */
    3697                 return bp_get_button( apply_filters( 'bp_get_group_join_button', $button, $group ) );
     3699                 * @param array  $button_args The arguments for the button.
     3700                 * @param object $group       BuddyPress group object
     3701                 */
     3702                return apply_filters( 'bp_get_group_join_button', $button_args, $group );
     3703        }
     3704        /**
     3705         * Return button to join a group.
     3706         *
     3707         * @since 1.0.0
     3708         * @since 11.0.0 uses `bp_groups_get_group_join_button_args()`.
     3709         *
     3710         * @param object|bool $group Single group object.
     3711         * @return false|string
     3712         */
     3713        function bp_get_group_join_button( $group = false ) {
     3714                global $groups_template;
     3715
     3716                // Set group to current loop group if none passed.
     3717                if ( empty( $group ) ) {
     3718                        $group =& $groups_template->group;
     3719                }
     3720
     3721                $button_args = bp_groups_get_group_join_button_args( $group );
     3722
     3723                if ( ! array_filter( $button_args ) ) {
     3724                        return false;
     3725                }
     3726
     3727                return bp_get_button( $button_args );
    36983728        }
    36993729
Note: See TracChangeset for help on using the changeset viewer.