Recipe: Find Friends search and personal friend codes

What it does

The BuddyPress All Friends content type (the Friends screen) has a Find Friends pill. Starting with 26.40.2 that pill offers two ways to connect:

  1. Search on the server. The app sends the typed text to the site, which returns matching members. Members are not limited to the 50 shown on the unsearched list.
  2. A personal friend code. Every signed-in member gets a My friend code row at the top of Find Friends. It opens a QR code. A friend who scans it sends a friend request in one step.

Nothing needs to be configured. Both features follow the member’s privacy choices automatically.


Search matching rules

What the member types How it matches
Part of a name (2 characters or more) Start of the display name, first name, last name, full name, or login
An email address The whole address, exactly. A partial email never matches.
A phone number (7 digits or more) The whole number in the billing phone field, exactly. Formatting such as spaces, dashes and brackets is ignored, and a leading US country code 1 is optional.

Always excluded from results:

  • members who turned on Hide me from friend search & public check-ins on their profile,
  • members with no first name,
  • the member searching, their friends, anyone with a pending request either way, and anyone they already follow (those appear in their own pills).

Searches are limited to 30 per member per minute.

Privacy of the search index

Each member row sent to the app carries a searchIndex used for on-device filtering. Email addresses and phone numbers are only included on rows for the viewer’s confirmed friends. Rows for everyone else carry names and login only. A login or display name that is itself an email address is left out for non-friends too.


Friend codes

  • The My friend code row shows a QR code, a one-line instruction, and a Reset my code button.
  • Reset my code asks for confirmation, then issues a new code. Every code shared before stops working. Codes do not expire otherwise.
  • Resetting does not affect your friends or pending friend requests.
  • The QR code holds a link to the site with the code attached (/?mam_fc=...).

What happens when someone scans a code

Situation Result
Not friends yet A friend request is sent and the code owner is notified (notification type BuddyPress – Friend Request).
The code owner already sent the scanner a request The request is accepted; the owner is notified (notification type BuddyPress – Friend Request Accepted).
Already friends “You’re already friends with …”
The scanner already sent a request “Your friend request to … is already pending.”
Own code, an account still in the Invited role, or an owner who hides from friend search Rejected with a message.
An old or altered code Rejected as not valid.

People are named by first and last name, never by email.

Limits: 20 scans per member per hour; after 5 invalid codes in 10 minutes a device is paused for the rest of that window.

The friend code button in the app header (26.40.9)

Signed-in members also get a QR code button in the app’s top navigation bar. It opens the same QR code, the instruction, and Reset my code, from any screen that shows the header.

  • While the button is on, the My friend code row is no longer shown in Find Friends. The scanner in the Friends search bar is unchanged.
  • Universal links. A code is a link to your site. When universal links are configured (the MAM Universal Link Manager plugin is active), the phone’s Camera app can open the app from it. Without universal links, the friend code screen tells members to scan the code inside the app.

Settings, under BuddyPress Settings > Friend Codes:

Setting Default Effect
Friend code: QR button in the app nav header yes no removes the header button and brings the Find Friends row back
Friend code: also keep the “My friend code” row no yes shows the row in Find Friends as well as the header button

Friends screen chips (26.41.7)

When the Friends tab uses the BuddyPress Members content type with the Friends screen source, the chips read, left to right: Find, My Friends, Requests, Following, Followers. The screen still opens on My Friends.

When a member has friend requests waiting for their answer, the chip shows the count, for example Requests (2). Requests the member sent are not counted.

Friend request notifications

When a member taps Add Friend on someone’s profile or row, or scans their friend code, the other member is notified, for example “Alex Smith sent you a friend request on ABI Now.” BuddyPress’s own friend request email is not sent for these requests. Nothing is sent when the two members are already friends or a request is already pending.

The notification type is BuddyPress – Friend Request under Mobile App Manager > Notifications. The Invite Friends form uses the same type when it invites someone who is already in the app; people not yet in the app get BuddyPress – Friend Request (New App User), the branded invite email.

Friend request accepted notifications

When a member accepts a friend request in the app, the member who sent the request is notified, for example “Alex Smith accepted your friend request.” This covers tapping Accept, scanning the code of someone who already sent you a request, and tapping Add Friend on someone who already sent you a request: in that last case the waiting request is accepted, and no second request is created. BuddyPress’s own “request accepted” email is not sent for these accepts. Nothing is sent when the two members are already friends.

The notification type is BuddyPress – Friend Request Accepted under Mobile App Manager > Notifications.

Which channels go out

The Notifications screen is the only place that decides. Whatever is ticked there (Email, Push Notification, Text Message) for a type is what is sent, and its subject and messages are what the member sees. When the plugin is activated or updated, a type the site has never saved is set up as:

Type Ticked Subject Message
BuddyPress – Friend Request Email, Push Notification [sender_name] sent you a friend request [sender_name] sent you a friend request on [app_name].
BuddyPress – Friend Request Accepted Push Notification [sender_name] accepted your friend request [sender_name] accepted your friend request
BuddyPress – Friend Request (New App User) Email [sender_name] invited you to [app_name] The branded invite email (app logo, the note, store badges); Push Notification and Text Message read [sender_name] invited you to [app_name].

A type you have saved is never changed by an update, and any box on it can be unticked. All three types also offer [message]: who sent the request and how (for example “Alex Smith scanned your friend code and sent you a friend request.”), or the personal note typed into the Invite Friends form.

Scanning from the existing QR scanner

The app’s general QR scanner also accepts friend codes. Only scanned values that are friend codes are handled by this plugin; product barcodes and every other code continue to work as before.


For app builders: screen keys

The Friends screen (button level) carries these string keys so the apps know what the screen supports:

Key Value
search_sub_action mam_bp_friend_search
search_min_chars 2
search_scan yes
scan_sub_action mam_bp_friend_code_scan

App endpoints (all require a signed-in member):

Subaction Arguments Purpose
mam_bp_friend_search search (string), reload (int) Run a Find Friends search; returns the rebuilt app JSON
mam_bp_friend_code_scan id (string, the scanned value) Resolve a scanned friend code
mam_bp_friend_code_rotate none Issue a new friend code

Scan and reset responses carry status, message, snackbar and reload: "yes", plus jsonData when something changed. The reset response also carries the new code_url.

Header button JSON

The button is an entry in the top-level nav_header_buttons array (all values are strings):

Key Value
id mam_bp_friend_code
icon qrcode (the apps draw their own QR glyph in the header colour)
position right
title My friend code
action friend_code
friend_code object: code_url, name, avatar (when the member has one), instructions, scan_hint, universal_links (yes / no), reset_title, reset_note, reset_confirm, reset_sub_action (mam_bp_friend_code_rotate)

The apps show scan_hint only when universal_links is no. A site can override the universal-link answer with the bp_mam_friend_code_universal_links filter (for example when its universal links do not claim the home page path).


Metadata

Field Value
Article type Recipe
Plugin slug mam-buddypress
Category Friends
Audience WordPress admin, app builder
Since 26.40.2
Was this article helpful?
Contents

    Need Support?

    Can't find the answer you're looking for? Don't worry we're here to help!