WP_View_Config_Data::remove_propertiesprivateWP 7.1.0

Removes the properties a spec names from the current value.

The mirror of merge_properties(), applied at every nesting level: a list in $spec names entries to delete from $current — associative keys are unset, and list members are matched by identity (list_item_identity) and dropped — while an associative $spec recurses into each named entry to prune from within it. A name absent from $current is ignored, and a list is renumbered after members are removed so it keeps sequential keys.

Method of the class: WP_View_Config_Data{}

No Hooks.

Returns

mixed. The pruned value.

Usage

// private - for code of main (parent) class only
$result = $this->remove_properties( $current, $spec );
$current(mixed) (required)
The current value.
$spec(mixed) (required)
The names to remove from it.

Changelog

Since 7.1.0 Introduced.

WP_View_Config_Data::remove_properties() code WP 7.1

private function remove_properties( $current, $spec ) {
	if ( ! is_array( $current ) || ! is_array( $spec ) ) {
		return $current;
	}

	$current_is_list = array_is_list( $current );

	if ( array_is_list( $spec ) ) {
		// Each entry names something to delete from the current value.
		foreach ( $spec as $name ) {
			if ( $current_is_list ) {
				$current = $this->remove_list_member( $current, $name );
			} else {
				unset( $current[ $name ] );
			}
		}
	} else {
		// Each key names an entry to recurse into and prune from within.
		foreach ( $spec as $name => $subspec ) {
			if ( $current_is_list ) {
				foreach ( $current as $index => $member ) {
					if ( $this->list_item_identity( $member ) === (string) $name ) {
						$current[ $index ] = $this->remove_properties( $member, $subspec );
						break;
					}
				}
			} elseif ( array_key_exists( $name, $current ) ) {
				$current[ $name ] = $this->remove_properties( $current[ $name ], $subspec );
			}
		}
	}

	// Renumber so a list from which a member was removed keeps sequential keys.
	return $current_is_list ? array_values( $current ) : $current;
}