BP_Invitation_Manager::add_invitation( array $args = array() )

Add an invitation to a specific user, from a specific user, related to a specific class.

Description

Parameters

$args

(Optional) Array of arguments describing the invitation. All are optional.

  • 'user_id'
    (int) ID of the invited user.
  • 'inviter_id'
    (int) ID of the user who created the invitation.
  • 'invitee_email'
    (string) Email address of the invited user.
  • 'item_id'
    (int) ID associated with the invitation and class.
  • 'secondary_item_id'
    (int) Secondary ID associated with the invitation and class.
  • 'type'
    (string) Type of record this is: 'invite' or 'request'.
  • 'content'
    (string) Extra information provided by the requester or inviter.
  • 'date_modified'
    (string) Date the invitation was last modified.
  • 'send_invite'
    (int) Should the invitation also be sent, or is it a draft invite?

Default value: array()

Return

(int|bool) ID of the newly created invitation on success, false on failure.

Source

File: bp-core/classes/class-bp-invitation-manager.php

82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
public function add_invitation( $args = array() ) {
 
    $r = bp_parse_args( $args, array(
        'user_id'           => 0,
        'invitee_email'     => '',
        'inviter_id'        => 0,
        'item_id'           => 0,
        'secondary_item_id' => 0,
        'type'              => 'invite',
        'content'           => '',
        'date_modified'     => bp_core_current_time(),
        'send_invite'       => 0,
        'accepted'          => 0
    ), 'add_invitation' );
 
    // Invitations must have an invitee and inviter.
    if ( ! ( ( $r['user_id'] || $r['invitee_email'] ) && $r['inviter_id'] ) ) {
        return false;
    }
 
    /**
     * Is this user allowed to extend invitations in this situation?
     *
     * @since BuddyBoss 1.3.5
     *
     * @param array $r Describes the invitation to be added.
     */
    if ( ! $this->allow_invitation( $r ) ) {
        return false;
    }
 
    // Avoid creating duplicate invitations.
    $invite_id = $this->invitation_exists( array(
        'user_id'           => $r['user_id'],
        'invitee_email'     => $r['invitee_email'],
        'inviter_id'        => $r['inviter_id'],
        'item_id'           => $r['item_id'],
        'secondary_item_id' => $r['secondary_item_id'],
    ) );
 
    if ( ! $invite_id ) {
        // Set up the new invitation as a draft.
        $invitation                    = new BP_Invitation;
        $invitation->user_id           = $r['user_id'];
        $invitation->inviter_id        = $r['inviter_id'];
        $invitation->invitee_email     = $r['invitee_email'];
        $invitation->class             = $this->class_name;
        $invitation->item_id           = $r['item_id'];
        $invitation->secondary_item_id = $r['secondary_item_id'];
        $invitation->type              = $r['type'];
        $invitation->content           = $r['content'];
        $invitation->date_modified     = $r['date_modified'];
        $invitation->invite_sent       = 0;
        $invitation->accepted          = 0;
 
        $invite_id = $invitation->save();
    }
 
    // "Send" the invite if necessary.
    if ( $invite_id && $r['send_invite'] ) {
        $sent = $this->send_invitation_by_id( $invite_id );
        if ( ! $sent ) {
            return false;
        }
    }
 
    return $invite_id;
}

Changelog

Changelog
Version Description
BuddyBoss 1.3.5 Introduced.

Questions?

We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.