Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // begin record products to BP activity stream
- function product_record_activity( $post_id, $post, $user_id = false ) {
- global $bp, $wpdb;
- //check for multisite install
- if(!is_multisite()) return false;
- $post_id = (int)$post_id;
- $blog_id = (int)$wpdb->blogid;
- if ( !$user_id )
- $user_id = (int)$post->post_author;
- /* This is to stop infinite loops with Donncha's sitewide tags plugin */
- if ( (int)$bp->site_options['tags_blog_id'] == (int)$blog_id ) return false;
- /* Don't record this if it's a regular post */
- if ( $post->post_type != 'product' ) return false;
- if ( ( 'publish' == $post->post_status ) && ( '' == $post->post_password ) ) {
- if ( (int)get_blog_option( $blog_id, 'blog_public' ) || !bp_core_is_multisite() ) {
- /* Record this in activity streams */
- $post_permalink = get_permalink( $post_id );
- $activity_action = sprintf( __( '%1$s added or updated the product %2$s, in the store: %3$s', 'buddypress' ), bp_core_get_userlink( (int)$post->post_author ), '<a href="' . $post_permalink . '">' . $post->post_title . '</a>', get_blog_option($blog_id, 'blogname') );
- $activity_content = $post->post_content;
- bp_blogs_record_activity( array(
- 'user_id' => (int)$post->post_author,
- 'action' => apply_filters( 'bp_blogs_activity_new_post_action', $activity_action, &$post, $post_permalink ),
- 'content' => apply_filters( 'bp_blogs_activity_new_post_content', $activity_content, &$post, $post_permalink ),
- 'primary_link' => apply_filters( 'bp_blogs_activity_new_post_primary_link', $post_permalink, $post_id ),
- 'type' => 'new_blog_post',
- 'item_id' => $blog_id,
- 'secondary_item_id' => $post_id,
- 'recorded_time' => $post->post_modified_gmt
- ));
- }
- } else
- bp_blogs_remove_post( $post_id, $blog_id );
- bp_blogs_update_blogmeta( $blog_id, 'last_activity', bp_core_current_time() );
- do_action( 'bp_blogs_new_blog_post', $post_id, $post, $user_id );
- /* check for existing entry and update if one exists */
- $id = bp_activity_get_activity_id( array(
- 'user_id' => $user_id,
- 'component' => $component,
- 'type' => $type,
- 'item_id' => $item_id,
- 'secondary_item_id' => $secondary_item_id
- ) );
- return bp_activity_add( array( 'id' => $id, 'user_id' => $user_id, 'action' => $action, 'content' => $content, 'primary_link' => $primary_link, 'component' => $component, 'type' => $type, 'item_id' => $item_id, 'secondary_item_id' => $secondary_item_id, 'recorded_time' => $recorded_time, 'hide_sitewide' => $hide_sitewide ) );
- }
- add_action( 'save_post', 'product_record_activity', 10, 2 );
- //end record products to the BP activity stream
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement