bp_dtheme_ajax_querystring( $query_string, $object )
This function looks scarier than it actually is. 🙂 Each object loop (activity/members/groups/blogs/forums) contains default parameters to show specific information based on the page we are currently looking at.
Description Description
The following function will take into account any cookies set in the JS and allow us to override the parameters sent. That way we can change the results returned without reloading the page. By using cookies we can also make sure that user settings are retained across page loads.
Return Return
(string) Query string for the activity/members/groups/blogs/forums loops
Source Source
File: bp-themes/bp-default/_inc/ajax.php
function bp_dtheme_ajax_querystring( $query_string, $object ) { if ( empty( $object ) ) return ''; // Set up the cookies passed on this AJAX request. Store a local var to avoid conflicts if ( ! empty( $_POST['cookie'] ) ) $_BP_COOKIE = wp_parse_args( str_replace( '; ', '&', urldecode( $_POST['cookie'] ) ) ); else $_BP_COOKIE = &$_COOKIE; $qs = array(); /** * Check if any cookie values are set. If there are then override the default params passed to the * template loop */ // Activity stream filtering on action if ( ! empty( $_BP_COOKIE['bp-' . $object . '-filter'] ) && '-1' != $_BP_COOKIE['bp-' . $object . '-filter'] ) { $qs[] = 'type=' . urlencode( $_BP_COOKIE['bp-' . $object . '-filter'] ); $qs[] = 'action=' . urlencode( $_BP_COOKIE['bp-' . $object . '-filter'] ); } if ( ! empty( $_BP_COOKIE['bp-' . $object . '-scope'] ) ) { if ( 'personal' == $_BP_COOKIE['bp-' . $object . '-scope'] ) { $user_id = ( bp_displayed_user_id() ) ? bp_displayed_user_id() : bp_loggedin_user_id(); $qs[] = 'user_id=' . $user_id; } // Activity stream scope only on activity directory. if ( 'all' != $_BP_COOKIE['bp-' . $object . '-scope'] && ! bp_displayed_user_id() && ! bp_is_single_item() ) $qs[] = 'scope=' . urlencode( $_BP_COOKIE['bp-' . $object . '-scope'] ); } // If page and search_terms have been passed via the AJAX post request, use those. if ( ! empty( $_POST['page'] ) && '-1' != $_POST['page'] ) $qs[] = 'page=' . absint( $_POST['page'] ); // exludes activity just posted and avoids duplicate ids if ( ! empty( $_POST['exclude_just_posted'] ) ) { $just_posted = wp_parse_id_list( $_POST['exclude_just_posted'] ); $qs[] = 'exclude=' . implode( ',', $just_posted ); } $object_search_text = bp_get_search_default_text( $object ); if ( ! empty( $_POST['search_terms'] ) && $object_search_text != $_POST['search_terms'] && 'false' != $_POST['search_terms'] && 'undefined' != $_POST['search_terms'] ) $qs[] = 'search_terms=' . urlencode( $_POST['search_terms'] ); // Now pass the querystring to override default values. $query_string = empty( $qs ) ? '' : join( '&', (array) $qs ); $object_filter = ''; if ( isset( $_BP_COOKIE['bp-' . $object . '-filter'] ) ) $object_filter = $_BP_COOKIE['bp-' . $object . '-filter']; $object_scope = ''; if ( isset( $_BP_COOKIE['bp-' . $object . '-scope'] ) ) $object_scope = $_BP_COOKIE['bp-' . $object . '-scope']; $object_page = ''; if ( isset( $_BP_COOKIE['bp-' . $object . '-page'] ) ) $object_page = $_BP_COOKIE['bp-' . $object . '-page']; $object_search_terms = ''; if ( isset( $_BP_COOKIE['bp-' . $object . '-search-terms'] ) ) $object_search_terms = $_BP_COOKIE['bp-' . $object . '-search-terms']; $object_extras = ''; if ( isset( $_BP_COOKIE['bp-' . $object . '-extras'] ) ) $object_extras = $_BP_COOKIE['bp-' . $object . '-extras']; return apply_filters( 'bp_dtheme_ajax_querystring', $query_string, $object, $object_filter, $object_scope, $object_page, $object_search_terms, $object_extras ); }
Changelog Changelog
Version | Description |
---|---|
BuddyPress (1.2) | Introduced. |