acf_field_icon_picker::render_fieldpublicACF 6.3

Renders icon picker field

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

Возвращает

null. Ничего (null).

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

$acf_field_icon_picker = new acf_field_icon_picker();
$acf_field_icon_picker->render_field( $field );
$field(объект) (обязательный)
The ACF Field.

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

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

Код acf_field_icon_picker::render_field() ACF 6.4.2

<?php
public function render_field( $field ) {
	$uploader = acf_get_setting( 'uploader' );

	// Enqueue uploader scripts
	if ( $uploader === 'wp' ) {
		acf_enqueue_uploader();
	}

	$div = array(
		'id'    => $field['id'],
		'class' => $field['class'] . ' acf-icon-picker',
	);

	echo '<div ' . acf_esc_attrs( $div ) . '>';

	acf_hidden_input(
		array(
			'name'             => $field['name'] . '[type]',
			'value'            => $field['value']['type'],
			'data-hidden-type' => 'type',
		)
	);
	acf_hidden_input(
		array(
			'name'             => $field['name'] . '[value]',
			'value'            => $field['value']['value'],
			'data-hidden-type' => 'value',
		)
	);

	if ( ! is_array( $field['tabs'] ) ) {
		$field['tabs'] = array();
	}

	$tabs  = $this->get_tabs();
	$shown = array_filter(
		$tabs,
		function ( $tab ) use ( $field ) {
			return in_array( $tab, $field['tabs'], true );
		},
		ARRAY_FILTER_USE_KEY
	);

	foreach ( $shown as $name => $label ) {
		if ( count( $shown ) > 1 ) {
			acf_render_field_wrap(
				array(
					'type'           => 'tab',
					'label'          => $label,
					'key'            => 'acf_icon_picker_tabs',
					'selected'       => $name === $field['value']['type'],
					'unique_tab_key' => $name,
				)
			);
		}

		$wrapper_class = str_replace( '_', '-', $name );
		echo '<div class="acf-icon-picker-tabs acf-icon-picker-' . esc_attr( $wrapper_class ) . '-tabs" data-tab="' . esc_attr( $name ) . '">';

		switch ( $name ) {
			case 'dashicons':
				$this->render_icon_list_tab( $name );
				break;
			case 'media_library':
				?>
				<div class="acf-icon-picker-tab" data-category="<?php echo esc_attr( $name ); ?>">
					<div class="acf-icon-picker-media-library">
						<?php
						$button_style = 'display: none;';

						if ( in_array( $field['value']['type'], array( 'media_library', 'dashicons' ), true ) && ! empty( $field['value']['value'] ) ) {
							$button_style = '';
						}
						?>
						<button
							aria-label="<?php esc_attr_e( 'Click to change the icon in the Media Library', 'acf' ); ?>"
							class="acf-icon-picker-media-library-preview"
							style="<?php echo esc_attr( $button_style ); ?>"
						>
							<div class="acf-icon-picker-media-library-preview-img" style="<?php echo esc_attr( 'media_library' !== $field['value']['type'] ? 'display: none;' : '' ); ?>">
								<?php
									$img_url = wp_get_attachment_image_url( $field['value']['value'], 'thumbnail' );
									// If the type is media_library, then we need to show the media library preview.
								?>
									<img src="<?php echo esc_url( $img_url ); ?>" alt="<?php esc_attr_e( 'The currently selected image preview', 'acf' ); ?>" />
							</div>
							<div class="acf-icon-picker-media-library-preview-dashicon" style="<?php echo esc_attr( 'dashicons' !== $field['value']['type'] ? 'display: none;' : '' ); ?>">
								<div class="dashicons <?php echo esc_attr( $field['value']['value'] ); ?>">
								</div>
							</div>
						</button>
						<button class="acf-icon-picker-media-library-button">
							<div class="acf-icon-picker-media-library-button-icon dashicons dashicons-admin-media"></div>
							<span><?php esc_html_e( 'Browse Media Library', 'acf' ); ?></span>
						</button>
					</div>
				</div>
				<?php
				break;
			case 'url':
				echo '<div class="acf-icon-picker-url">';
				acf_text_input(
					array(
						'class' => 'acf-icon_url',
						'value' => $field['value']['type'] === 'url' ? $field['value']['value'] : '',
					)
				);

				// Helper Text
				?>
				<p class="description"><?php esc_html_e( 'The URL to the icon you\'d like to use, or svg as Data URI', 'acf' ); ?></p>
				<?php
				echo '</div>';
				break;
			default:
				do_action( 'acf/fields/icon_picker/tab/' . $name, $field );

				$custom_icons = apply_filters( 'acf/fields/icon_picker/' . $name . '/icons', array(), $field );

				if ( is_array( $custom_icons ) && ! empty( $custom_icons ) ) {
					$this->render_icon_list_tab( $name, $custom_icons );

					acf_localize_data(
						array(
							'iconPickerIcons_' . $name  => $custom_icons,
						)
					);
				}
		}

		echo '</div>';
	}

	echo '</div>';
}