Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
08/12/2019 08:42:49 PM (4 months ago)
Author:
dcavins
Message:

Introduce BP_Groups_Invitation_Manager.

  • Add BP_Groups_Invitation_Manager, a new class that extends BP_Invitation_Manager for the purpose of using the new API to manage group invitations and requests.
  • Migrate group invitations to the new table on update, via bp_groups_migrate_invitations().
  • Update group invitation function logic to make use of BP_Groups_Invitation_Manager.

See #6210.

File:
1 edited

Legend:

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

    r12087 r12429  
    144144    );
    145145
     146    $request_message = '';
     147    $requests = groups_get_requests( $args = array(
     148        'user_id'    => $requesting_user_id,
     149        'item_id'    => $group_id,
     150    ) );
     151    if ( $requests ) {
     152        $request_message = current( $requests )->content;
     153    }
     154
    146155    $group = groups_get_group( $group_id );
    147156    $args  = array(
     
    152161            'group.id'             => $group_id,
    153162            'group-requests.url'   => esc_url( bp_get_group_permalink( $group ) . 'admin/membership-requests' ),
    154             'membership.id'        => $membership_id,
    155163            'profile.url'          => esc_url( bp_core_get_user_domain( $requesting_user_id ) ),
    156164            'requesting-user.id'   => $requesting_user_id,
    157165            'requesting-user.name' => bp_core_get_user_displayname( $requesting_user_id ),
     166            'request.message'      => $request_message,
    158167            'unsubscribe'          => esc_url( bp_email_get_unsubscribe_link( $unsubscribe_args ) ),
    159168        ),
     
    290299 * @since 1.0.0
    291300 *
    292  * @param BP_Groups_Group  $group           Group object.
    293  * @param BP_Groups_Member $member          Member object.
    294  * @param int              $inviter_user_id ID of the user who sent the invite.
     301 * @param BP_Groups_Group      $group           Group object.
     302 * @param BP_Groups_Member|int $member          Member object or invited_user_id.
     303 * @param int                  $inviter_user_id ID of the user who sent the invite.
    295304 */
    296305function groups_notification_group_invites( &$group, &$member, $inviter_user_id ) {
    297 
    298     // Bail if member has already been invited.
    299     if ( ! empty( $member->invite_sent ) ) {
    300         return;
    301     }
    302306
    303307    // @todo $inviter_ud may be used for caching, test without it
    304308    $inviter_ud      = bp_core_get_core_userdata( $inviter_user_id );
    305     $invited_user_id = $member->user_id;
     309
     310    if ( $member instanceof BP_Groups_Member ) {
     311        $invited_user_id = $member->user_id;
     312    } else if ( is_int( $member ) ) {
     313        $invited_user_id = $member;
     314    }
    306315
    307316    // Trigger a BuddyPress Notification.
     
    327336    );
    328337
     338    $invite_message = '';
     339    $invitations = groups_get_invites( $args = array(
     340        'user_id'    => $invited_user_id,
     341        'item_id'    => $group->id,
     342        'inviter_id' => $inviter_user_id,
     343    ) );
     344    if ( $invitations ) {
     345        $invite_message = current( $invitations )->content;
     346    }
     347
    329348    $args         = array(
    330349        'tokens' => array(
    331             'group'        => $group,
    332             'group.url'    => bp_get_group_permalink( $group ),
    333             'group.name'   => $group->name,
    334             'inviter.name' => bp_core_get_userlink( $inviter_user_id, true, false, true ),
    335             'inviter.url'  => bp_core_get_user_domain( $inviter_user_id ),
    336             'inviter.id'   => $inviter_user_id,
    337             'invites.url'  => esc_url( $invited_link . '/invites/' ),
    338             'unsubscribe'  => esc_url( bp_email_get_unsubscribe_link( $unsubscribe_args ) ),
     350            'group'          => $group,
     351            'group.url'      => bp_get_group_permalink( $group ),
     352            'group.name'     => $group->name,
     353            'inviter.name'   => bp_core_get_userlink( $inviter_user_id, true, false, true ),
     354            'inviter.url'    => bp_core_get_user_domain( $inviter_user_id ),
     355            'inviter.id'     => $inviter_user_id,
     356            'invites.url'    => esc_url( $invited_link . '/invites/' ),
     357            'invite.message' => $invite_message,
     358            'unsubscribe'    => esc_url( bp_email_get_unsubscribe_link( $unsubscribe_args ) ),
    339359        ),
    340360    );
     361
    341362    bp_send_email( 'groups-invitation', (int) $invited_user_id, $args );
    342363}
Note: See TracChangeset for help on using the changeset viewer.