bp_ps_print_filter( $f )

Output BuddyBoss profile search condition filters.

Description

Source

File: bp-core/profile-search/bps-templates47.php

function bp_ps_print_filter( $f ) {
	if ( ! empty ( $f->options ) ) {
		$values = array();
		foreach ( $f->options as $key => $label ) {
			if ( in_array( $key, $f->values ) ) {
				$values[] = $label;
			}
		}
	}

	if ( isset( $f->filter ) ) {
		switch ( $f->filter ) {
			case 'range':
			case 'date_range':
				if ( ! isset ( $f->value['max'] ) ) {
					return sprintf( esc_html__( 'min: %1$s', 'buddyboss' ), $f->value['min'] );
				}
				if ( ! isset ( $f->value['min'] ) ) {
					return sprintf( esc_html__( 'max: %1$s', 'buddyboss' ), $f->value['max'] );
				}

				return sprintf( esc_html__( 'min: %1$s, max: %2$s', 'buddyboss' ), $f->value['min'], $f->value['max'] );

			case '':
				if ( isset ( $values ) ) {
					return sprintf( esc_html__( 'is: %1$s', 'buddyboss' ), $values[0] );
				}

				return sprintf( esc_html__( 'is: %1$s', 'buddyboss' ), $f->value );

			case 'contains':
				return sprintf( esc_html__( 'contains: %1$s', 'buddyboss' ), $f->value );

			case 'like':
				return sprintf( esc_html__( 'is like: %1$s', 'buddyboss' ), $f->value );

			case 'one_of':
				if ( count( $values ) == 1 ) {
					return sprintf( esc_html__( 'is: %1$s', 'buddyboss' ), $values[0] );
				}

				return sprintf( esc_html__( 'is one of: %1$s', 'buddyboss' ), implode( ', ', $values ) );

			case 'match_any':
				if ( count( $values ) == 1 ) {
					return sprintf( esc_html__( 'match: %1$s', 'buddyboss' ), $values[0] );
				}

				return sprintf( esc_html__( 'match any: %1$s', 'buddyboss' ), implode( ', ', $values ) );

			case 'match_all':
				if ( count( $values ) == 1 ) {
					return sprintf( esc_html__( 'match: %1$s', 'buddyboss' ), $values[0] );
				}

				return sprintf( esc_html__( 'match all: %1$s', 'buddyboss' ), implode( ', ', $values ) );

			case 'distance':
				if ( $f->value['units'] == 'km' ) {
					return sprintf( esc_html__( 'is within: %1$s km of %2$s', 'buddyboss' ),
						$f->value['distance'],
						$f->value['location'] );
				}

				return sprintf( esc_html__( 'is within: %1$s miles of %2$s', 'buddyboss' ),
					$f->value['distance'],
					$f->value['location'] );

			default:
				return "BP Profile Search: undefined filter <em>$f->filter</em>";
		}
	}
}

Changelog

Changelog
Version Description
BuddyBoss 1.0.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.