Skip to:
Content
Pages
Categories
Search
Top
Bottom

bp_pre_user_query_construct filter missing during AJAX call


  • MattPurland
    Participant

    @mattpurland

    Warning in advance: I rarely, if ever, use WP – so please bare with me, and I apologise if any of my terminology is way off base!

    I’m using BuddyPress Profile Search (BPS) for member searches and the initial search form I’ve created works as expected, but when using AJAX to get more results a specific BP filter (bp_pre_user_query_construct) that needs to run is missing. This filter is used to run a function that modifies the BP_User_Query object by adding IDs to ‘include’, based on the BPS form fields.

    When I say ‘missing’, I mean it’s not part of the $wp_filters array when do_action_ref_array is executed to trigger the filter (line 171 of bp-core-classes.php). I found this when debugging the do_action_ref_array function, if I debug the code at line 556 (the if statement that locates the filter in $wp_filters) it returns due to not being found, and so isn’t executed.

    I really hope that makes sense to someone. I’m not sure why this specific filter is missing, as it seems the rest do exist (or a lot of them do).

    Any help would be appreciated!

Viewing 4 replies - 1 through 4 (of 4 total)

  • shanebp
    Moderator

    @shanebp

    Did you look thru the files for BuddyPress Profile Search ?

    Did you notice this action in bp-profile-search\bps-search.php ? And what it does?
    add_action ('bp_after_members_loop', 'bps_remove_filter');

    Might be a clue.


    MattPurland
    Participant

    @mattpurland

    I’m not really sure what you’re suggesting, that’s just to ensure the filter doesn’t apply to any member loops after the search. As a test I tried commenting it out but it made no difference.


    MattPurland
    Participant

    @mattpurland

    OK, I debugged the functions bps_add_filter and bps_remove_filter and neither of them get executed when it’s an AJAX request, even though they do get added. Which makes me think that the bp_before_members_loop and bp_after_members_loop hooks aren’t executing on AJAX calls.

    How do I get around this?


    MattPurland
    Participant

    @mattpurland

    OK, I figured out a fix. I’ve added do_action(‘bp_before_members_loop’) at the point when the arguments are unserialised in bps_set_cookie (line 17 of bps-search.php), and this works. But I need to have the filter removed once it’s done.

    Where should I put do_action(‘bp_after_members_loop’)?

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘bp_pre_user_query_construct filter missing during AJAX call’ is closed to new replies.
Skip to toolbar