WC_Product_Variable_Data_Store_CPT::validate_children_data()protectedWC 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.

Return

true|false. True if valid, false otherwise.

Usage

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

WC_Product_Variable_Data_Store_CPT::validate_children_data() code WC 9.7.1

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

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

	// Version check - only if version is set.
	if ( isset( $children['version'] ) && $children['version'] !== $current_version ) {
		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;
}