bp_blogs_record_blog( int $blog_id, int $user_id, bool $no_activity = false )
Make BuddyPress aware of a new site so that it can track its activity.
Description
Parameters
- $blog_id
-
(int) (Required) ID of the blog being recorded.
- $user_id
-
(int) (Required) ID of the user for whom the blog is being recorded.
- $no_activity
-
(bool) (Optional) Whether to skip recording an activity item about this blog creation. Default: false.
Default value: false
Return
(false|null) Returns false on failure.
Source
File: bp-blogs/bp-blogs-functions.php
function bp_blogs_record_blog( $blog_id, $user_id, $no_activity = false ) { if ( empty( $user_id ) ) $user_id = bp_loggedin_user_id(); // If blog is not recordable, do not record the activity. if ( !bp_blogs_is_blog_recordable( $blog_id, $user_id ) ) return false; $name = get_blog_option( $blog_id, 'blogname' ); $url = get_home_url( $blog_id ); if ( empty( $name ) ) { $name = $url; } $description = get_blog_option( $blog_id, 'blogdescription' ); $close_old_posts = get_blog_option( $blog_id, 'close_comments_for_old_posts' ); $close_days_old = get_blog_option( $blog_id, 'close_comments_days_old' ); $moderation = get_blog_option( $blog_id, 'comment_moderation' ); $thread_depth = get_blog_option( $blog_id, 'thread_comments' ); if ( ! empty( $thread_depth ) ) { $thread_depth = get_blog_option( $blog_id, 'thread_comments_depth' ); } else { // Perhaps filter this? $thread_depth = 1; } $recorded_blog = new BP_Blogs_Blog; $recorded_blog->user_id = $user_id; $recorded_blog->blog_id = $blog_id; $recorded_blog_id = $recorded_blog->save(); $is_recorded = !empty( $recorded_blog_id ) ? true : false; bp_blogs_update_blogmeta( $recorded_blog->blog_id, 'url', $url ); bp_blogs_update_blogmeta( $recorded_blog->blog_id, 'name', $name ); bp_blogs_update_blogmeta( $recorded_blog->blog_id, 'description', $description ); bp_blogs_update_blogmeta( $recorded_blog->blog_id, 'last_activity', bp_core_current_time() ); bp_blogs_update_blogmeta( $recorded_blog->blog_id, 'close_comments_for_old_posts', $close_old_posts ); bp_blogs_update_blogmeta( $recorded_blog->blog_id, 'close_comments_days_old', $close_days_old ); bp_blogs_update_blogmeta( $recorded_blog->blog_id, 'thread_comments_depth', $thread_depth ); bp_blogs_update_blogmeta( $recorded_blog->blog_id, 'comment_moderation', $moderation ); $is_private = !empty( $_POST['blog_public'] ) && (int) $_POST['blog_public'] ? false : true; /** * Filters whether or not a new blog is public. * * @since BuddyPress 1.5.0 * * @param bool $is_private Whether or not blog is public. */ $is_private = !apply_filters( 'bp_is_new_blog_public', !$is_private ); /** * Fires after BuddyPress has been made aware of a new site for activity tracking. * * @since BuddyPress 1.0.0 * @since BuddyPress 2.6.0 Added $no_activity as a parameter. * * @param BP_Blogs_Blog $recorded_blog Current blog being recorded. Passed by reference. * @param bool $is_private Whether or not the current blog being recorded is private. * @param bool $is_recorded Whether or not the current blog was recorded. * @param bool $no_activity Whether to skip recording an activity item for this blog creation. */ do_action_ref_array( 'bp_blogs_new_blog', array( &$recorded_blog, $is_private, $is_recorded, $no_activity ) ); }
Changelog
Version | Description |
---|---|
BuddyPress 1.0.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.