Skip to content

Instantly share code, notes, and snippets.

@JudeRosario
Forked from anonymous/bp-custom.php
Last active August 29, 2015 14:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JudeRosario/2af17a9dd5cb511a465a to your computer and use it in GitHub Desktop.
Save JudeRosario/2af17a9dd5cb511a465a to your computer and use it in GitHub Desktop.
<?php
function activity_publish_classified_posts($classified) {
$classified[] = array(
'classifieds',
'type' => 'new_blog_post',
'action' => apply_filters( 'bp_blogs_activity_new_post_action', sprintf( __( '%1$s updated the article, %2$s, in the %3$s', 'buddypress' ), bp_core_get_userlink( (int)$post->post_author ), '<a href="' . $post_permalink . '">' . $post->post_title . '</a>', '<a href="' . get_blog_option( $blog_id, 'home' ) . '">' . get_blog_option( $blog_id, 'blogname' ) . '</a>' ))
);
return $classified;
}
add_filter ( 'bp_blogs_record_post_post_types', 'activity_publish_classified_posts' );
function activity_edit_classified_posts( $post_id, $post, $user_id = false ) {
global $bp, $wpdb;
$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 not a post */
if ( $post->post_type != 'classifieds' )
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( __( '%s wrote a new blog post: %s', 'buddypress' ), bp_core_get_userlink( (int)$post->post_author ), '<a href="' . $post_permalink . '">' . $post->post_title . '</a>' );
$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_date_gmt
));
}
} else
bp_blogs_remove_post( $post_id, $blog_id );
bp_blogs_update_blogmeta( $blog_id, 'last_activity', bp_core_current_time() );
}
add_filter ( 'bp_blogs_record_post_post_types', 'activity_edit_classified_posts', 10 , 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment