bp_blogs_record_blog

Make BuddyPress aware of a new site so that it can track its activity.

Description

(bool|null) bp_blogs_record_blog( (int) $blog_id, (int) $user_id, (bool) $no_activity = false ); 

Returns (bool|null)

Returns false on failure.

Parameters (3)

0. $blog_id (int)
ID of the blog being recorded.
1. $user_id (int)
ID of the user for whom the blog is being recorded.
2. $no_activity — Optional. (bool) => false
Whether to skip recording an activity item about this blog creation. Default: false.

Usage

  1. if ( !function_exists( 'bp_blogs_record_blog' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-blogs/bp-blogs-functions.php'; 
  3.  
  4. // ID of the blog being recorded. 
  5. $blog_id = -1; 
  6.  
  7. // ID of the user for whom the blog is being recorded. 
  8. $user_id = -1; 
  9.  
  10. // Optional. Whether to skip recording an activity 
  11. // item about this blog creation. Default: false. 
  12. $no_activity = false; 
  13.  
  14. // NOTICE! Understand what this does before running. 
  15. $result = bp_blogs_record_blog($blog_id, $user_id, $no_activity); 
  16.  

Defined (1)

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

/bp-blogs/bp-blogs-functions.php  
  1. function bp_blogs_record_blog( $blog_id, $user_id, $no_activity = false ) { 
  2.  
  3. if ( empty( $user_id ) ) 
  4. $user_id = bp_loggedin_user_id(); 
  5.  
  6. // If blog is not recordable, do not record the activity. 
  7. if ( !bp_blogs_is_blog_recordable( $blog_id, $user_id ) ) 
  8. return false; 
  9.  
  10. $name = get_blog_option( $blog_id, 'blogname' ); 
  11. $url = get_home_url( $blog_id ); 
  12.  
  13. if ( empty( $name ) ) { 
  14. $name = $url; 
  15.  
  16. $description = get_blog_option( $blog_id, 'blogdescription' ); 
  17. $close_old_posts = get_blog_option( $blog_id, 'close_comments_for_old_posts' ); 
  18. $close_days_old = get_blog_option( $blog_id, 'close_comments_days_old' ); 
  19.  
  20. $thread_depth = get_blog_option( $blog_id, 'thread_comments' ); 
  21. if ( ! empty( $thread_depth ) ) { 
  22. $thread_depth = get_blog_option( $blog_id, 'thread_comments_depth' ); 
  23. } else { 
  24. // Perhaps filter this? 
  25. $thread_depth = 1; 
  26.  
  27. $recorded_blog = new BP_Blogs_Blog; 
  28. $recorded_blog->user_id = $user_id; 
  29. $recorded_blog->blog_id = $blog_id; 
  30. $recorded_blog_id = $recorded_blog->save(); 
  31. $is_recorded = !empty( $recorded_blog_id ) ? true : false; 
  32.  
  33. bp_blogs_update_blogmeta( $recorded_blog->blog_id, 'url', $url ); 
  34. bp_blogs_update_blogmeta( $recorded_blog->blog_id, 'name', $name ); 
  35. bp_blogs_update_blogmeta( $recorded_blog->blog_id, 'description', $description ); 
  36. bp_blogs_update_blogmeta( $recorded_blog->blog_id, 'last_activity', bp_core_current_time() ); 
  37. bp_blogs_update_blogmeta( $recorded_blog->blog_id, 'close_comments_for_old_posts', $close_old_posts ); 
  38. bp_blogs_update_blogmeta( $recorded_blog->blog_id, 'close_comments_days_old', $close_days_old ); 
  39. bp_blogs_update_blogmeta( $recorded_blog->blog_id, 'thread_comments_depth', $thread_depth ); 
  40.  
  41. $is_private = !empty( $_POST['blog_public'] ) && (int) $_POST['blog_public'] ? false : true; 
  42. $is_private = !apply_filters( 'bp_is_new_blog_public', !$is_private ); 
  43.  
  44. /** 
  45. * Fires after BuddyPress has been made aware of a new site for activity tracking. 
  46. * @since 1.0.0 
  47. * @since 2.6.0 Added $no_activity as a parameter. 
  48. * @param BP_Blogs_Blog $recorded_blog Current blog being recorded. Passed by reference. 
  49. * @param bool $is_private Whether or not the current blog being recorded is private. 
  50. * @param bool $is_recorded Whether or not the current blog was recorded. 
  51. * @param bool $no_activity Whether to skip recording an activity item for this blog creation. 
  52. */ 
  53. do_action_ref_array( 'bp_blogs_new_blog', array( &$recorded_blog, $is_private, $is_recorded, $no_activity ) );