Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Filtering bp_ajax_querystring
<?php
/**
* Filter the querystring when on the activity directory
*
* @param string/array $query_string component loop arguments
* @param sting $object component name
* @return string the edited query string
*/
function bphelp_ajax_querystring( $query_string, $object ) {
// if not a query string about activities, return without modifying
if ( 'activity' != $object ) {
return $query_string;
}
// if not on the activity directory page, return without modifying
if ( ! bp_is_activity_directory() ) {
return $query_string;
}
// Make sure we will manipulate an array
$query_args = wp_parse_args( $query_string, array() );
/**
* About overriding scope
* the commented line would force the scope to be just-me but on the activity
* directory there's the mentions/friends tab so it would prevent mentions to
* ever appear for instance
*/
//$query_args['scope'] = 'just-me';
/**
* A nicer way to deal with it...
* (add as much scopes as needed)
*/
$enabled_scopes = array( 'mentions', 'friends', 'just-me' );
if ( ! empty( $query_args['scope'] ) ) {
$scopes = explode( ',', $query_args['scope'] );
$scopes_to_use = array_intersect( $scopes, $enabled_scopes );
// Default to just-me
} else {
$scopes_to_use = array( 'just-me' );
}
$query_args['scope'] = join( ',', $scopes_to_use );
// random example..
$query_args['per_page'] = 1;
// Build the querystring
$new_query_string = http_build_query( $query_args );
// it's always a good idea to allow other edit the querystring
// and to include the originale querystring
return apply_filters( 'bphelp_ajax_querystring', $new_query_string, $query_string );
}
add_filter( 'bp_ajax_querystring', 'bphelp_ajax_querystring', 20, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.