WC_Meta_Box_Product_Data::prepare_set_attributes() private WC 1.0
Prepare attributes for a specific variation or defaults.
{} Это метод класса: WC_Meta_Box_Product_Data{}
Хуков нет.
Возвращает
Массив.
Использование
$result = WC_Meta_Box_Product_Data::prepare_set_attributes( $all_attributes, $key_prefix, $index );
- $all_attributes(массив) (обязательный)
- List of attribute keys.
- $key_prefix(строка)
- Attribute key prefix.
По умолчанию: 'attribute_' - $index(число)
- Attribute array index.
По умолчанию: null
Код WC_Meta_Box_Product_Data::prepare_set_attributes() WC Meta Box Product Data::prepare set attributes WC 4.9.0
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 ] ) ? wp_unslash( $_POST[ $key_prefix . $attribute_key ][ $index ] ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
} else {
$value = isset( $_POST[ $key_prefix . $attribute_key ] ) ? wp_unslash( $_POST[ $key_prefix . $attribute_key ] ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
}
if ( $attribute->is_taxonomy() ) {
// Don't use wc_clean as it destroys sanitized characters.
$value = sanitize_title( $value );
} else {
$value = html_entity_decode( wc_clean( $value ), ENT_QUOTES, get_bloginfo( 'charset' ) ); // WPCS: sanitization ok.
}
$attributes[ $attribute_key ] = $value;
}
}
}
return $attributes;
}