WC_Product_Variable_Data_Store_CPT::validate_children_dataprotectedWC 1.0

Validate the children data by checking the structure and type of the data.

Method of the class: WC_Product_Variable_Data_Store_CPT{}

No Hooks.

Returns

true|false. True if valid, false otherwise.

Usage

// protected - for code of main (parent) or child class
$result = $this->validate_children_data( $children, $deprecated );
$children(array) (required)
The children data.
$deprecated(string) (required)
Was the current transient version, unused since 10.3.0.

WC_Product_Variable_Data_Store_CPT::validate_children_data() code WC 10.6.2

protected function validate_children_data( $children, $deprecated ) {
	if ( ! is_array( $children ) ) {
		return false;
	}

	// Basic structure checks.
	if ( empty( $children['all'] ) || ! isset( $children['visible'] ) ) {
		return false;
	}

	if ( ! is_array( $children['all'] ) || ! is_array( $children['visible'] ) ) {
		return false;
	}

	foreach ( $children['all'] as $id ) {
		if ( ! is_numeric( $id ) ) {
			return false;
		}
	}

	foreach ( $children['visible'] as $id ) {
		if ( ! is_numeric( $id ) ) {
			return false;
		}
	}

	return true;
}