Skip to:
Content

BuddyPress.org

Changeset 13302


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

Location:
trunk/src
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-core/deprecated/11.0.php

    r13301 r13302  
    3434        return array();
    3535}
     36
     37/**
     38 * Catch the arguments for buttons
     39 *
     40 * @since 3.0.0
     41 * @deprecated 11.0.0
     42 *
     43 * @param array $button The arguments of the button that BuddyPress is about to create.
     44 *
     45 * @return array An empty array to stop the button creation process.
     46 */
     47function bp_nouveau_groups_catch_button_args( $button = array() ) {
     48        _deprecated_function( __FUNCTION__, '11.0.0' );
     49
     50        /**
     51         * Globalize the arguments so that we can use it
     52         * in bp_nouveau_get_groups_buttons().
     53         */
     54        bp_nouveau()->groups->button_args = $button;
     55
     56        // return an empty array to stop the button creation process
     57        return array();
     58}
  • 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
  • trunk/src/bp-templates/bp-nouveau/includes/groups/functions.php

    r13192 r13302  
    661661
    662662/**
    663  * Catch the arguments for buttons
    664  *
    665  * @since 3.0.0
    666  *
    667  * @param array $button The arguments of the button that BuddyPress is about to create.
    668  *
    669  * @return array An empty array to stop the button creation process.
    670  */
    671 function bp_nouveau_groups_catch_button_args( $button = array() ) {
    672         /**
    673          * Globalize the arguments so that we can use it
    674          * in bp_nouveau_get_groups_buttons().
    675          */
    676         bp_nouveau()->groups->button_args = $button;
    677 
    678         // return an empty array to stop the button creation process
    679         return array();
    680 }
    681 
    682 /**
    683663 * Catch the content hooked to the 'bp_group_header_meta' action
    684664 *
  • trunk/src/bp-templates/bp-nouveau/includes/groups/template-tags.php

    r13193 r13302  
    997997                // Membership button on groups loop or single group's header
    998998                } else {
    999                         /*
    1000                          * This filter workaround is waiting for a core adaptation
    1001                          * so that we can directly get the groups button arguments
    1002                          * instead of the button.
    1003                          *
    1004                          * See https://buddypress.trac.wordpress.org/ticket/7126
    1005                          */
    1006                         add_filter( 'bp_get_group_join_button', 'bp_nouveau_groups_catch_button_args', 100, 1 );
    1007 
    1008                         bp_get_group_join_button( $group );
    1009 
    1010                         remove_filter( 'bp_get_group_join_button', 'bp_nouveau_groups_catch_button_args', 100, 1 );
    1011 
    1012                         if ( isset( bp_nouveau()->groups->button_args ) && bp_nouveau()->groups->button_args ) {
    1013                                 $button_args = bp_nouveau()->groups->button_args;
    1014 
    1015                                 // If we pass through parent classes merge those into the existing ones
    1016                                 if ( $parent_class ) {
    1017                                         $parent_class .= ' ' . $button_args['wrapper_class'];
    1018                                 }
    1019 
    1020                                 // The join or leave group header button should default to 'button'
    1021                                 // Reverse the earler button var to set default as 'button' not 'a'
    1022                                 if ( empty( $args['button_element'] ) ) {
    1023                                         $button_element = 'button';
    1024                                 }
    1025 
    1026                                 $buttons['group_membership'] = array(
    1027                                         'id'                => 'group_membership',
    1028                                         'position'          => 5,
    1029                                         'component'         => $button_args['component'],
    1030                                         'must_be_logged_in' => $button_args['must_be_logged_in'],
    1031                                         'block_self'        => $button_args['block_self'],
    1032                                         'parent_element'    => $parent_element,
    1033                                         'button_element'    => $button_element,
    1034                                         'link_text'         => $button_args['link_text'],
    1035                                         'parent_attr'       => array(
    1036                                                         'id'    => $button_args['wrapper_id'],
    1037                                                         'class' => $parent_class,
    1038                                         ),
    1039                                         'button_attr'       => array(
    1040                                                 'id'    => ! empty( $button_args['link_id'] ) ? $button_args['link_id'] : '',
    1041                                                 'class' => $button_args['link_class'] . ' button',
    1042                                                 'rel'   => ! empty( $button_args['link_rel'] ) ? $button_args['link_rel'] : '',
    1043                                                 'title' => '',
    1044                                         ),
    1045                                 );
     999                        $button_args = bp_groups_get_group_join_button_args( $group );
     1000
     1001                        // If we pass through parent classes merge those into the existing ones
     1002                        if ( $parent_class ) {
     1003                                $parent_class .= ' ' . $button_args['wrapper_class'];
     1004                        }
     1005
     1006                        // The join or leave group header button should default to 'button'
     1007                        // Reverse the earler button var to set default as 'button' not 'a'
     1008                        if ( empty( $args['button_element'] ) ) {
     1009                                $button_element = 'button';
     1010                        }
     1011
     1012                        $buttons['group_membership'] = array(
     1013                                'id'                => 'group_membership',
     1014                                'position'          => 5,
     1015                                'component'         => $button_args['component'],
     1016                                'must_be_logged_in' => $button_args['must_be_logged_in'],
     1017                                'block_self'        => $button_args['block_self'],
     1018                                'parent_element'    => $parent_element,
     1019                                'button_element'    => $button_element,
     1020                                'link_text'         => $button_args['link_text'],
     1021                                'link_title'        => $button_args['link_title'],
     1022                                'parent_attr'       => array(
     1023                                                'id'    => $button_args['wrapper_id'],
     1024                                                'class' => $parent_class,
     1025                                ),
     1026                                'button_attr'       => array(
     1027                                        'id'    => ! empty( $button_args['link_id'] ) ? $button_args['link_id'] : '',
     1028                                        'class' => $button_args['link_class'] . ' button',
     1029                                        'rel'   => ! empty( $button_args['link_rel'] ) ? $button_args['link_rel'] : '',
     1030                                        'title' => '',
     1031                                ),
     1032                        );
    10461033
    10471034                        // If button element set add nonce 'href' link to data-attr attr.
     
    10511038                        // Else this is an anchor so use an 'href' attr.
    10521039                                $buttons['group_membership']['button_attr']['href'] = $button_args['link_href'];
    1053                         }
    1054 
    1055                                 unset( bp_nouveau()->groups->button_args );
    10561040                        }
    10571041                }
Note: See TracChangeset for help on using the changeset viewer.