bp_email_get_unsubscribe_link

Creates unsubscribe link for notification emails.

Description

(string) bp_email_get_unsubscribe_link( (string) $args ); 

Returns (string)

The unsubscribe link.

Parameters (1)

0. $args (string)
The URL to which the unsubscribe query string is appended.

Usage

  1. if ( !function_exists( 'bp_email_get_unsubscribe_link' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-core/bp-core-functions.php'; 
  3.  
  4. // The URL to which the unsubscribe query string is appended. 
  5. $args = ''; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = bp_email_get_unsubscribe_link($args); 
  9.  

Defined (1)

The function is defined in the following location(s).

/bp-core/bp-core-functions.php  
  1. function bp_email_get_unsubscribe_link( $args ) { 
  2.  
  3. if ( empty( $args['notification_type'] ) || ! array_key_exists( $args['notification_type'], $emails ) ) { 
  4. return site_url( 'wp-login.php' ); 
  5.  
  6. $email_type = $args['notification_type']; 
  7. $redirect_to = ! empty( $args['redirect_to'] ) ? $args['redirect_to'] : site_url(); 
  8. $user_id = (int) $args['user_id']; 
  9.  
  10. // Bail out if the activity type is not un-unsubscribable. 
  11. if ( empty( $emails[ $email_type ]['unsubscribe'] ) ) { 
  12. return ''; 
  13.  
  14. $link = add_query_arg
  15. array( 
  16. 'action' => 'unsubscribe',  
  17. 'nh' => hash_hmac( 'sha1', "{$email_type}:{$user_id}", bp_email_get_salt() ),  
  18. 'nt' => $args['notification_type'],  
  19. 'uid' => $user_id,  
  20. ),  
  21. $redirect_to 
  22. ); 
  23.  
  24. /** 
  25. * Filters the unsubscribe link. 
  26. * @since 2.7.0 
  27. */ 
  28. return apply_filters( 'bp_email_get_link', $link, $redirect_to, $args );