Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
03/16/2021 06:53:43 PM (6 years ago)
Author:
imath
Message:

Make sure to apply Nouveau's Group invite restrictions in REST

(trunk)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-templates/bp-nouveau/includes/groups/functions.php

    r12715 r12860  
    44 *
    55 * @since 3.0.0
    6  * @version 6.3.0
     6 * @version 7.2.1
    77 */
    88
    … …  
    510510
    511511/**
     512 * Makes sure the BP REST API groups/invites endpoint respects invite restrictions.
     513 *
     514 * @since 7.2.1
     515 *
     516 * @param bool|WP_Error   $retval  Whether the request can continue.
     517 * @param WP_REST_Request $request The request sent to the API.
     518 * @return bool|WP_Error
     519 */
     520function bp_nouveau_restrict_rest_group_invite_to_friends( $retval, $request ) {
     521        if ( true === $retval && bp_is_active( 'friends' ) ) {
     522                $group_id   = $request->get_param( 'group_id' );
     523                $user_id    = $request->get_param( 'user_id' );
     524                $inviter_id = $request->get_param( 'inviter_id' );
     525
     526                if ( ! $inviter_id ) {
     527                        $inviter_id = bp_loggedin_user_id();
     528                }
     529
     530                if ( bp_nouveau_groups_get_group_invites_setting( $user_id ) && 'is_friend' !== BP_Friends_Friendship::check_is_friend( $inviter_id, $user_id ) ) {
     531                        $retval = new WP_Error(
     532                                'bp_rest_group_invite_cannot_create_item',
     533                                __( 'Sorry, you are not allowed to create the invitation as requested.', 'buddypress' ),
     534                                array(
     535                                        'status' => rest_authorization_required_code(),
     536                                )
     537                        );
     538                }
     539        }
     540
     541        return $retval;
     542}
     543add_filter( 'bp_rest_group_invites_create_item_permissions_check', 'bp_nouveau_restrict_rest_group_invite_to_friends', 10, 2 );
     544
     545/**
    512546 * @since 3.0.0
    513547 */
Note: See TracChangeset for help on using the changeset viewer.