Skip to content

Instantly share code, notes, and snippets.

@KaineLabs
Last active February 13, 2022 21:31
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KaineLabs/6c84a972885dfd0866af0b968006348b to your computer and use it in GitHub Desktop.
Save KaineLabs/6c84a972885dfd0866af0b968006348b to your computer and use it in GitHub Desktop.
BuddyPress move new commented activity stream to top
<?php
/**
* Sort last commented posts to the top of activity line
* Source: http://techiescircle.com/move-new-commented-activity-stream-to-top/
*/
function yzc_bp_activity_bump_comment_posted( $comment_id, $params ) {
global $bp, $wpdb;
extract( $params, EXTR_SKIP );
$activity_parent = bp_activity_get_specific( array( 'activity_ids' => $activity_id ) );
if ( !$activity_parent = $activity_parent['activities'][0] ) {
return;
}
if ( yzc_bp_activity_bump_denied_activity_type_check( $activity_parent->type ) ){
return;
}
if ( ! yzc_bp_activity_bump_denied_user_check() ) {
return;
}
//be nice and save the date_recorded
if ( ! bp_activity_get_meta( $activity_id, 'bp_activity_bump_date_recorded') ) {
bp_activity_update_meta( $activity_id, 'bp_activity_bump_date_recorded', $activity_parent->date_recorded );
}
$q = $wpdb->prepare( "UPDATE {$bp->activity->table_name} SET date_recorded = %s WHERE id = %d",gmdate( "Y-m-d H:i:s" ), $activity_id );
// Update Date.
$wpdb->query( $q );
}
add_action( 'bp_activity_comment_posted', 'yzc_bp_activity_bump_comment_posted', 1, 2 );
/**
* Show Last Updated Comment Time.
**/
function yzc_bp_activity_bump_time_since( $content, $activity ) {
global $bp;
if ( ! $bumpdate = bp_activity_get_meta( $activity->id, 'bp_activity_bump_date_recorded') )
return $content;
$content = '<span class="time-since">' . sprintf( __( ' updated %s', 'bp-activity-bump' ), bp_core_time_since( $activity->date_recorded ) ) . '</span>';
return apply_filters( 'etivite_bp_activity_bump_time_since', '<span class="time-since time-created">' . sprintf( __( ' %s', 'buddypress' ), bp_core_time_since( $bumpdate ) ) . '</span> &middot; ' . $content, $activity->date_recorded, $bumpdate, $content );
}
add_filter( 'bp_activity_time_since', 'yzc_bp_activity_bump_time_since', 1, 2 );
function yzc_bp_activity_bump_denied_activity_type_check( $type ) {
$types = (array) maybe_unserialize( get_option( 'bp_activity_bump_denied_activity_types') );
return in_array( $type, apply_filters( 'yzc_bp_activity_bump_denied_activity_types', $types ) );
}
function yzc_bp_activity_bump_denied_user_check() {
global $bp;
// All, super, wp_cap
$types = maybe_unserialize( get_option( 'bp_activity_bump_denied_user_types') );
if ( $types && ( $types['super_admin'] || $types['user_cap'] ) ) {
if ( current_user_can( $types['user_cap'] ) ){
return true;
}
if ( $types['super_admin'] && $bp->loggedin_user->is_super_admin ) {
return true;
}
return false;
}
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment