BP_Suggestions::validate()

Validate and sanitise the parameters for the suggestion service query.

Description

Be sure to call this class’ version of this method when implementing it in your own service. If validation fails, you must return a WP_Error object.

Return

(true|WP_Error) If validation fails, return a WP_Error object. On success, return true (bool).

Source

File: bp-core/classes/class-bp-suggestions.php

	public function validate() {
		$this->args['limit'] = absint( $this->args['limit'] );
		$this->args['term']  = trim( sanitize_text_field( $this->args['term'] ) );

		/**
		 * Filters the arguments to be validated for the BP_Suggestions query.
		 *
		 * @since BuddyPress 2.1.0
		 *
		 * @param BP_Suggestions $value Arguments to be validated.
		 * @param BP_Suggestions $this  Current BP_Suggestions instance.
		 */
		$this->args          = apply_filters( 'bp_suggestions_args', $this->args, $this );

		// Check for invalid or missing mandatory parameters.
		if ( ! $this->args['limit'] || ! $this->args['term'] ) {
			return new WP_Error( 'missing_parameter' );
		}

		// Check for blocked users (e.g. deleted accounts, or spammers).
		if ( is_user_logged_in() && ! bp_is_user_active( get_current_user_id() ) ) {
			return new WP_Error( 'invalid_user' );
		}

		/**
		 * Filters the status of validation for the BP_Suggestions query.
		 *
		 * @since BuddyPress 2.1.0
		 *
		 * @param bool           $value Whether or not the values are valid.
		 * @param BP_Suggestions $this  Current BP_Suggestions instance.
		 */
		return apply_filters( 'bp_suggestions_validate_args', true, $this );
	}

Changelog

Changelog
Version Description
BuddyPress 2.1.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.