_acf_get_field_wrapper_attributes()
Returns the attributes of a prepared field's wrapping element.
Внутренняя функция — эта функция рассчитана на использование самим ядром. Не рекомендуется использовать эту функцию в своем коде.
Хуки из функции
Возвращает
array. The wrapper attributes.
Использование
_acf_get_field_wrapper_attributes( $field, $element );
- $field(массив) (обязательный)
- The prepared field array.
- $element(строка) (обязательный)
- The wrapping element type.
Список изменений
| С версии 6.8.11 | Введена. |
Код _acf_get_field_wrapper_attributes() acf get field wrapper attributes ACF 6.8.11
function _acf_get_field_wrapper_attributes( $field, $element ) {
// Generate wrapper attributes.
$wrapper = array(
'id' => '',
'class' => 'acf-field',
'width' => '',
'style' => '',
'data-name' => $field['_name'],
'data-type' => $field['type'],
'data-key' => $field['key'],
);
// Add field type attributes.
$wrapper['class'] .= " acf-field-{$field['type']}";
// add field key attributes
if ( $field['key'] ) {
$wrapper['class'] .= " acf-field-{$field['key']}";
}
// Add required attributes.
// Todo: Remove data-required
if ( $field['required'] ) {
$wrapper['class'] .= ' is-required';
$wrapper['data-required'] = 1;
}
// Support custom attributes.
if ( ! empty( $field['data'] ) && is_array( $field['data'] ) ) {
foreach ( $field['data'] as $name => $attr ) {
$wrapper[ 'data-' . $name ] = $attr;
}
unset( $field['data'] );
}
// Clean up class attribute.
$wrapper['class'] = str_replace( '_', '-', $wrapper['class'] );
$wrapper['class'] = str_replace( 'field-field-', 'field-', $wrapper['class'] );
// Merge in field 'wrapper' setting without destroying class and style.
if ( $field['wrapper'] ) {
// Event handlers can't come from field settings. Use the
// "acf/field_wrapper_attributes" filter to add them intentionally.
$field_wrapper = array_filter(
$field['wrapper'],
function ( $name ) {
return stripos( (string) $name, 'on' ) !== 0;
},
ARRAY_FILTER_USE_KEY
);
$wrapper = acf_merge_attributes( $wrapper, $field_wrapper );
}
// Extract wrapper width and generate style.
// Todo: Move from $wrapper out into $field.
$width = acf_extract_var( $wrapper, 'width' );
if ( $width ) {
$width = acf_numval( $width );
if ( $element !== 'tr' && $element !== 'td' ) {
$wrapper['data-width'] = $width;
$wrapper['style'] .= " width:{$width}%;";
}
}
// Clean up all attributes.
$wrapper = array_map( 'trim', $wrapper );
$wrapper = array_filter( $wrapper );
/**
* Filters the $wrapper array before rendering.
*
* @date 21/1/19
* @since 5.7.10
*
* @param array $wrapper The wrapper attributes array.
* @param array $field The field array.
*/
$wrapper = apply_filters( 'acf/field_wrapper_attributes', $wrapper, $field );
// Append conditional logic attributes.
if ( ! empty( $field['conditional_logic'] ) ) {
$wrapper['data-conditions'] = $field['conditional_logic'];
}
if ( ! empty( $field['conditions'] ) ) {
$wrapper['data-conditions'] = $field['conditions'];
}
return $wrapper;
}