WP_REST_Abilities_V1_List_Controller::strip_internal_schema_keywords( $schema ): array<string,

This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only by core. It is listed here for completeness.

Recursively removes WordPress-internal keywords from a schema.

Description

Ability schemas may include WordPress-internal properties like sanitize_callback, validate_callback, and arg_options that are used server-side but are not valid JSON Schema keywords. This method removes those specific keys so they are not exposed in REST responses.

Parameters

mixed> $schema The schema array.

Return

array<string, mixed> The schema without WordPress-internal keywords.

Source

private function strip_internal_schema_keywords( array $schema ): array {
	$schema = array_diff_key( $schema, self::INTERNAL_SCHEMA_KEYWORDS );

	// Sub-schema maps: keys are user-defined, values are sub-schemas.
	// Note: 'dependencies' values can also be property-dependency arrays
	// (numeric arrays of strings) which are skipped via wp_is_numeric_array().
	foreach ( array( 'properties', 'patternProperties', 'definitions', 'dependencies' ) as $keyword ) {
		if ( isset( $schema[ $keyword ] ) && is_array( $schema[ $keyword ] ) ) {
			foreach ( $schema[ $keyword ] as $key => $child_schema ) {
				if ( is_array( $child_schema ) && ! wp_is_numeric_array( $child_schema ) ) {
					$schema[ $keyword ][ $key ] = $this->strip_internal_schema_keywords( $child_schema );
				}
			}
		}
	}

	// Single sub-schema keywords.
	foreach ( array( 'not', 'additionalProperties', 'additionalItems' ) as $keyword ) {
		if ( isset( $schema[ $keyword ] ) && is_array( $schema[ $keyword ] ) ) {
			$schema[ $keyword ] = $this->strip_internal_schema_keywords( $schema[ $keyword ] );
		}
	}

	// Items: single schema or tuple array of schemas.
	if ( isset( $schema['items'] ) ) {
		if ( wp_is_numeric_array( $schema['items'] ) ) {
			foreach ( $schema['items'] as $index => $item_schema ) {
				if ( is_array( $item_schema ) ) {
					$schema['items'][ $index ] = $this->strip_internal_schema_keywords( $item_schema );
				}
			}
		} elseif ( is_array( $schema['items'] ) ) {
			$schema['items'] = $this->strip_internal_schema_keywords( $schema['items'] );
		}
	}

	// Array-of-schemas keywords.
	foreach ( array( 'anyOf', 'oneOf', 'allOf' ) as $keyword ) {
		if ( isset( $schema[ $keyword ] ) && is_array( $schema[ $keyword ] ) ) {
			foreach ( $schema[ $keyword ] as $index => $sub_schema ) {
				if ( is_array( $sub_schema ) ) {
					$schema[ $keyword ][ $index ] = $this->strip_internal_schema_keywords( $sub_schema );
				}
			}
		}
	}

	return $schema;
}

Changelog

VersionDescription
7.0.0Introduced.

User Contributed Notes

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