Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function on_activity_publish( $activity_id, $post, $activity_args ) {
- if ( $post->post_type != bcg_get_post_type() ) {
- return;
- }
- $term_ids = array();
- foreach ( bcg_get_taxonomies() as $taxonomy ) {
- $categories = wp_get_post_terms( $post->ID, $taxonomy, array( 'fields' => 'ids' ) );
- if ( empty( $categories ) || is_wp_error( $categories ) ) {
- continue;
- }
- $term_ids = array_merge( $term_ids, $categories );
- }
- $term_ids = array_unique( $term_ids );
- if ( empty( $term_ids ) ) {
- return;
- }
- $term_group_id = 0;
- $user_id = get_current_user_id();
- foreach ( $term_ids as $term_id ) {
- $group_ids = bcg_get_term_group_ids( $term_id );
- if ( ! empty( $group_ids ) ) {
- foreach ( $group_ids as $gid ) {
- if ( groups_is_user_member( $user_id, $gid ) ) {
- $term_group_id = $gid;
- break;
- }
- }
- if ( $term_group_id ) {
- break;
- }
- }
- }
- if ( empty( $term_group_id ) ) {
- return;
- }
- //update_post_meta( $post->ID, '_bcg_group_id', $term_group_id );
- $args = wp_parse_args( array(
- 'id' => $activity_id,
- 'component' => 'groups',
- 'item_id' => $term_group_id,
- 'secondary_item_id' => $post->ID,
- ), $activity_args );
- bp_activity_add( $args );
- }
Add Comment
Please, Sign In to add comment