Yoast_Form::file_upload
Create a File upload field.
Метод класса: Yoast_Form{}
Хуков нет.
Возвращает
null. Ничего (null).
Использование
$Yoast_Form = new Yoast_Form(); $Yoast_Form->file_upload( $variable, $label, $attr );
- $variable(строка) (обязательный)
- The variable within the option to create the file upload field for.
- $label(строка) (обязательный)
- The label to show for the variable.
- $attr(массив)
- Extra attributes to add to the file upload input.
По умолчанию: []
Список изменений
| С версии 2.0 | Введена. |
Код Yoast_Form::file_upload() Yoast Form::file upload Yoast 26.7
public function file_upload( $variable, $label, $attr = [] ) {
$val = $this->get_field_value( $variable, '' );
if ( is_array( $val ) ) {
$val = $val['url'];
}
$defaults = [
'disabled' => false,
];
$attr = wp_parse_args( $attr, $defaults );
$var_esc = esc_attr( $variable );
$this->label(
$label,
[
'for' => $variable,
'class' => 'select',
]
);
$disabled_attribute = $this->get_disabled_attribute( $variable, $attr );
// phpcs:ignore WordPress.Security.EscapeOutput -- Reason: $disabled_attribute output is hardcoded and all other output is properly escaped.
echo '<input type="file" value="' . esc_attr( $val ) . '" class="textinput" name="' . esc_attr( $this->option_name ) . '[' . $var_esc . ']" id="' . $var_esc . '"', $disabled_attribute, '/>';
// Need to save separate array items in hidden inputs, because empty file inputs type will be deleted by settings API.
if ( ! empty( $val ) ) {
$this->hidden( 'file', $this->option_name . '_file' );
$this->hidden( 'url', $this->option_name . '_url' );
$this->hidden( 'type', $this->option_name . '_type' );
}
echo '<br class="clear"/>';
}