WC_Meta_Box_Product_Data::prepare_set_attributes()private staticWC 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(int)
Attribute array index.
По умолчанию: null

Код WC_Meta_Box_Product_Data::prepare_set_attributes() WC 8.7.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;
}