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

(array) (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

	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.