private static function prepare_set_attributes($all_attributes, $key_prefix = 'attribute_', $index = null)
{
$attributes = array();
if ($all_attributes) {
foreach ($all_attributes as $attribute) {
if ($attribute->get_variation()) {
$attribute_key = sanitize_title($attribute->get_name());
if (!is_null($index)) {
$value = isset($_POST[$key_prefix . $attribute_key][$index]) ? stripslashes($_POST[$key_prefix . $attribute_key][$index]) : '';
} else {
$value = isset($_POST[$key_prefix . $attribute_key]) ? stripslashes($_POST[$key_prefix . $attribute_key]) : '';
}
$value = $attribute->is_taxonomy() ? sanitize_title($value) : wc_clean($value);
// Don't use wc_clean as it destroys sanitized characters in terms.
$attributes[$attribute_key] = $value;
}
}
}
return $attributes;
}