BP_REST_Members_Endpoint::prepare_item_for_database( WP_REST_Request $request )

Prepares a single user for creation or update.


Parameters Parameters

$request

(WP_REST_Request) (Required) Request object.


Top ↑

Return Return

(stdClass)


Source Source

File: bp-members/classes/class-bp-rest-members-endpoint.php

	protected function prepare_item_for_database( $request ) {
		$prepared_user = parent::prepare_item_for_database( $request );

		// The parent class uses username instead of user_login.
		if ( ! isset( $prepared_user->user_login ) && isset( $request['user_login'] ) ) {
			$prepared_user->user_login = $request['user_login'];
		}

		/**
		 * Until BP REST version 0.3.0 the `types` parameter was used into the schema
		 * but not used to actually assign the member type to the user.
		 */
		$types = $request->get_param( 'types' );
		if ( $types ) {
			$request->set_param( 'member_type', bp_rest_sanitize_member_types( $types ) );
		}

		// Set member type.
		if ( isset( $prepared_user->ID ) && isset( $request['member_type'] ) ) {

			// Append on update. Add on creation.
			$append = WP_REST_Server::EDITABLE === $request->get_method();

			bp_set_member_type( $prepared_user->ID, $request['member_type'], $append );
		}

		/**
		 * Filters an user object before it is inserted or updated via the REST API.
		 *
		 * @since 5.0.0
		 *
		 * @param stdClass        $prepared_user An object prepared for inserting or updating the database.
		 * @param WP_REST_Request $request       Request object.
		 */
		return apply_filters( 'bp_rest_members_pre_insert_value', $prepared_user, $request );
	}


Top ↑

Changelog Changelog

Changelog
Version Description
5.0.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.