WC_Settings_API::generate_multiselect_html()publicWC 1.0.0

Generate Multiselect HTML.

Метод класса: WC_Settings_API{}

Хуков нет.

Возвращает

Строку.

Использование

$WC_Settings_API = new WC_Settings_API();
$WC_Settings_API->generate_multiselect_html( $key, $data );
$key(строка) (обязательный)
Field key.
$data(массив) (обязательный)
Field data.

Список изменений

С версии 1.0.0 Введена.

Код WC_Settings_API::generate_multiselect_html() WC 9.3.3

<?php
public function generate_multiselect_html( $key, $data ) {
	$field_key = $this->get_field_key( $key );
	$defaults  = array(
		'title'             => '',
		'disabled'          => false,
		'class'             => '',
		'css'               => '',
		'placeholder'       => '',
		'type'              => 'text',
		'desc_tip'          => false,
		'description'       => '',
		'custom_attributes' => array(),
		'select_buttons'    => false,
		'options'           => array(),
	);

	$data  = wp_parse_args( $data, $defaults );
	$value = (array) $this->get_option( $key, array() );

	ob_start();
	?>
	<tr valign="top">
		<th scope="row" class="titledesc">
			<label for="<?php echo esc_attr( $field_key ); ?>"><?php echo wp_kses_post( $data['title'] ); ?> <?php echo $this->get_tooltip_html( $data ); // WPCS: XSS ok. ?></label>
		</th>
		<td class="forminp">
			<fieldset>
				<legend class="screen-reader-text"><span><?php echo wp_kses_post( $data['title'] ); ?></span></legend>
				<select multiple="multiple" class="multiselect <?php echo esc_attr( $data['class'] ); ?>" name="<?php echo esc_attr( $field_key ); ?>[]" id="<?php echo esc_attr( $field_key ); ?>" style="<?php echo esc_attr( $data['css'] ); ?>" <?php disabled( $data['disabled'], true ); ?> <?php echo $this->get_custom_attribute_html( $data ); // WPCS: XSS ok. ?>>
					<?php foreach ( (array) $data['options'] as $option_key => $option_value ) : ?>
						<?php if ( is_array( $option_value ) ) : ?>
							<optgroup label="<?php echo esc_attr( $option_key ); ?>">
								<?php foreach ( $option_value as $option_key_inner => $option_value_inner ) : ?>
									<option value="<?php echo esc_attr( $option_key_inner ); ?>" <?php selected( in_array( (string) $option_key_inner, $value, true ), true ); ?>><?php echo esc_html( $option_value_inner ); ?></option>
								<?php endforeach; ?>
							</optgroup>
						<?php else : ?>
							<option value="<?php echo esc_attr( $option_key ); ?>" <?php selected( in_array( (string) $option_key, $value, true ), true ); ?>><?php echo esc_html( $option_value ); ?></option>
						<?php endif; ?>
					<?php endforeach; ?>
				</select>
				<?php echo $this->get_description_html( $data ); // WPCS: XSS ok. ?>
				<?php if ( $data['select_buttons'] ) : ?>
					<br/><a class="select_all button" href="#"><?php esc_html_e( 'Select all', 'woocommerce' ); ?></a> <a class="select_none button" href="#"><?php esc_html_e( 'Select none', 'woocommerce' ); ?></a>
				<?php endif; ?>
			</fieldset>
		</td>
	</tr>
	<?php

	return ob_get_clean();
}