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

	 */
	protected $disallowed_additional_fields = array();

	/**
	 * Meta field names to skip (added via `register_meta()`).
	 *
	 * @var string[]
	 */
	protected $disallowed_meta_fields = array();

	/**
	 * Create an item.
	 *
	 * @since 1.0.0-beta.1
	 * @since 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).
	 * @since 1.0.0-beta.27 Handle custom meta registered via `register_meta()` and custom rest fields registered via `register_rest_field()`.
	 *
	 * @param WP_REST_Request $request Request object.
	 * @return WP_Error|WP_REST_Response
	 */
	public function create_item( $request ) {

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

		$schema = $this->get_item_schema();

		$item = $this->prepare_item_for_database( $request );
		// Exclude additional fields registered via `register_rest_field()`.
		$item   = array_diff_key( $item, $this->get_additional_fields() );
		$object = $this->create_object( $item, $request );


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.