Last active
July 20, 2016 11:29
-
-
Save kish2011/80715680b61f6b77fe37f41595860cf5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// bp-custom.php does not exist by default. If you don’t have a file located at /wp-content/plugins/bp-custom.php, | |
// @see https://codex.buddypress.org/themes/bp-custom-php/ | |
// @see https://codex.buddypress.org/developer/loops-reference/the-activity-stream-loop/ | |
// @see https://codex.buddypress.org/developer/function-examples/bp_ajax_querystring/ | |
// Show activity to friends only :) | |
function bp_loop_querystring_for_friend_only_activity( $query_string, $object ) { | |
if ( ! empty( $query_string ) ) { | |
$query_string .= '&'; | |
} | |
if ( 'activity' != $object ) // if not in activity page, then return!! | |
return; | |
// Get your friends | |
$friends = friends_get_friend_user_ids( bp_loggedin_user_id() ); | |
$friends[] = bp_loggedin_user_id(); | |
$friends_and_me = implode( ',', (array) $friends ); | |
$friends_and_me = '&user_id=' . $friends_and_me; | |
$query_string .= $friends_and_me; | |
$query_string .= '&per_page=2'; // You can set pagaination. If not needed, you can remove it. | |
return $query_string; | |
} | |
// Let's start ! | |
function bp_friend_only_activity() { | |
add_action( 'bp_legacy_theme_ajax_querystring', 'bp_loop_querystring_for_friend_only_activity', 20, 2 ); | |
} | |
// Not too early and not too late ! 9 seems ok ;) | |
add_action( 'bp_include', 'bp_friend_only_activity', 9 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment