Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
07/22/2022 10:50:40 AM (4 years ago)
Author:
imath
Message:

Introduce a function to only get the Friendship button arguments

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

Props hnla

See #7126
See #8722

File:
1 edited

Legend:

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

    r13108 r13301  
    361361        echo bp_get_add_friend_button( $potential_friend_id, $friend_status );
    362362}
    363         /**
    364          * Create the Add Friend button.
    365          *
    366          * @since 1.1.0
    367          *
    368          * @param int  $potential_friend_id ID of the user to whom the button
    369          *                                  applies. Default: value of {@link bp_get_potential_friend_id()}.
    370          * @param bool $friend_status       Not currently used.
    371          * @return bool|string HTML for the Add Friend button. False if already friends.
    372          */
    373         function bp_get_add_friend_button( $potential_friend_id = 0, $friend_status = false ) {
     363
     364        /**
     365         * Build friend button arguments.
     366         *
     367         * @since 11.0.0
     368         *
     369         * @param int    $potential_friend_id The user ID of the potential friend.
     370         * @return array The friend button arguments.
     371         */
     372        function bp_get_add_friend_button_args( $potential_friend_id = 0 ) {
     373                $button_args = array();
    374374
    375375                if ( empty( $potential_friend_id ) ) {
     
    377377                }
    378378
    379                 $is_friend = bp_is_friend( $potential_friend_id );
    380 
    381                 if ( empty( $is_friend ) ) {
    382                         return false;
    383                 }
    384 
    385                 switch ( $is_friend ) {
     379                $friendship_status = bp_is_friend( $potential_friend_id );
     380
     381                if ( empty( $friendship_status ) ) {
     382                        return $button_args;
     383                }
     384
     385                switch ( $friendship_status ) {
    386386                        case 'pending':
    387                                 $button = array(
     387                                $button_args = array(
    388388                                        'id'                => 'pending',
    389389                                        'component'         => 'friends',
     
    394394                                        'link_href'         => wp_nonce_url( bp_loggedin_user_domain() . bp_get_friends_slug() . '/requests/cancel/' . $potential_friend_id . '/', 'friends_withdraw_friendship' ),
    395395                                        'link_text'         => __( 'Cancel Friendship Request', 'buddypress' ),
     396                                        'link_title'        => __( 'Cancel Friendship Requested', 'buddypress' ),
    396397                                        'link_id'           => 'friend-' . $potential_friend_id,
    397398                                        'link_rel'          => 'remove',
     
    401402
    402403                        case 'awaiting_response':
    403                                 $button = array(
     404                                $button_args = array(
    404405                                        'id'                => 'awaiting_response',
    405406                                        'component'         => 'friends',
     
    410411                                        'link_href'         => bp_loggedin_user_domain() . bp_get_friends_slug() . '/requests/',
    411412                                        'link_text'         => __( 'Friendship Requested', 'buddypress' ),
     413                                        'link_title'        => __( 'Friendship Requested', 'buddypress' ),
    412414                                        'link_id'           => 'friend-' . $potential_friend_id,
    413415                                        'link_rel'          => 'remove',
     
    417419
    418420                        case 'is_friend':
    419                                 $button = array(
     421                                $button_args = array(
    420422                                        'id'                => 'is_friend',
    421423                                        'component'         => 'friends',
     
    426428                                        'link_href'         => wp_nonce_url( bp_loggedin_user_domain() . bp_get_friends_slug() . '/remove-friend/' . $potential_friend_id . '/', 'friends_remove_friend' ),
    427429                                        'link_text'         => __( 'Cancel Friendship', 'buddypress' ),
     430                                        'link_title'        => __( 'Cancel Friendship', 'buddypress' ),
    428431                                        'link_id'           => 'friend-' . $potential_friend_id,
    429432                                        'link_rel'          => 'remove',
     
    433436
    434437                        default:
    435                                 $button = array(
     438                                $button_args = array(
    436439                                        'id'                => 'not_friends',
    437440                                        'component'         => 'friends',
     
    442445                                        'link_href'         => wp_nonce_url( bp_loggedin_user_domain() . bp_get_friends_slug() . '/add-friend/' . $potential_friend_id . '/', 'friends_add_friend' ),
    443446                                        'link_text'         => __( 'Add Friend', 'buddypress' ),
     447                                        'link_title'        => __( 'Add Friend', 'buddypress' ),
    444448                                        'link_id'           => 'friend-' . $potential_friend_id,
    445449                                        'link_rel'          => 'add',
     
    454458                 * @since 1.1.0
    455459                 *
    456                  * @param string $button HTML markup for add friend button.
    457                  */
    458                 return bp_get_button( apply_filters( 'bp_get_add_friend_button', $button ) );
     460                 * @param string $button_args Button arguments for add friend button.
     461                 */
     462                return apply_filters( 'bp_get_add_friend_button', $button_args );
     463        }
     464
     465        /**
     466         * Create the Add Friend button.
     467         *
     468         * @since 1.1.0
     469         * @since 11.0.0 uses `bp_get_add_friend_button_args()`.
     470         *
     471         * @param int  $potential_friend_id ID of the user to whom the button
     472         *                                  applies. Default: value of {@link bp_get_potential_friend_id()}.
     473         * @param bool $friend_status       Not currently used.
     474         * @return bool|string HTML for the Add Friend button. False if already friends.
     475         */
     476        function bp_get_add_friend_button( $potential_friend_id = 0, $friend_status = false ) {
     477                $button_args = bp_get_add_friend_button_args( $potential_friend_id );
     478
     479                if ( ! array_filter( $button_args ) ) {
     480                        return false;
     481                }
     482
     483                return bp_get_button( $button_args );
    459484        }
    460485
Note: See TracChangeset for help on using the changeset viewer.