Guest User

Untitled

a guest
Apr 26th, 2019
29
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.32 KB | None | 0 0
  1. public function on_activity_publish( $activity_id, $post, $activity_args ) {
  2.  
  3.         if ( $post->post_type != bcg_get_post_type() ) {
  4.             return;
  5.         }
  6.  
  7.         $term_ids = array();
  8.         foreach ( bcg_get_taxonomies() as $taxonomy ) {
  9.             $categories = wp_get_post_terms( $post->ID, $taxonomy, array( 'fields' => 'ids' ) );
  10.  
  11.             if ( empty( $categories ) || is_wp_error( $categories ) ) {
  12.                 continue;
  13.             }
  14.  
  15.             $term_ids = array_merge( $term_ids, $categories );
  16.         }
  17.  
  18.         $term_ids = array_unique( $term_ids );
  19.  
  20.         if ( empty( $term_ids ) ) {
  21.             return;
  22.         }
  23.  
  24.         $term_group_id = 0;
  25.         $user_id       = get_current_user_id();
  26.  
  27.         foreach ( $term_ids as $term_id ) {
  28.             $group_ids = bcg_get_term_group_ids( $term_id );
  29.  
  30.             if ( ! empty( $group_ids ) ) {
  31.                 foreach ( $group_ids as $gid ) {
  32.                     if ( groups_is_user_member( $user_id, $gid ) ) {
  33.                         $term_group_id = $gid;
  34.                         break;
  35.                     }
  36.  
  37.                 }
  38.  
  39.                 if ( $term_group_id ) {
  40.                     break;
  41.                 }
  42.             }
  43.         }
  44.  
  45.         if ( empty( $term_group_id ) ) {
  46.             return;
  47.         }
  48.  
  49.         //update_post_meta( $post->ID, '_bcg_group_id', $term_group_id );
  50.         $args = wp_parse_args( array(
  51.             'id'                => $activity_id,
  52.             'component'         => 'groups',
  53.             'item_id'           => $term_group_id,
  54.             'secondary_item_id' => $post->ID,
  55.         ), $activity_args );
  56.  
  57.         bp_activity_add( $args );
  58.     }
Add Comment
Please, Sign In to add comment