Skip to:
Content

BuddyPress.org

Opened 3 years ago

Closed 3 years ago

Last modified 3 years ago

#7093 closed defect (bug) (fixed)

Groups: still using $_REQUEST['s'] for members search in bp_has_group_members()

Reported by: garrett-eclipse Owned by: dcavins
Milestone: 2.6 Priority: normal
Severity: normal Version: 2.5.0
Component: Groups Keywords: has-patch
Cc:

Description

Hello,

Updating my Buddypress to the latest and going through the updating templates I found that the latest Buddypress breaks the Members Search if ajax is disabled or viewing on non-js.

The search form in bp_directory_members_search_form() was updated to submit the search query via $_REQUESTmembers_search? rather than the previous $_REQUESTs?. But the bp_group_has_members function is still expecting the old $_REQUESTs? so searches don't turn up any results instead they just list all users as though no search was done.

The following code will need to be updated to us the new request term 'members_search';

<?php
        if ( is_null( $r['search_terms'] ) && ! empty( $_REQUEST['s'] ) ) {
                $r['search_terms'] = $_REQUEST['s'];
        }

Reference: https://github.com/buddypress/BuddyPress/blob/843da8eef10c12884c9a94186eec32743cb038e3/src/bp-groups/bp-groups-template.php#L3638

There may be other instances where it's looking for 's' instead of 'members_search' as the search request.

This isn't evident on a clean install as ajax is enabled and the script intercepts the search and handles the lookup via ajax rather than form submission and the bp_group_has_members method.

Thank you

Attachments (2)

7093.patch (1.5 KB) - added by Offereins 3 years ago.
Use 'members_search' key in $_REQUEST for group member searches
7093.1.patch (1.6 KB) - added by Offereins 3 years ago.
Use members component query arg in $_REQUEST

Download all attachments as: .zip

Change History (9)

#1 @garrett-eclipse
3 years ago

Temporary Workaround

In your members.php template under groups/single/members.php and admin.php under groups/single/admin.php before the bp_group_has_members loop inject the following php workaround;

<?php // Workaround for members_search
        if ( array_key_exists( 'members_search', $_REQUEST ) && isset( $_REQUEST['members_search'] ) && ! empty( $_REQUEST['members_search'] ) ) {
                $_REQUEST['s'] = $_REQUEST['members_search'];
        }
?>

This will intercept the $_REQUESTmembers_search? search string and apply it to $_REQUESTs? so that the bp_group_has_members loop function is provided the search term.

Cheers

#2 @garrett-eclipse
3 years ago

This seems to only affect group members and not general members as the search query arg there is set as follows;

<?php
    $search_terms_default = null;
    $search_query_arg = bp_core_get_component_search_query_arg( 'members' );
    if ( ! empty( $_REQUEST[ $search_query_arg ] ) ) {
        $search_terms_default = stripslashes( $_REQUEST[ $search_query_arg ] );
    }

So can safely focus on Members loops that are contained within Groups such as the Group Members loop and the Admin Group Members loop.

@Offereins
3 years ago

Use 'members_search' key in $_REQUEST for group member searches

@Offereins
3 years ago

Use members component query arg in $_REQUEST

#3 @Offereins
3 years ago

  • Component changed from Component - Members to Component - Groups
  • Keywords has-patch added
  • Summary changed from Group Members search broken on non-ajax sites as it's providing 'members_search' on $_REQUEST but system looks for 's' to Groups: still using $_REQUEST['s'] for members search in bp_has_group_members()

Good catch! Looks like this is a bug-worth-fixing-for-2.6. Patch is attached.

#4 @garrett-eclipse
3 years ago

Thanks @Offereins, appreciated. Would love if it could make it into 2.6

This ticket was mentioned in Slack in #buddypress by dcavins. View the logs.


3 years ago

#6 @dcavins
3 years ago

  • Owner set to dcavins
  • Resolution set to fixed
  • Status changed from new to closed

In 10847:

Improve search query arg handling in bp_group_has_members().

Structure the search term calculation in
bp_group_has_members() to match
the search term handling in
bp_has_members().

Fixes #7093.

Props dcavins, offereins, garrett-eclipse.

#7 @dcavins
3 years ago

  • Milestone changed from Awaiting Review to 2.6
Note: See TracTickets for help on using tickets.