[New Hack] Bumping Activity to the top when a reply comment is made
-
standard disclaimer – i don’t plan on releasing this as a plugin (better suited as a core thing – created a trac ticket already and don’t want to support messing around with the dates outside of the normal scope)
warning: there is no way to auto-revert back the date_recorded for the activity but this will store the date_recorded in the activity meta table for safe keeping (on your own if you want to revert back and moving that date back)
function etiviti_bp_activity_bump_denied_activity_type_check( $type ) {
return in_array($type, array( 'tweet', 'bp_link_comment', 'bp_link_vote', 'joined_group', 'created_group', 'friendship_created', 'friendship_accepted', 'new_member' ) );
}
function etiviti_bp_activity_bump( $comment_id, $params ) {
global $bp, $wpdb;
extract( $params, EXTR_SKIP );
$activity_parent = bp_activity_get_specific( array( 'activity_ids' => $activity_id ) );
//make sure we have something
if ( !$activity_parent = $activity_parent['activities'][0] )
return;
//don't update if certain activity types - remove this if you don't care
if ( etiviti_bp_activity_bump_denied_activity_type_check( $activity_parent->type ) )
return;
//be nice and save the date_recorded
if ( !bp_activity_get_meta( $activity_id, 'bump_date_recorded') )
bp_activity_update_meta( $activity_id, 'bump_date_recorded', $activity_parent->date_recorded );
//naughty but some bug using BP_Activity_Activity and save() - set the "new" date in order to bump this activity_parent wrap to the top
$wpdb->query( $wpdb->prepare( "UPDATE {$bp->activity->table_name} SET date_recorded = %s WHERE id = %d", gmdate( "Y-m-d H:i:s" ), $activity_id ) );
}
add_action( 'bp_activity_comment_posted', 'etiviti_bp_activity_bump', 1, 2 );the
etiviti_bp_activity_bump_denied_activity_type_check
is purely optional – i like to restrict certain activity functions.i have it working on my test site
http://etivite.com/ (just view the activity stream)
- The topic ‘[New Hack] Bumping Activity to the top when a reply comment is made’ is closed to new replies.