LLMS_REST_Controller_Stubs::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-controller-stubs.php

	protected function prepare_object_for_response( $object, $request ) {

		if ( ! method_exists( $object, 'get' ) ) {
			// Translators: %s = method name.
			_doing_it_wrong( 'LLMS_REST_Controller::prepare_object_for_response', sprintf( __( "Method '%s' must be overridden.", 'lifterlms' ), __METHOD__ ), '1.0.0-beta.1' );
		}

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

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

		return $prepared;

	}

Top ↑

Changelog Changelog

Changelog
Version Description
1.0.0-beta.3 Conditionally throw _doing_it_wrong().
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.