LLMS_REST_Controller::filter_item_schema( array $schema )

Filter the item schema.


Parameters Parameters

$schema

(array) (Required) The resource item schema.


Top ↑

Return Return

(array)


Top ↑

Source Source

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

	protected function filter_item_schema( $schema ) {

		$object_type       = $this->get_object_type( $schema );
		$unfiltered_schema = $schema;

		/**
		 * Filters the item schema.
		 *
		 * The dynamic portion of the hook name, `$object_type`, refers the object type this controller is responsible for managing.
		 *
		 * @since 1.0.0-beta.27
		 *
		 * @param array $schema The item schema.
		 */
		$schema = apply_filters( "llms_rest_{$object_type}_item_schema", $schema );

		/**
		 * Filters whether to allow filtering the item schema to add fields.
		 *
		 * The dynamic portion of the hook name, `$object_type`, refers the object type this controller is responsible for managing.
		 *
		 * @since 1.0.0-beta.27
		 *
		 * @param bool  $allow  Whether to allow filtering the item schema to add fields.
		 * @param array $schema The item schema.
		 */
		if ( ! apply_filters( "llms_rest_allow_filtering_{$object_type}_item_schema_to_add_fields", false, $schema ) ) {
			// Emit a _doing_it_wrong warning if user tries to add new properties using this filter.
			$new_fields = array_diff_key( $schema['properties'], $unfiltered_schema['properties'] );
			if ( count( $new_fields ) > 0 ) {
				_doing_it_wrong(
					esc_html( "llms_rest_{$object_type}_item_schema" ),
					esc_html(
						sprintf(
						/* translators: %s: register_rest_field */
							__( 'Please use %s to add new schema properties.', 'lifterlms' ),
							'register_rest_field()'
						)
					),
					'[version]'
				);
			}
		}

		return $schema;
	}


Top ↑

Changelog Changelog

Changelog
Version Description
1.0.0-beta.27 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

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