LLMS_REST_Controller::create_item( WP_REST_Request $request )

Create an item.


Parameters Parameters

$request

(WP_REST_Request) (Required) Request object.


Top ↑

Return Return

(WP_Error|WP_REST_Response)


Top ↑

Source Source

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

	public function create_item( $request ) {

		if ( ! empty( $request['id'] ) ) {
			return llms_rest_bad_request_error( __( 'Cannot create an existing resource.', 'lifterlms' ) );
		}

		$item   = $this->prepare_item_for_database( $request );
		$object = $this->create_object( $item, $request );
		$schema = $this->get_item_schema();

		if ( is_wp_error( $object ) ) {
			return $object;
		}

		$this->object_inserted( $object, $request, $schema, true );

		$fields_update = $this->update_additional_fields_for_object( $item, $request );
		if ( is_wp_error( $fields_update ) ) {
			return $fields_update;
		}

		$this->object_completely_inserted( $object, $request, $schema, true );

		$request->set_param( 'context', 'edit' );

		$response = $this->prepare_item_for_response( $object, $request );
		$response = rest_ensure_response( $response );

		$response->set_status( 201 );
		$response->header( 'Location', rest_url( sprintf( '%s/%s/%d', $this->namespace, $this->rest_base, $this->get_object_id( $object ) ) ) );

		return $response;

	}


Top ↑

Changelog Changelog

Changelog
Version Description
1.0.0-beta.12 Call object_inserted and object_completely_inserted after an object is respectively inserted in the DB and all its additional fields have been updated as well (completely inserted).
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.