Number of posts is not quite the same as most recent post. The plugin itself doesn’t have a bug. You use a function called get_user_last_activity which checks if BP is running and uses the BP activity. If BP is not running it uses the most recent post.
Original code:
function get_user_last_activity($user_id) {
if (AA_is_bp()) {
return gmdate( 'Y-m-d H:i:s', (int)get_user_meta( $user_id, 'last_activity' ) );
}else{
global $wpdb;
$query = $wpdb->prepare(
"SELECT p.post_date
FROM $wpdb->posts p
WHERE
p.post_status = 'publish'
AND
p.post_author = %d
ORDER BY p.post_date
DESC LIMIT 1",
$user_id
);
return $wpdb->get_var( $query);
}
}
The other issue is that it only looks at posts table without regard for the post type. So if you have admins in there, it will count things like pages, added products etc… So in our case I also only wanted to use actual blog posts and not other posts so in the query I set the post type to posts.
Here is the hacked version:
// pluginhack
// if (AA_is_bp()) {
// return gmdate( 'Y-m-d H:i:s', (int)get_user_meta( $user_id, 'last_activity' ) );
// }else{
global $wpdb;
$query = $wpdb->prepare(
"SELECT p.post_date
FROM $wpdb->posts p
WHERE
p.post_status = 'publish'
AND
p.post_type = 'post'
AND
p.post_author = %d
ORDER BY p.post_date
DESC LIMIT 1",
$user_id
);
return $wpdb->get_var( $query);
}
// }
The hack is not appropriate for contribution to the plugin because its a dirty fix for my own specific purposes. However it shouldn’t take long to break out the options a little more to include recent post as a sorting option.
Have a look!