Skip to:
Content

BuddyPress.org

Opened 10 years ago

Closed 6 years ago

#5455 closed enhancement (maybelater)

bp_ajax_querystring to filter members by role?

Reported by: landwire's profile landwire Owned by:
Milestone: Priority: normal
Severity: normal Version: 1.9.2
Component: Members Keywords: trac-tidy-2018
Cc:

Description

Hi there,
I am trying to put together some different member directory pages based on roles. I got the basic functionality working ok, but I am stuck with the ajax filtering of the "last active", "alphabetical" etc as they always revert to all members not just the ones I initially filtered, when used.

This discussion will explain better what I have tried:

http://buddypress.org/support/topic/how-to-add-a-few-more-members-directory-pages/

Maybe it needs an enhancement in the filter (like to take another argument that I can pass to it) - maybe there is a totally different approach necessary. Not sure. Any response is greatly appreciated.

Change History (4)

#1 @boonebgorges
10 years ago

landwire - I tried posting this to the buddypress.org thread, but I seem to be getting blocked by a mod_security rule or something. Anyway:

is_page does not work in ajax call.

I'd recommend working around it by looking at $SERVER[ 'HTTP_REFERER'] . During an AJAX request, it'll show the URL of the page that the AJAX request came from. A complete solution would then look something like this:

function bbg_filter_querystring( $q ) {
    // Break up the query string into the $query_args array   
    parse_str( $q, $query_args );

    if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
        $current_url = $SERVER['HTTP_REFERER'];
        // Do magic to determine whether you're on 'office' or whatever
        if ( false !== strpos( 'office', $current_url ) ) {
            $page_type = 'office';
        }
    } else {
        if ( is_page( 'office' ) ) {
            $page_type = 'office';
        }
    }

    // continue to query members
}
add_filter( 'bp_ajax_querystring', 'bbg_filter_querystring', 20 ); // Use a high priority so you don't stomp on BP

#2 @boonebgorges
10 years ago

  • Milestone changed from Awaiting Review to Future Release

As for the broader question of whether we can do something to make this process easier, the answer is yes, but it's very complicated. AJAX page filtering works based on a fairly complicated series of events involving cookies and a JS function called bp_filter_request. Our JS is not written in a way that allows for hooks/filters, so there's not really an obvious way we could add a parameter somewhere in this series of events that'd help.

I do think we could provide a more elegant API for reading/modifying the contents of bp_ajax_querystring. The current method, which requires you to look out for query string syntax, requires you to check whether AJAX is happening, etc, is fraught with issues.

I'll put this into Future Release so we can mull it over.

#3 @DJPaul
6 years ago

  • Keywords trac-tidy-2018 added

We're closing this ticket because it has not received any contribution or comments for at least two years. We have decided that it is better to close tickets that are good ideas, which have not gotten (or are unlikely to get) contributions, rather than keep things open indefinitely. This will help us share a more realistic roadmap for BuddyPress with you.

Everyone very much appreciates the time and effort that you spent sharing your idea with us. On behalf of the entire BuddyPress team, thank you.

If you feel strongly that this enhancement should still be added to BuddyPress, and you are able to contribute effort towards it, we encourage you to re-open the ticket, or start a discussion about it in our Slack channel. Please consider that time has proven that good ideas without contributions do not get built.

For more information, see https://bpdevel.wordpress.com/2018/01/21/our-awaiting-contributions-milestone-contains/
or find us on Slack, in the #buddypress channel: https://make.wordpress.org/chat/

#4 @DJPaul
6 years ago

  • Milestone Awaiting Contributions deleted
  • Resolution set to maybelater
  • Status changed from new to closed
Note: See TracTickets for help on using tickets.