groups_send_membership_request( array|string $args )

Create a group membership request.


Parameters Parameters

$args

(array|string) (Required) Array of arguments.

  • 'user_id'
    (int) ID of the user being invited.
  • 'group_id'
    (int) ID of the group to which the user is being invited.
  • 'content'
    (string) Optional. Message to invitee.
  • 'date_modified'
    (string) Optional. Modified date for the invitation. Default: current date/time.


Top ↑

Return Return

(bool) True on success, false on failure.


Source Source

File: bp-groups/bp-groups-functions.php

function groups_send_membership_request( ...$args ) {
	// Backward compatibility with old method of passing arguments.
	if ( ! is_array( $args[0] ) || count( $args ) > 1 ) {
		_deprecated_argument( __METHOD__, '5.0.0', sprintf( __( 'Arguments passed to %1$s should be in an associative array. See the inline documentation at %2$s for more details.', 'buddypress' ), __METHOD__, __FILE__ ) );

		$old_args_keys = array(
			0 => 'user_id',
			1 => 'group_id',
		);

		$args = bp_core_parse_args_array( $old_args_keys, $args );
	} else {
		$args = reset( $args );
	}

	$r = bp_parse_args( $args, array(
		'user_id'       => false,
		'group_id'      => false,
		'content'       => '',
		'date_modified' => bp_core_current_time(),
	), 'groups_send_membership_request' );

	$inv_args = array(
		'user_id'       => $r['user_id'],
		'item_id'       => $r['group_id'],
		'content'       => $r['content'],
		'date_modified' => $r['date_modified'],
	);

	$invites_class = new BP_Groups_Invitation_Manager();
	$request_id = $invites_class->add_request( $inv_args );

	// If a new request was created, send the emails.
	if ( $request_id && is_int( $request_id ) ) {
		$invites_class->send_request_notification_by_id( $request_id, $r );
		$admins = groups_get_group_admins( $r['group_id'] );

		/**
		 * Fires after the creation of a new membership request.
		 *
		 * @since 1.0.0
		 *
		 * @param int   $requesting_user_id  ID of the user requesting membership.
		 * @param array $admins              Array of group admins.
		 * @param int   $group_id            ID of the group being requested to.
		 * @param int   $request_id          ID of the request.
		 */
		do_action( 'groups_membership_requested', $r['user_id'], $admins, $r['group_id'], $request_id );

		return $request_id;
	}

	return false;
}


Top ↑

Changelog Changelog

Changelog
Version Description
1.0.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

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