bp_groupblog_set_group_to_post_activity

Bp_groupblog_set_group_to_post_activity ( $activity ).

Description

bp_groupblog_set_group_to_post_activity( $activity ); 

Record the blog activity for the group - by Luiz Armesto

Parameters (1)

0. $activity
The activity.

Usage

  1. if ( !function_exists( 'bp_groupblog_set_group_to_post_activity' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'bp-groupblog/bp-groupblog.php'; 
  3.  
  4. // The activity. 
  5. $activity = null; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = bp_groupblog_set_group_to_post_activity($activity); 
  9.  

Defined (1)

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

/bp-groupblog.php  
  1. function bp_groupblog_set_group_to_post_activity( $activity ) { 
  2.  
  3. // sanity check! 
  4. if ( ! bp_is_active( 'groups' ) ) { 
  5. return; 
  6.  
  7. // stop if this activity item is not a blog post! 
  8. if ( $activity->type != 'new_blog_post' ) { 
  9. return; 
  10.  
  11. $blog_id = $activity->item_id; 
  12. $post_id = $activity->secondary_item_id; 
  13. $group_id = get_groupblog_group_id( $blog_id ); 
  14.  
  15. // no group is attached to this blog, so stop now! 
  16. if ( ! $group_id ) { 
  17. return; 
  18.  
  19. // fetch group data 
  20. $group = groups_get_group( array( 'group_id' => $group_id ) ); 
  21.  
  22. // fetch post data 
  23. $post = get_post( $post_id ); 
  24.  
  25. // Try to see if we are editing an existing groupblog post 
  26. $id = bp_activity_get_activity_id( array( 
  27. 'type' => 'new_groupblog_post',  
  28. 'item_id' => $group_id,  
  29. 'secondary_item_id' => $post_id 
  30. ) ); 
  31.  
  32. // Only allow certain HTML tags in post titles. 
  33. if ( ! empty( $post->post_title ) ) { 
  34. $allowed_tags = array( 
  35. 'em' => array(),  
  36. 'strong' => array(),  
  37. ); 
  38. $post->post_title = wp_kses( $post->post_title, $allowed_tags ); 
  39.  
  40. // This is an existing blog post! 
  41. if ( ! empty( $id ) ) { 
  42.  
  43. if ( apply_filters( 'groupblog_skip_edit_activity', false ) ) { 
  44. return; 
  45.  
  46. $activity->id = $id; 
  47.  
  48. // @todo just in case another user edited the original author's post? 
  49. //$activity->user_id = $post->post_author; 
  50.  
  51. $activity->action = sprintf( __( '%s edited the blog post %s in the group %s:', 'groupblog'), bp_core_get_userlink( $post->post_author ), '<a href="' . get_permalink( $post->ID ) .'">' . $post->post_title . '</a>', '<a href="' . bp_get_group_permalink( $group ) . '">' . esc_attr( $group->name ) . '</a>' ); 
  52.  
  53. // This is a new blog post! 
  54. } else { 
  55. $activity->action = sprintf( __( '%s wrote a new blog post %s in the group %s:', 'groupblog'), bp_core_get_userlink( $post->post_author ), '<a href="' . get_permalink( $post->ID ) .'">' . $post->post_title . '</a>', '<a href="' . bp_get_group_permalink( $group ) . '">' . esc_attr( $group->name ) . '</a>' ); 
  56.  
  57. $activity->primary_link = get_permalink( $post->ID ); 
  58.  
  59. // Replace the necessary values to display in group activity stream 
  60. $activity->item_id = (int)$group_id; 
  61. $activity->component = 'groups'; 
  62.  
  63. // use group's privacy settings for activity privacy 
  64. $activity->hide_sitewide = $group->status == 'public' ? 0 : 1; 
  65.  
  66. // need to set type as new_groupblog_post (see bp_groupblog_posts() below) or filters won't work 
  67. $activity->type = 'new_groupblog_post'; 
  68.  
  69. remove_action( 'bp_activity_before_save', 'bp_groupblog_set_group_to_post_activity'); 
  70.