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

Add a request to an item for a specific user, related to a specific class.


Parameters 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.
  • 'class'
    (string) Name of the invitations class.
  • 'item_id'
    (int) ID associated with the invitation and class.
  • 'secondary_item_id'
    (int) secondary ID associated with the invitation and class.
  • 'type'
    (string) @TODO. < missing description.
  • 'content'
    (string) Extra information provided by the requester or inviter.
  • 'date_modified'
    (string) Date the invitation was last modified.
  • 'invite_sent'
    (int) Has the invitation been sent, or is it a draft invite?

Default value: array()


Top ↑

Return Return

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


Source Source

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

	public function add_request( $args = array() ) {

		$r = bp_parse_args( $args, array(
			'user_id'           => 0,
			'inviter_id'        => 0,
			'invitee_email'     => '',
			'item_id'           => 0,
			'secondary_item_id' => 0,
			'type'              => 'request',
			'content'           => '',
			'date_modified'     => bp_core_current_time(),
			'invite_sent'       => 0,
			'accepted'          => 0
		), 'add_request' );

		// If there is no invitee, bail.
		if ( ! ( $r['user_id'] || $r['invitee_email'] ) ) {
			return false;
		}

		/**
		 * Is this user allowed to make a request in this situation?
		 *
		 * @since 5.0.0
		 *
		 * @param array $r Describes the invitation to be added.
		 */
		if ( ! $this->allow_request( $r ) ) {
			return false;
		}

		/*
		 * Avoid creating duplicate requests.
		 */
		$base_args = array(
			'user_id'           => $r['user_id'],
			'invitee_email'     => $r['invitee_email'],
			'item_id'           => $r['item_id'],
			'secondary_item_id' => $r['secondary_item_id'],
		);
		if ( $this->request_exists( $base_args ) ) {
			return false;
		}

		/*
		 * Check for outstanding invitations to the same item.
		 * A request + a sent invite = acceptance.
		 */
		$invite_args = array_merge( $base_args, array( 'invite_sent' => 'sent' ) );
		$invite = $this->invitation_exists( $invite_args );

		if ( $invite ) {
			// Accept the invite.
			return $this->accept_invitation( $base_args );
		} else {
			// Set up the new request.
			$request                    = new BP_Invitation;
			$request->user_id           = $r['user_id'];
			$request->inviter_id        = $r['inviter_id'];
			$request->invitee_email     = $r['invitee_email'];
			$request->class             = $this->class_name;
			$request->item_id           = $r['item_id'];
			$request->secondary_item_id = $r['secondary_item_id'];
			$request->type              = $r['type'];
			$request->content           = $r['content'];
			$request->date_modified     = $r['date_modified'];
			$request->invite_sent       = $r['invite_sent'];
			$request->accepted          = $r['accepted'];

			// Save the new invitation.
			return $request->save();
		}
	}


Top ↑

Changelog Changelog

Changelog
Version Description
5.0.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.