LLMS_REST_Users_Controller::prepare_object_for_response( LLMS_Abstract_User_Data $object, WP_REST_Request $request )

Prepare an object for response


Parameters Parameters

$object

(LLMS_Abstract_User_Data) (Required) User object.

$request

(WP_REST_Request) (Required) Request object.


Top ↑

Return Return

(array)


Top ↑

Source Source

File: libraries/lifterlms-rest/includes/abstracts/class-llms-rest-users-controller.php

	protected function prepare_object_for_response( $object, $request ) {

		$prepared = array();
		$map      = array_flip( $this->map_schema_to_database() );
		$fields   = $this->get_fields_for_response( $request );

		// Write Only.
		unset( $map['user_pass'] );

		foreach ( $map as $db_key => $schema_key ) {
			if ( in_array( $schema_key, $fields, true ) ) {
				$prepared[ $schema_key ] = $object->get( $db_key );
			}
		}

		if ( in_array( 'roles', $fields, true ) ) {
			$prepared['roles'] = $object->get_user()->roles;
		}

		if ( in_array( 'avatar_urls', $fields, true ) ) {
			$prepared['avatar_urls'] = rest_get_avatar_urls( $object->get( 'user_email' ) );
		}

		return $prepared;

	}


Top ↑

Changelog Changelog

Changelog
Version Description
1.0.0-beta.14 Only add remapped keys to the response when the schema key is present in the expected response fields array.
1.0.0-beta.1 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

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