Aurangajeb

buddypress-activity-post-with-wp-user-frontend

Sep 28th, 2021 (edited)
1,023
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function wpuf_bp_add_user_activity($activity_content) {
  2.     global $bp;
  3.     $user_id = get_current_user_id();
  4.     $from_user_link = bp_core_get_userlink($user_id);
  5.     $activity_action = sprintf(__('%s posted an update', 'buddypress'), $from_user_link);
  6.     $primary_link = bp_core_get_userlink($user_id, false, true);
  7.     $activity_id = bp_activity_add(array(
  8.         'user_id' => $user_id,
  9.         'action' => $activity_action,
  10.         'content' => $activity_content,
  11.         'primary_link' => $primary_link,
  12.         'component' => $bp->activity->id,
  13.         'type' => 'activity_update'
  14.     ));
  15.     return $activity_id;
  16. }
  17.  
  18. function wpuf_bp_add_group_activity($group_id, $content) {
  19.     $user_id = get_current_user_id();
  20.     $activity_id = groups_post_update(array(
  21.         'user_id' => $user_id,
  22.         'group_id' => $group_id,
  23.         'content' => $content
  24.     ));
  25.     return $activity_id;
  26. }
  27.  
  28. function wpufe_add_bp_activities($post_id) {
  29.     if (isset($_POST['bp_activity'])) {
  30.         $content = trim($_POST['bp_activity']);
  31.         if (!strlen($content)) {
  32.             return;
  33.         }
  34.         $group_id = 1;
  35.         wpuf_bp_add_user_activity($content);
  36.         wpuf_bp_add_group_activity($group_id, $content);
  37.     }
  38. }
  39. add_action('wpuf_add_post_after_insert', 'wpufe_add_bp_activities');
RAW Paste Data