Advertisement
Guest User

bp-activity-functions

a guest
Sep 21st, 2020
232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.89 KB | None | 0 0
  1. function bp_activity_add( $args = '' ) {
  2.  
  3.     $r = bp_parse_args( $args, array(
  4.         'id'                => false,                  
  5.         'action'            => '',                    
  6.         'content'           => '',                    
  7.         'component'         => false,                  
  8.         'type'              => false,                  
  9.         'primary_link'      => '',                    
  10.         'user_id'           => bp_loggedin_user_id(),  
  11.         'item_id'           => false,                  
  12.         'secondary_item_id' => false,                  
  13.         'recorded_time'     => bp_core_current_time(),
  14.         'hide_sitewide'     => false,
  15.         'new_row'       => '',                              //MY NEW ROW!
  16.         'is_spam'           => false,                
  17.         'error_type'        => 'bool'
  18.     ), 'activity_add' );
  19.  
  20.     // Make sure we are backwards compatible.
  21.     if ( empty( $r['component'] ) && !empty( $r['component_name'] ) ) {
  22.         $r['component'] = $r['component_name'];
  23.     }
  24.  
  25.     if ( empty( $r['type'] ) && !empty( $r['component_action'] ) ) {
  26.         $r['type'] = $r['component_action'];
  27.     }
  28.  
  29.     // Setup activity to be added.
  30.     $activity                    = new BP_Activity_Activity( $r['id'] );
  31.     $activity->user_id           = $r['user_id'];
  32.     $activity->component         = $r['component'];
  33.     $activity->type              = $r['type'];
  34.     $activity->content           = $r['content'];
  35.     $activity->primary_link      = $r['primary_link'];
  36.     $activity->item_id           = $r['item_id'];
  37.     $activity->secondary_item_id = $r['secondary_item_id'];
  38.     $activity->new_row       = $r['new_row'];               //MY NEW ROW!
  39.     $activity->date_recorded     = $r['recorded_time'];
  40.     $activity->hide_sitewide     = $r['hide_sitewide'];
  41.     $activity->is_spam           = $r['is_spam'];
  42.     $activity->error_type        = $r['error_type'];
  43.     $activity->action            = ! empty( $r['action'] )
  44.                         ? $r['action']
  45.                         : bp_activity_generate_action_string( $activity );
  46.  
  47.     $save = $activity->save();
  48.  
  49.     if ( 'wp_error' === $r['error_type'] && is_wp_error( $save ) ) {
  50.         return $save;
  51.     } elseif ('bool' === $r['error_type'] && false === $save ) {
  52.         return false;
  53.     }
  54.  
  55.     // If this is an activity comment, rebuild the tree.
  56.     if ( 'activity_comment' === $activity->type ) {
  57.         // Also clear the comment cache for the parent activity ID.
  58.         wp_cache_delete( $activity->item_id, 'bp_activity_comments' );
  59.  
  60.         BP_Activity_Activity::rebuild_activity_comment_tree( $activity->item_id );
  61.     }
  62.  
  63.     wp_cache_delete( 'bp_activity_sitewide_front', 'bp' );
  64.  
  65.     /**
  66.      * Fires at the end of the execution of adding a new activity item, before returning the new activity item ID.
  67.      *
  68.      * @since 1.1.0
  69.      * @since 4.0.0 Added the `$activity_id` parameter.
  70.      *
  71.      * @param array $r           Array of parsed arguments for the activity item being added.
  72.      * @param int   $activity_id The id of the activity item being added.
  73.      */
  74.     do_action( 'bp_activity_add', $r, $activity->id );
  75.  
  76.     return $activity->id;
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement