Created
February 20, 2015 19:47
-
-
Save imath/6017aec29dfcbde5e2ee to your computer and use it in GitHub Desktop.
Filtering bp_ajax_querystring
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
| <?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