Replies
- Update: I looked in the database and it seems like the “secondary_item_id” was also being used to hold info for the type “friendship_created”, so both userIDs can be checked, both initiator and accepter. - I updated my code, it works. - It’s probably poor code, I am not a coder! - Could you please check it’s safe. - Thankyou. - function do_not_display_sitewide( $activity_object ) { // array of user IDs $exclude = array( 1, 2, 3 ); if( in_array( $activity_object->user_id, $exclude ) ) return $activity_object->hide_sitewide = true; if( in_array( $activity_object->secondary_item_id, $exclude ) && $activity_object->type === 'friendship_created') return $activity_object->hide_sitewide = true; } add_action('bp_activity_before_save', 'do_not_display_sitewide', 1, 1 );-  This reply was modified 10 months ago by Michael. 
 
-  This reply was modified 10 months ago by 
- Sorry, it pasted messy and won’t let me edit. - Here it is again. - function do_not_display_sitewide( $activity_object ) { // array of user IDs $exclude = array( 1, 2, 3 ); if( in_array( $activity_object->user_id, $exclude ) ) $activity_object->hide_sitewide = true; } add_action('bp_activity_before_save', 'do_not_display_sitewide', 1, 1 );
- Works great, thankyou! - The Lost Password form however still displays (initially) the prompt “Please enter your username or email address” and above the input text field it says “Username or Email Address” … any way those can also be modified to indicate it accepts email address only? Just for tidiness sake. - If not, thankyou anyway, the functionality is great. 
- Hi Brajesh 
 Thankyou, unfortunately my knowledge of SQL queries is too limited to modify your plugin code safely.- I tried to write a function to do the deletions by looping through the user IDs. Is this a reasonable way to approach it? It works on my test site but please could you review the code to confirm it’s safe to use. - Code loops through user IDs, checks if user exists, checks the last_activity and if older than 365 days ago then the account gets deleted. - function delete_abandoned() { require_once( ABSPATH.'wp-admin/includes/user.php' ); $nowTime = time(); for ( $x = 1; $x <= 1000; $x++ ) { $user = get_user_by( 'ID', $x ); if ( $user ) { $lastTime = strtotime( bp_get_user_last_activity($x) ); $daysAgo = intval( ($nowTime - $lastTime) / (3600*24) ); if ( $daysAgo > 365 ) { wp_delete_user($x); } } } }
- Thankyou so much Ravi, that works great on my test environment. Deletes the comments and correctly updates the total comments count per post too. Perfect. - Re. possible performance issues for large numbers of comments. - – the particular user has approx. 2000 comments spread over 4 years. 
 – would it be safe to do them all at once?
 – or maybe using ‘date_query’ with the get_comments() function, I could delete them in smaller batches.- What would you recommend? - Thanks! 
- Sorry! Sorry! Sorry! - The code snippet above was pasted wrong, here’s the correct version: - $entries = $wpdb->get_results("SELECT * FROM wp_posts WHERE post_type IN ('post', 'page')"); foreach($entries as $entry) { $post_id = $entry->ID; $comment_count = $wpdb->get_var("SELECT COUNT(*) AS comment_cnt FROM wp_comments WHERE comment_post_ID = '$post_id' AND comment_approved = '1'"); $wpdb->query("UPDATE wp_posts SET comment_count = '$comment_count' WHERE ID = '$post_id'"); }