bbp_sanitize_search_request( string $query_arg = 's' )

Sanitize a query argument used to pass some search terms.

Description

Accepts a single parameter to be used for forums, topics, or replies.

Parameters

$query_arg

(Optional) s|fs|ts|rs

Default value: 's'

Return

(mixed)

Source

File: bp-forums/search/functions.php

109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
function bbp_sanitize_search_request( $query_arg = 's' ) {
 
    // Define allowed keys
    $allowed = bbp_get_search_type_ids();
 
    // Bail if not an allowed query string key
    if ( ! in_array( $query_arg, $allowed, true ) ) {
        return false;
    }
 
    // Get search terms if requested
    $terms = ! empty( $_REQUEST[ $query_arg ] )
        ? $_REQUEST[ $query_arg ]
        : false;
 
    // Bail if query argument does not exist
    if ( empty( $terms ) ) {
        return false;
    }
 
    // Maybe implode if an array
    if ( is_array( $terms ) ) {
        $terms = implode( ' ', $terms );
    }
 
    // Sanitize
    $retval = sanitize_title( trim( $terms ) );
 
    // Filter & return
    return apply_filters( 'bbp_sanitize_search_request', $retval, $query_arg );
}

Changelog

Changelog
Version Description
2.6.0 Introduced.

Questions?

We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.