bp_email_get_unsubscribe_link( array $args )

Creates unsubscribe link for notification emails.

Description

Parameters

$redirect_to

(string) (Required) The URL to which the unsubscribe query string is appended.

$args

(array) (Required) Used to build unsubscribe query string.

  • 'notification_type'
    (string) Which notification type is being sent.
  • 'user_id'
    (string) The ID of the user to whom the notification is sent.
  • 'redirect_to'
    (string) Optional. The url to which the user will be redirected. Default is the activity directory.

Return

(string) The unsubscribe link.

Source

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

function bp_email_get_unsubscribe_link( $args ) {
	$emails = bp_email_get_unsubscribe_type_schema();

	if ( empty( $args['notification_type'] ) || ! array_key_exists( $args['notification_type'], $emails ) ) {
		return wp_login_url();
	}

	$email_type  = $args['notification_type'];
	$redirect_to = ! empty( $args['redirect_to'] ) ? $args['redirect_to'] : site_url();
	$user_id     = (int) $args['user_id'];

	// Bail out if the activity type is not un-unsubscribable.
	if ( empty( $emails[ $email_type ]['unsubscribe'] ) ) {
		return '';
	}

	$link = add_query_arg(
		array(
			'action' => 'unsubscribe',
			'nh'     => hash_hmac( 'sha1', "{$email_type}:{$user_id}", bp_email_get_salt() ),
			'nt'     => $args['notification_type'],
			'uid'    => $user_id,
		),
		$redirect_to
	);

	/**
	 * Filters the unsubscribe link.
	 *
	 * @since BuddyPress 2.7.0
	 */
	return apply_filters( 'bp_email_get_link', $link, $redirect_to, $args );
}

Changelog

Changelog
Version Description
BuddyPress 2.7.0 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.