bbp_add_user_subscription

Add a topic to user's subscriptions.

Description

bbp_add_user_subscription( (int) $user_id = 0, (int) $object_id = 0 ); 

Parameters (2)

0. $user_id — Optional. (int)
User id
1. $object_id — Optional. (int)
Topic id

Usage

  1. if ( !function_exists( 'bbp_add_user_subscription' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'bbpress/includes/users/functions.php'; 
  3.  
  4. // Optional. User id 
  5. $user_id = -1; 
  6.  
  7. // Optional. Topic id 
  8. $object_id = -1; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = bbp_add_user_subscription($user_id, $object_id); 
  12.  

Defined (1)

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

/includes/users/functions.php  
  1. function bbp_add_user_subscription( $user_id = 0, $object_id = 0 ) { 
  2. if ( empty( $user_id ) || empty( $object_id ) ) { 
  3. return false; 
  4.  
  5. // Get the post type 
  6. $post_type = get_post_type( $object_id ); 
  7. if ( empty( $post_type ) ) { 
  8. return false; 
  9.  
  10. switch( $post_type ) { 
  11.  
  12. // Forum 
  13. bbp_add_user_forum_subscription( $user_id, $object_id ); 
  14. break; 
  15.  
  16. // Topic 
  17. default : 
  18. bbp_add_user_topic_subscription( $user_id, $object_id ); 
  19. break; 
  20.  
  21. do_action( 'bbp_add_user_subscription', $user_id, $object_id, $post_type ); 
  22.  
  23. return true;